Hoa central
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Hoa\Database\Query\SelectCore Class Reference
Inheritance diagram for Hoa\Database\Query\SelectCore:

Public Member Functions

 __construct (Array $columns=[])
 
 distinct ()
 
 all ()
 
 select ($column)
 
 groupBy ($expression)
 
 having ($expression)
 
 from ($source)
 
 _as ($alias)
 
 join ($source)
 
 naturalJoin ($source)
 
 leftJoin ($source)
 
 naturalLeftJoin ($source)
 
 leftOuterJoin ($source)
 
 naturalLeftOuterJoin ($source)
 
 innerJoin ($source)
 
 naturalInnerJoin ($source)
 
 crossJoin ($source)
 
 naturalCrossJoin ($source)
 
 reset ()
 
 __toString ()
 
- Public Member Functions inherited from Hoa\Database\Query\Where
 where ($expression)
 
 __call ($name, Array $values)
 
 __get ($name)
 
 reset ()
 
 __toString ()
 

Protected Member Functions

 _join ($type, $source)
 

Protected Attributes

 $_columns = null
 
 $_distinctOrAll = null
 
 $_from = []
 
 $_groupBy = []
 
 $_having = null
 
- Protected Attributes inherited from Hoa\Database\Query\Where
 $_where = []
 
 $_logicOperator = null
 

Detailed Description

Class .

Core of the SELECT query.

Definition at line 47 of file SelectCore.php.

Constructor & Destructor Documentation

Hoa\Database\Query\SelectCore::__construct ( Array  $columns = [])

Set columns.

Parameters
array$columnsColumns.
Returns
void

Definition at line 92 of file SelectCore.php.

93  {
94  $this->_columns = $columns;
95 
96  return;
97  }

Member Function Documentation

Hoa\Database\Query\SelectCore::__toString ( )

Generate the query.

Returns
string

Definition at line 362 of file SelectCore.php.

363  {
364  $out = 'SELECT';
365 
366  if (null !== $this->_distinctOrAll) {
367  $out .= ' ' . $this->_distinctOrAll;
368  }
369 
370  if (!empty($this->_columns)) {
371  $out .= ' ' . implode(', ', $this->_columns);
372  } else {
373  $out .= ' *';
374  }
375 
376  if (!empty($this->_from)) {
377  $out .= ' FROM ';
378  $handle = [];
379 
380  foreach ($this->_from as $alias => $from) {
381  if (is_int($alias)) {
382  $handle[] = $from;
383  } else {
384  $handle[] = $from . ' AS ' . $alias;
385  }
386  }
387 
388  $out .= implode(', ', $handle);
389  }
390 
391  $out .= parent::__toString();
392 
393  if (!empty($this->_groupBy)) {
394  $out .= ' GROUP BY ' . implode(', ', $this->_groupBy);
395 
396  if (!empty($this->_having)) {
397  $out .= ' HAVING ' . $this->_having;
398  }
399  }
400 
401  return $out;
402  }
Hoa\Database\Query\SelectCore::_as (   $alias)

Alias the last declared source.

Parameters
string$aliasAlias.
Returns

Definition at line 194 of file SelectCore.php.

195  {
196  if (empty($this->_from)) {
197  return $this;
198  }
199 
200  $this->_from[$alias] = array_pop($this->_from);
201 
202  return $this;
203  }
Hoa\Database\Query\SelectCore::_join (   $type,
  $source 
)
protected

Make a join.

Parameters
string$typeType.
mixed$sourceSource.
Returns

Definition at line 322 of file SelectCore.php.

323  {
324  if (empty($this->_from)) {
325  return $this;
326  }
327 
328  if ($source instanceof self) {
329  $source = '(' . $source . ')';
330  }
331 
332  end($this->_from);
333  $key = key($this->_from);
334  $value = current($this->_from);
335  $this->_from[$key] = $value . ' ' . $type . ' ' . $source;
336 
337  return new Join($this, $this->_from);
338  }

Here is the caller graph for this function:

Hoa\Database\Query\SelectCore::all ( )

Make a SELECT ALL.

Returns

Definition at line 116 of file SelectCore.php.

117  {
118  $this->_distinctOrAll = 'ALL';
119 
120  return $this;
121  }
Hoa\Database\Query\SelectCore::crossJoin (   $source)

Cross join a source (regular of a SELECT query).

Parameters
mixed$sourceSource.
Returns

Definition at line 299 of file SelectCore.php.

300  {
301  return $this->_join('CROSS JOIN', $source);
302  }

Here is the call graph for this function:

Hoa\Database\Query\SelectCore::distinct ( )

Make a SELECT DISTINCT.

Returns

Definition at line 104 of file SelectCore.php.

105  {
106  $this->_distinctOrAll = 'DISTINCT';
107 
108  return $this;
109  }
Hoa\Database\Query\SelectCore::from (   $source)

Set source (regular or a SELECT query).

Parameters
mixed$sourceSource.
......
Returns

Definition at line 175 of file SelectCore.php.

