Returns this object for chaining purposes. ie. $db->Select()->From();
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. |
return | Gdn_SQLDriver | $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); } }
/** * Used by $this->stash() to create & manage sessions for users & guests. * * This is a stop-gap solution until full session management for users & * guests can be implemented. * * @param Gdn_SQLDriver $sql Local clone of the sql driver. * @param string $valueToStash The value of the stash to set. * * @return bool|Gdn_DataSet Current session. */ private function getStashSession($sql, $valueToStash) { $cookieName = c('Garden.Cookie.Name', 'Vanilla'); $name = $cookieName . '-sid'; // Grab the entire session record. $sessionID = val($name, $_COOKIE, ''); // If there is no session, and no value for saving, return. if ($sessionID == '' && $valueToStash == '') { return false; } $session = $sql->select()->from('Session')->where('SessionID', $sessionID)->get()->firstRow(); if (!$session) { $sessionID = betterRandomString(32); $transientKey = substr(md5(mt_rand()), 0, 11) . '!'; // Save the session information to the database. $sql->insert('Session', ['SessionID' => $sessionID, 'UserID' => Gdn::session()->UserID, 'TransientKey' => $transientKey, 'DateInserted' => Gdn_Format::toDateTime(), 'DateUpdated' => Gdn_Format::toDateTime()]); trace("Inserting session stash {$sessionID}"); $session = $sql->select()->from('Session')->where('SessionID', $sessionID)->get()->firstRow(); // Save a session cookie. $path = c('Garden.Cookie.Path', '/'); $domain = c('Garden.Cookie.Domain', ''); $expire = 0; // If the domain being set is completely incompatible with the // current domain then make the domain work. $currentHost = Gdn::request()->host(); if (!stringEndsWith($currentHost, trim($domain, '.'))) { $domain = ''; } safeCookie($name, $sessionID, $expire, $path, $domain); $_COOKIE[$name] = $sessionID; } $session->Attributes = dbdecode($session->Attributes); if (!$session->Attributes) { $session->Attributes = []; } return $session; }