public select ( mixed $Select = '*', string $Function = '', string $Alias = '' ) : Gdn_SQLDriver | ||
$Select | mixed | NotRequired "*" The field(s) being selected. It can be a comma delimited string, the name of a single field, or an array of field names. |
$Function | string | NotRequired "" The aggregate function to be used on the select column. Only valid if a single column name is provided. Accepted values are MAX, MIN, AVG, SUM. |
$Alias | string | NotRequired "" The alias to give a column name. |
Résultat | Gdn_SQLDriver | $this |
public function select($Select = '*', $Function = '', $Alias = '')
{
if (is_string($Select)) {
if ($Function == '') {
$Select = explode(',', $Select);
} else {
$Select = array($Select);
}
}
$Count = count($Select);
$i = 0;
for ($i = 0; $i < $Count; $i++) {
$Field = trim($Select[$i]);
// Try and figure out an alias for the field.
if ($Alias == '' || $Count > 1 && $i > 0) {
if (preg_match('/^([^\\s]+)\\s+(?:as\\s+)?`?([^`]+)`?$/i', $Field, $Matches) > 0) {
// This is an explicit alias in the select clause.
$Field = $Matches[1];
$Alias = $Matches[2];
} else {
// This is an alias from the field name.
$Alias = trim(strstr($Field, '.'), ' .`');
}
// Make sure we aren't selecting * as an alias.
if ($Alias == '*') {
$Alias = '';
}
}
$Expr = array('Field' => $Field, 'Function' => $Function, 'Alias' => $Alias);
if ($Alias == '') {
$this->_Selects[] = $Expr;
} else {
$this->_Selects[$Alias] = $Expr;
}
}
return $this;
}
/** Add the sql to perform a search. * * @param Gdn_SQLDriver $Sql * @param string $Columns a comma seperated list of columns to search on. */ public function addMatchSql($Sql, $Columns, $LikeRelavenceColumn = '') { if ($this->_SearchMode == 'like') { if ($LikeRelavenceColumn) { $Sql->select($LikeRelavenceColumn, '', 'Relavence'); } else { $Sql->select(1, '', 'Relavence'); } $Sql->beginWhereGroup(); $ColumnsArray = explode(',', $Columns); $First = true; foreach ($ColumnsArray as $Column) { $Column = trim($Column); $Param = $this->Parameter(); if ($First) { $Sql->where("{$Column} like {$Param}", null, false, false); $First = false; } else { $Sql->orWhere("{$Column} like {$Param}", null, false, false); } } $Sql->endWhereGroup(); } else { $Boolean = $this->_SearchMode == 'boolean' ? ' in boolean mode' : ''; $Param = $this->Parameter(); $Sql->select($Columns, "match(%s) against({$Param}{$Boolean})", 'Relavence'); $Param = $this->Parameter(); $Sql->where("match({$Columns}) against ({$Param}{$Boolean})", null, false, false); } }