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

Public Member Functions

 into ($name)
 
 rollback ()
 
 abort ()
 
 replace ()
 
 fail ()
 
 ignore ()
 
 on ($column)
 
 values ($expression)
 
 defaultValues ()
 
 __get ($name)
 
 __toString ()
 

Protected Member Functions

 _or ($or)
 

Protected Attributes

 $_into = null
 
 $_or = null
 
 $_columns = []
 
 $_values = []
 
 $_defaultValues = false
 

Detailed Description

Class .

Build an INSERT query.

Definition at line 47 of file Insert.php.

Member Function Documentation

Hoa\Database\Query\Insert::__get (   $name)

Allow to use the “or” attribute to chain method calls.

Parameters
string$nameName.
Returns
mixed

Definition at line 224 of file Insert.php.

225  {
226  switch (strtolower($name)) {
227  case 'or':
228  return $this;
229 
230  default:
231  return $this->$name;
232  }
233  }
Hoa\Database\Query\Insert::__toString ( )

Generate the query.

Returns
string

Implements Hoa\Database\Query\Dml.

Definition at line 240 of file Insert.php.

241  {
242  $out = 'INSERT';
243 
244  if (null !== $this->_or) {
245  $out .= ' OR ' . $this->_or;
246  }
247 
248  $out .= ' INTO ' . $this->_into;
249 
250  if (true === $this->_defaultValues) {
251  return $out . ' DEFAULT VALUES';
252  }
253 
254  if (!empty($this->_columns)) {
255  $out .= ' (' . implode(', ', $this->_columns) . ')';
256  }
257 
258  if (is_string($this->_values)) {
259  return $out . ' ' . $this->_values;
260  }
261 
262  $tuples = [];
263 
264  foreach ($this->_values as $tuple) {
265  $tuples[] = '(' . implode(', ', $tuple) . ')';
266  }
267 
268  return $out . ' VALUES ' . implode(', ', $tuples);
269  }

Here is the call graph for this function:

Hoa\Database\Query\Insert::_or (   $or)
protected

Declare an alternative to “INSERT”.

Parameters
string$orAlternative.
Returns

Definition at line 155 of file Insert.php.

156  {
157  $this->_or = $or;
158 
159  return $this;
160  }

Here is the caller graph for this function:

Hoa\Database\Query\Insert::abort ( )

Insert or abort.

Returns

Definition at line 114 of file Insert.php.

115  {
116  return $this->_or('ABORT');
117  }

Here is the call graph for this function:

Hoa\Database\Query\Insert::defaultValues ( )

Use default values.

Returns

Definition at line 211 of file Insert.php.

212  {
213  $this->_defaultValues = true;
214 
215  return $this;
216  }
Hoa\Database\Query\Insert::fail ( )

Insert or fail.

Returns

Definition at line 134 of file Insert.php.

135  {
136  return $this->_or('FAIL');
137  }

Here is the call graph for this function:

Hoa\Database\Query\Insert::ignore ( )

Insert or ignore.

Returns

Definition at line 144 of file Insert.php.

145  {
146  return $this->_or('IGNORE');
147  }

Here is the call graph for this function:

Hoa\Database\Query\Insert::into (   $name)

Set source.

Parameters
string$nameName.
Returns

Definition at line 92 of file Insert.php.

93  {
94  $this->_into = $name;
95 
96  return $this;
97  }
Hoa\Database\Query\Insert::on (   $column)

Set columns.

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

Definition at line 169 of file Insert.php.

170  {
171  foreach (func_get_args() as $column) {
172  $this->_columns[] = $column;
173  }
174 
175  return $this;
176  }
Hoa\Database\Query\Insert::replace ( )

Insert or replace.

Returns

Definition at line 124 of file Insert.php.

125  {
126  return $this->_or('REPLACE');
127  }

Here is the call graph for this function:

Hoa\Database\Query\Insert::rollback ( )

Insert or rollback.

Returns

Definition at line 104 of file Insert.php.

105  {
106  return $this->_or('ROLLBACK');
107  }

Here is the call graph for this function:

Hoa\Database\Query\Insert::values (   $expression)

Set values (on call per tuple). Expression can be: a regular value or a SELECT query.

Parameters
mixed$expressionExpression.
......
Returns

Definition at line 186 of file Insert.php.

187  {
188  if ($expression instanceof Select) {
189  $this->_values = (string) $expression;
190  } else {
191  if (is_string($this->_values)) {
192  $this->_values = [];
193  }
194 
195  $values = &$this->_values[];
196  $values = [];
197 
198  foreach (func_get_args() as $expression) {
199  $values[] = $expression;
200  }
201  }
202 
203  return $this;
204  }

Member Data Documentation

Hoa\Database\Query\Insert::$_columns = []
protected

Definition at line 68 of file Insert.php.

Hoa\Database\Query\Insert::$_defaultValues = false
protected

Definition at line 82 of file Insert.php.

Hoa\Database\Query\Insert::$_into = null
protected

Definition at line 54 of file Insert.php.

Hoa\Database\Query\Insert::$_or = null
protected

Definition at line 61 of file Insert.php.

Hoa\Database\Query\Insert::$_values = []
protected

Definition at line 75 of file Insert.php.


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