Represents a SQL Query expression. Internally it stores a tree of expressions that can be compiled by converting this object to string and will contain a correctly parenthesized and nested expression.
__call( string $method , array $args )
Helps calling the and()
and or()
methods transparently.
$method
$args
Cake\Database\Expression\QueryExpression
BadMethodCallException
__construct( string|array|Cake\Database\Expression\QueryExpression $conditions [] , array|Cake\Database\TypeMap $types [] , string $conjunction 'AND' )
Constructor. A new expression object can be created without any params and be built dynamically. Otherwise it is possible to pass an array of conditions containing either a tree-like array structure to be parsed and/or other expression objects. Optionally, you can set the conjunction keyword to be used for joining each part of this level of the expression tree.
Cake\Database\Expression\QueryExpression
$conditions
optional [] Cake\Database\TypeMap
$types
optional [] $conjunction
optional 'AND' _addConditions( array $conditions , array $types )
Auxiliary function used for decomposing a nested array of conditions and build a tree structure inside this object to represent the full SQL expression. String conditions are stored directly in the conditions, while any other representation is wrapped around an adequate instance or of this class.
$conditions
$types
_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
$value
string|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
$types
optional [] mixed
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
Cake\Database\ExpressionInterface
$values
optional [] ELSE
value$types
optional [] mixed
and_( string|array|Cake\Database\Expression\QueryExpression $conditions , array $types [] )
Returns a new QueryExpression object containing all the conditions passed and set up the conjunction to be "AND"
Cake\Database\Expression\QueryExpression
$conditions
$types
optional [] Cake\Database\Expression\QueryExpression
between( mixed $field , mixed $from , mixed $to , string $type null )
Adds a new condition to the expression object in the form "field BETWEEN from AND to".
$field
$from
$to
$type
optional null mixed
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
integer
Countable::count()
eq( string $field , mixed $value , string $type null )
Adds a new condition to the expression object in the form "field = value".
$field
$value
$type
optional null mixed
gt( string $field , mixed $value , string $type null )
Adds a new condition to the expression object in the form "field > value".
$field
$value
$type
optional null mixed
gte( string $field , mixed $value , string $type null )
Adds a new condition to the expression object in the form "field >= value".
$field
$value
$type
optional null mixed
hasNestedExpression( )
Returns true if this expression contains any other nested ExpressionInterface objects
boolean
in( string $field , string|array $values , string $type null )
Adds a new condition to the expression object in the form "field IN (value1, value2)".
$field
$values
$type
optional null mixed
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
boolean
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
mixed
isNull( string|Cake\Database\ExpressionInterface $field )
Adds a new condition to the expression object in the form "field IS NULL".
Cake\Database\ExpressionInterface
$field
mixed
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
mixed
like( string $field , mixed $value , string $type null )
Adds a new condition to the expression object in the form "field LIKE value".
$field
$value
$type
optional null mixed
lt( string $field , mixed $value , string $type null )
Adds a new condition to the expression object in the form "field < value".
$field
$value
$type
optional null mixed
lte( string $field , mixed $value , string $type null )
Adds a new condition to the expression object in the form "field <= value".
$field
$value
$type
optional null mixed
not( string|array|Cake\Database\Expression\QueryExpression $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\Expression\QueryExpression
$conditions
$types
optional [] mixed
notEq( string $field , mixed $value , string $type null )
Adds a new condition to the expression object in the form "field != value".
$field
$value
$type
optional null mixed
notIn( string $field , array $values , string $type null )
Adds a new condition to the expression object in the form "field NOT IN (value1, value2)".
$field
$values
$type
optional null mixed
notLike( string $field , mixed $value , string $type null )
Adds a new condition to the expression object in the form "field NOT LIKE value".
$field
$value
$type
optional null mixed
or_( string|array|Cake\Database\Expression\QueryExpression $conditions , array $types [] )
Returns a new QueryExpression object containing all the conditions passed and set up the conjunction to be "OR"
Cake\Database\Expression\QueryExpression
$conditions
$types
optional [] Cake\Database\Expression\QueryExpression
sql( Cake\Database\ValueBinder $generator )
Returns the string representation of this object so that it can be used in a SQL query. Note that values condition values are not included in the string, in their place placeholders are put and can be replaced by the quoted values accordingly.
$generator
string
Cake\Database\ExpressionInterface::sql()
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 a QueryExpression
$callable
Cake\Database\ExpressionInterface::traverse()
type( string $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 string|$this
defaultTypes( array $types null )
Allows setting default types when chaining query
$types
optional null mixed
typeMap( array|TypeMap $typeMap null )
Creates a new TypeMap if $typeMap is an array, otherwise returns the existing type map or exchanges it for the given one.
$typeMap
optional null mixed
protected Cake\Database\TypeMap
© 2005–2016 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.
http://api.cakephp.org/3.1/class-Cake.Database.Expression.QueryExpression.html