Cake\Database\Query::clause PHP Метод

clause() публичный Метод

The return value for each of those parts may vary. Some clauses use QueryExpression to internally store their state, some use arrays and others may use booleans or integers. This is summary of the return types for each clause. - update: string The name of the table to update - set: QueryExpression - insert: array, will return an array containing the table + columns. - values: ValuesExpression - select: array, will return empty array when no fields are set - distinct: boolean - from: array of tables - join: array - set: array - where: QueryExpression, returns null when not set - group: array - having: QueryExpression, returns null when not set - order: OrderByExpression, returns null when not set - limit: integer or QueryExpression, null when not set - offset: integer or QueryExpression, null when not set - union: array
public clause ( string $name ) : mixed
$name string name of the clause to be returned
Результат mixed
    public function clause($name)
    {
        return $this->_parts[$name];
    }

Usage Example

 /**
  * Transforms an insert query that is meant to insert multiple rows at a time,
  * otherwise it leaves the query untouched.
  *
  * The way Firebird works with multi insert is by having multiple select statements
  * joined with UNION.
  *
  * @param \Cake\Database\Query $query The query to translate
  * @return \Cake\Database\Query
  */
 protected function _insertQueryTranslator($query)
 {
     $v = $query->clause('values');
     if (count($v->values()) === 1 || $v->query()) {
         return $query;
     }
     $newQuery = $query->connection()->newQuery();
     $cols = $v->columns();
     $placeholder = 0;
     $replaceQuery = false;
     foreach ($v->values() as $k => $val) {
         $fillLength = count($cols) - count($val);
         if ($fillLength > 0) {
             $val = array_merge($val, array_fill(0, $fillLength, null));
         }
         foreach ($val as $col => $attr) {
             if (!$attr instanceof ExpressionInterface) {
                 $val[$col] = sprintf(':c%d', $placeholder);
                 $placeholder++;
             }
         }
         $select = array_combine($cols, $val);
         if ($k === 0) {
             $replaceQuery = true;
             $newQuery->select($select);
             continue;
         }
         $q = $newQuery->connection()->newQuery();
         $newQuery->unionAll($q->select($select));
     }
     if ($replaceQuery) {
         $v->query($newQuery);
     }
     return $query;
 }
All Usage Examples Of Cake\Database\Query::clause