Cake\Database\Query::newExpr PHP Method

newExpr() public method

You can optionally pass a single raw SQL string or an array or expressions in any format accepted by \Cake\Database\Expression\QueryExpression: $expression = $query->newExpr(); // Returns an empty expression object $expression = $query->newExpr('Table.column = Table2.column'); // Return a raw SQL expression
public newExpr ( mixed $rawExpression = null ) : Cake\Database\Expression\QueryExpression
$rawExpression mixed A string, array or anything you want wrapped in an expression object
return Cake\Database\Expression\QueryExpression
    public function newExpr($rawExpression = null)
    {
        $expression = new QueryExpression([], $this->typeMap());
        if ($rawExpression !== null) {
            $expression->add($rawExpression);
        }
        return $expression;
    }

Usage Example

 /**
  * Modify the limit/offset to TSQL
  *
  * @param \Cake\Database\Query $query The query to translate
  * @return \Cake\Database\Query The modified query
  */
 protected function _selectQueryTranslator($query)
 {
     $limit = $query->clause('limit');
     $offset = $query->clause('offset');
     if ($limit && $offset === null) {
         $query->modifier(['_auto_top_' => sprintf('TOP %d', $limit)]);
     }
     if ($offset !== null && !$query->clause('order')) {
         $query->order($query->newExpr()->add('(SELECT NULL)'));
     }
     if ($this->_version() < 11 && $offset !== null) {
         return $this->_pagingSubquery($query, $limit, $offset);
     }
     return $this->_transformDistinct($query);
 }
All Usage Examples Of Cake\Database\Query::newExpr