An expression object for ORDER BY clauses
Auxiliary function used for decomposing a nested array of conditions and building a tree structure inside this object to represent the full SQL expression.
__construct( string|array|Cake\Database\ExpressionInterface $conditions [] , array|Cake\Database\TypeMap $types [] , string $conjunction '' )
Constructor
Cake\Database\ExpressionInterface
$conditions
optional [] Cake\Database\TypeMap
$types
optional [] $conjunction
optional '' Cake\Database\Expression\QueryExpression::__construct()
_addConditions( array $orders , array $types )
Auxiliary function used for decomposing a nested array of conditions and building a tree structure inside this object to represent the full SQL expression.
New order by expressions are merged to existing ones
$orders
$types
Cake\Database\Expression\QueryExpression::_addConditions()
sql( Cake\Database\ValueBinder $generator )
Convert the expression into a SQL fragment.
$generator
Cake\Database\Expression\QueryExpression::sql()
__call( string $method , array $args )
Helps calling the and()
and or()
methods transparently.
$method
$args
Cake\Database\Expression\QueryExpression
_calculateType( string|Cake\Database\Expression\IdentifierExpression $field )
Returns the type name for the passed field if it was stored in the typeMap
Cake\Database\Expression\IdentifierExpression
$field
_parseCondition( string $field , mixed $value )
Parses a string conditions by trying to extract the operator inside it if any and finally returning either an adequate QueryExpression object or a plain string representation of the condition. This function is responsible for generating the placeholders and replacing the values by them, while storing the value elsewhere for future binding.
$field
The value from with the actual field and operator will be extracted.
$value
Cake\Database\ExpressionInterface
add( string|array|Cake\Database\ExpressionInterface $conditions , array $types [] )
Adds one or more conditions to this expression object. Conditions can be expressed in a one dimensional array, that will cause all conditions to be added directly at this level of the tree or they can be nested arbitrarily making it create more expression objects that will be nested inside and configured to use the specified conjunction.
If the type passed for any of the fields is expressed "type[]" (note braces) then it will cause the placeholder to be re-written dynamically so if the value is an array, it will create as many placeholders as values are in it.
Cake\Database\ExpressionInterface
$conditions
single or multiple conditions to be added. When using an array and the key is 'OR' or 'AND' a new expression object will be created with that conjunction and internal array value passed as conditions.
$types
optional [] associative array of fields pointing to the type of the values that are being passed. Used for correctly binding values to statements.
addCase( array|Cake\Database\ExpressionInterface $conditions , array|Cake\Database\ExpressionInterface $values [] , array $types [] )
Adds a new case expression to the expression object
Cake\Database\ExpressionInterface
$conditions
The conditions to test. Must be a ExpressionInterface instance, or an array of ExpressionInterface instances.
Cake\Database\ExpressionInterface
$values
optional [] associative array of values to be associated with the conditions passed in $conditions. If there are more $values than $conditions, the last $value is used as the ELSE
value
$types
optional [] associative array of types to be associated with the values passed in $values
and_( string|array|Cake\Database\ExpressionInterface $conditions , array $types [] )
Returns a new QueryExpression object containing all the conditions passed and set up the conjunction to be "AND"
Cake\Database\ExpressionInterface
$conditions
$types
optional [] associative array of fields pointing to the type of the values that are being passed. Used for correctly binding values to statements.
Cake\Database\Expression\QueryExpression
between( string|Cake\Database\ExpressionInterface $field , mixed $from , mixed $to , string|null $type null )
Adds a new condition to the expression object in the form "field BETWEEN from AND to".
Cake\Database\ExpressionInterface
$field
$from
$to
$type
optional null count( )
Returns the number of internal conditions that are stored in this expression. Useful to determine if this expression object is void or it will generate a non-empty string when compiled
Countable::count()
eq( string|Cake\Database\ExpressionInterface $field , mixed $value , string|null $type null )
Adds a new condition to the expression object in the form "field = value".
Cake\Database\ExpressionInterface
$field
$value
$type
optional null the type name for $value as configured using the Type map. If it is suffixed with "[]" and the value is an array then multiple placeholders will be created, one per each value in the array.
equalFields( string $left , string $right )
Builds equal condition or assignment with identifier wrapping.
$left
$right
exists( Cake\Database\ExpressionInterface $query )
Adds a new condition to the expression object in the form "EXISTS (...)".
Cake\Database\ExpressionInterface
$query
getConjunction( )
Gets the currently configured conjunction for the conditions at this level of the expression tree.
gt( string|Cake\Database\ExpressionInterface $field , mixed $value , string|null $type null )
Adds a new condition to the expression object in the form "field > value".
Cake\Database\ExpressionInterface
$field
$value
$type
optional null gte( string|Cake\Database\ExpressionInterface $field , mixed $value , string|null $type null )
Adds a new condition to the expression object in the form "field >= value".
Cake\Database\ExpressionInterface
$field
$value
$type
optional null hasNestedExpression( )
Returns true if this expression contains any other nested ExpressionInterface objects
in( string|Cake\Database\ExpressionInterface $field , string|array $values , string|null $type null )
Adds a new condition to the expression object in the form "field IN (value1, value2)".
Cake\Database\ExpressionInterface
$field
$values
$type
optional null isCallable( callable $c )
Check whether or not a callable is acceptable.
We don't accept ['class', 'method'] style callbacks, as they often contain user input and arrays of strings are easy to sneak in.
$c
isNotNull( string|Cake\Database\ExpressionInterface $field )
Adds a new condition to the expression object in the form "field IS NOT NULL".
Cake\Database\ExpressionInterface
$field
database field to be tested for not null
isNull( string|Cake\Database\ExpressionInterface $field )
Adds a new condition to the expression object in the form "field IS NULL".
Cake\Database\ExpressionInterface
$field
database field to be tested for null
iterateParts( callable $callable )
Executes a callable function for each of the parts that form this expression.
The callable function is required to return a value with which the currently visited part will be replaced. If the callable function returns null then the part will be discarded completely from this expression.
The callback function will receive each of the conditions as first param and the key as second param. It is possible to declare the second parameter as passed by reference, this will enable you to change the key under which the modified part is stored.
$callable
like( string|Cake\Database\ExpressionInterface $field , mixed $value , string|null $type null )
Adds a new condition to the expression object in the form "field LIKE value".
Cake\Database\ExpressionInterface
$field
$value
$type
optional null lt( string|Cake\Database\ExpressionInterface $field , mixed $value , string|null $type null )
Adds a new condition to the expression object in the form "field < value".
Cake\Database\ExpressionInterface
$field
$value
$type
optional null lte( string|Cake\Database\ExpressionInterface $field , mixed $value , string|null $type null )
Adds a new condition to the expression object in the form "field <= value".
Cake\Database\ExpressionInterface
$field
$value
$type
optional null not( string|array|Cake\Database\ExpressionInterface $conditions , array $types [] )
Adds a new set of conditions to this level of the tree and negates the final result by prepending a NOT, it will look like "NOT ( (condition1) AND (conditions2) )" conjunction depends on the one currently configured for this object.
Cake\Database\ExpressionInterface
$conditions
$types
optional [] associative array of fields pointing to the type of the values that are being passed. Used for correctly binding values to statements.
notEq( string|Cake\Database\ExpressionInterface $field , mixed $value , string|null $type null )
Adds a new condition to the expression object in the form "field != value".
Cake\Database\ExpressionInterface
$field
$value
$type
optional null the type name for $value as configured using the Type map. If it is suffixed with "[]" and the value is an array then multiple placeholders will be created, one per each value in the array.
notExists( Cake\Database\ExpressionInterface $query )
Adds a new condition to the expression object in the form "NOT EXISTS (...)".
Cake\Database\ExpressionInterface
$query
notIn( string|Cake\Database\ExpressionInterface $field , array $values , string|null $type null )
Adds a new condition to the expression object in the form "field NOT IN (value1, value2)".
Cake\Database\ExpressionInterface
$field
$values
$type
optional null notLike( string|Cake\Database\ExpressionInterface $field , mixed $value , string|null $type null )
Adds a new condition to the expression object in the form "field NOT LIKE value".
Cake\Database\ExpressionInterface
$field
$value
$type
optional null or_( string|array|Cake\Database\ExpressionInterface $conditions , array $types [] )
Returns a new QueryExpression object containing all the conditions passed and set up the conjunction to be "OR"
Cake\Database\ExpressionInterface
$conditions
$types
optional [] associative array of fields pointing to the type of the values that are being passed. Used for correctly binding values to statements.
Cake\Database\Expression\QueryExpression
setConjunction( string $conjunction )
Changes the conjunction for the conditions at this level of the expression tree.
$conjunction
tieWith( string|null $conjunction null )
Changes the conjunction for the conditions at this level of the expression tree. If called with no arguments it will return the currently configured value.
$conjunction
optional null value to be used for joining conditions. If null it will not set any value, but return the currently stored one
Cake\Database\Expression\QueryExpression
traverse( callable $callable )
Traverses the tree structure of this query expression by executing a callback function for each of the conditions that are included in this object. Useful for compiling the final expression, or doing introspection in the structure.
Callback function receives as only argument an instance of ExpressionInterface
$callable
Cake\Database\ExpressionInterface::traverse()
type( string|null $conjunction null )
Backwards compatible wrapper for tieWith()
$conjunction
optional null value to be used for joining conditions. If null it will not set any value, but return the currently stored one
Cake\Database\Expression\QueryExpression
defaultTypes( array $types null )
Allows setting default types when chaining query
$types
optional null getDefaultTypes( )
Gets default types of current type map.
getTypeMap( )
Returns the existing type map.
Cake\Database\TypeMap
setDefaultTypes( array $types )
Allows setting default types when chaining query.
$types
setTypeMap( array|Cake\Database\TypeMap $typeMap )
Creates a new TypeMap if $typeMap is an array, otherwise exchanges it for the given one.
Cake\Database\TypeMap
$typeMap
typeMap( array|Cake\Database\TypeMap|null $typeMap null )
Creates a new TypeMap if $typeMap is an array, otherwise returns the existing type map or exchanges it for the given one.
Cake\Database\TypeMap
|null $typeMap
optional null
© 2005–2018 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/3.5/class-Cake.Database.Expression.OrderByExpression.html