176  {
177  foreach (func_get_args() as $source) {
178  if ($source instanceof self) {
179  $source = '(' . $source . ')';
180  }
181 
182  $this->_from[] = $source;
183  }
184 
185  return $this;
186  }
Hoa\Database\Query\SelectCore::groupBy (   $expression)

Group by expression.

Parameters
string$expressionExpression.
......
Returns

Definition at line 146 of file SelectCore.php.

147  {
148  foreach (func_get_args() as $expression) {
149  $this->_groupBy[] = $expression;
150  }
151 
152  return $this;
153  }
Hoa\Database\Query\SelectCore::having (   $expression)

Having expression.

Parameters
string$expressionExpression.
Returns

Definition at line 161 of file SelectCore.php.

162  {
163  $this->_having = $expression;
164 
165  return $this;
166  }
Hoa\Database\Query\SelectCore::innerJoin (   $source)

Inner join a source (regular of a SELECT query).

Parameters
mixed$sourceSource.
Returns

Definition at line 277 of file SelectCore.php.

278  {
279  return $this->_join('INNER JOIN', $source);
280  }

Here is the call graph for this function:

Hoa\Database\Query\SelectCore::join (   $source)

Join a source (regular of a SELECT query).

Parameters
mixed$sourceSource.
Returns

Definition at line 211 of file SelectCore.php.

212  {
213  return $this->_join('JOIN', $source);
214  }

Here is the call graph for this function:

Hoa\Database\Query\SelectCore::leftJoin (   $source)

Left join a source (regular of a SELECT query).

Parameters
mixed$sourceSource.
Returns

Definition at line 233 of file SelectCore.php.

234  {
235  return $this->_join('LEFT JOIN', $source);
236  }

Here is the call graph for this function:

Hoa\Database\Query\SelectCore::leftOuterJoin (   $source)

Left outer join a source (regular of a SELECT query).

Parameters
mixed$sourceSource.
Returns

Definition at line 255 of file SelectCore.php.

256  {
257  return $this->_join('LEFT OUTER JOIN', $source);
258  }

Here is the call graph for this function:

Hoa\Database\Query\SelectCore::naturalCrossJoin (   $source)

Natural cross join a source (regular of a SELECT query).

Parameters
mixed$sourceSource.
Returns

Definition at line 310 of file SelectCore.php.

311  {
312  return $this->_join('NATURAL CROSS JOIN', $source);
313  }

Here is the call graph for this function:

Hoa\Database\Query\SelectCore::naturalInnerJoin (   $source)

Natural inner join a source (regular of a SELECT query).

Parameters
mixed$sourceSource.
Returns

Definition at line 288 of file SelectCore.php.

289  {
290  return $this->_join('NATURAL INNER JOIN', $source);
291  }

Here is the call graph for this function:

Hoa\Database\Query\SelectCore::naturalJoin (   $source)

Natural join a source (regular of a SELECT query).

Parameters
mixed$sourceSource.
Returns

Definition at line 222 of file SelectCore.php.

223  {
224  return $this->_join('NATURAL JOIN', $source);
225  }

Here is the call graph for this function:

Hoa\Database\Query\SelectCore::naturalLeftJoin (   $source)

Natural left join a source (regular of a SELECT query).

Parameters
mixed$sourceSource.
Returns

Definition at line 244 of file SelectCore.php.

245  {
246  return $this->_join('NATURAL LEFT JOIN', $source);
247  }

Here is the call graph for this function:

Hoa\Database\Query\SelectCore::naturalLeftOuterJoin (   $source)

Natural left outer join a source (regular of a SELECT query).

Parameters
mixed$sourceSource.
Returns

Definition at line 266 of file SelectCore.php.

267  {
268  return $this->_join('NATURAL LEFT OUTER JOIN', $source);
269  }

Here is the call graph for this function:

Hoa\Database\Query\SelectCore::reset ( )

Reset some properties.

Returns

Definition at line 345 of file SelectCore.php.

346  {
347  parent::reset();
348  $this->_columns = [];
349  $this->_distinctOrAll = null;
350  $this->_groupBy = [];
351  $this->_having = [];
352  $this->_from = [];
353 
354  return $this;
355  }

Here is the caller graph for this function:

Hoa\Database\Query\SelectCore::select (   $column)

Select a column.

Parameters
string$columnColumn.
......
Returns

Definition at line 130 of file SelectCore.php.

131  {
132  foreach (func_get_args() as $column) {
133  $this->_columns[] = $column;
134  }
135 
136  return $this;
137  }

Member Data Documentation

Hoa\Database\Query\SelectCore::$_columns = null
protected

Definition at line 54 of file SelectCore.php.

Hoa\Database\Query\SelectCore::$_distinctOrAll = null
protected

Definition at line 61 of file SelectCore.php.

Hoa\Database\Query\SelectCore::$_from = []
protected

Definition at line 68 of file SelectCore.php.

Hoa\Database\Query\SelectCore::$_groupBy = []
protected

Definition at line 75 of file SelectCore.php.

Hoa\Database\Query\SelectCore::$_having = null
protected

Definition at line 82 of file SelectCore.php.


The documentation for this class was generated from the following file: