On this page
Class FunctionsBuilder
Contains methods related to generating FunctionExpression objects with most commonly used SQL functions.
This acts as a factory for FunctionExpression objects.
Method Summary
-
_build() protected
Returns a new instance of a FunctionExpression. This is used for generating arbitrary function calls in the final SQL string.
-
_literalArgumentFunction() protected
Helper function to build a function expression that only takes one literal argument.
-
dateDiff() public
Returns a FunctionExpression representing the difference in days between two dates.
-
now() public
Returns a FunctionExpression representing a call that will return the current date and time. By default it returns both date and time, but you can also make it generate only the date or only the time.
Method Detail
__call() public
__call(mixed $name, mixed $args)
Magic method dispatcher to create custom SQL function calls
Parameters
string
$name-
the SQL function name to construct
array
$args-
list with up to 3 arguments, first one being an array with parameters for the SQL function, the second one a list of types to bind to those params, and the third one the return type of the function
Returns
\Cake\Database\Expression\FunctionExpression
_build() protected
_build(mixed $name, mixed $params, mixed $types, mixed $return)
Returns a new instance of a FunctionExpression. This is used for generating arbitrary function calls in the final SQL string.
Parameters
string
$name-
the name of the SQL function to constructed
array
$params optional-
list of params to be passed to the function
array
$types optional-
list of types for each function param
string
$return optional-
The return type of the function expression
Returns
\Cake\Database\Expression\FunctionExpression
_literalArgumentFunction() protected
_literalArgumentFunction(mixed $name, mixed $expression, mixed $types, mixed $return)
Helper function to build a function expression that only takes one literal argument.
Parameters
string
$name-
name of the function to build
string|\Cake\Database\ExpressionInterface
$expression-
the function argument
array
$types optional-
list of types to bind to the arguments
string
$return optional-
The return type for the function
Returns
\Cake\Database\Expression\FunctionExpression
avg() public
avg(mixed $expression, mixed $types)
Returns a FunctionExpression representing a call to SQL AVG function.
Parameters
string|\Cake\Database\ExpressionInterface
$expression-
the function argument
array
$types optional-
list of types to bind to the arguments
Returns
\Cake\Database\Expression\FunctionExpression
cast() public
cast(mixed $field, mixed $type)
Returns a FunctionExpression representing a call to SQL CAST function.
Parameters
string|\Cake\Database\ExpressionInterface
$field-
Field or expression to cast.
string
$type optional-
The target data type
Returns
\Cake\Database\Expression\FunctionExpression
coalesce() public
coalesce(mixed $args, mixed $types)
Returns a FunctionExpression representing a call to SQL COALESCE function.
Parameters
array
$args-
List of expressions to evaluate as function parameters
array
$types optional-
list of types to bind to the arguments
Returns
\Cake\Database\Expression\FunctionExpression
concat() public
concat(mixed $args, mixed $types)
Returns a FunctionExpression representing a string concatenation
Parameters
array
$args-
List of strings or expressions to concatenate
array
$types optional-
list of types to bind to the arguments
Returns
\Cake\Database\Expression\FunctionExpression
count() public
count(mixed $expression, mixed $types)
Returns a FunctionExpression representing a call to SQL COUNT function.
Parameters
string|\Cake\Database\ExpressionInterface
$expression-
the function argument
array
$types optional-
list of types to bind to the arguments
Returns
\Cake\Database\Expression\FunctionExpression
dateAdd() public
dateAdd(mixed $expression, mixed $value, mixed $unit, mixed $types)
Add the time unit to the date expression
Parameters
string|\Cake\Database\ExpressionInterface
$expression-
Expression to obtain the date part from.
string|int
$value-
Value to be added. Use negative to subtract.
string
$unit-
Unit of the value e.g. hour or day.
array
$types optional-
list of types to bind to the arguments
Returns
\Cake\Database\Expression\FunctionExpression
dateDiff() public
dateDiff(mixed $args, mixed $types)
Returns a FunctionExpression representing the difference in days between two dates.
Parameters
array
$args-
List of expressions to obtain the difference in days.
array
$types optional-
list of types to bind to the arguments
Returns
\Cake\Database\Expression\FunctionExpression
datePart() public
datePart(mixed $part, mixed $expression, mixed $types)
Returns the specified date part from the SQL expression.
Parameters
string
$part-
Part of the date to return.
string|\Cake\Database\ExpressionInterface
$expression-
Expression to obtain the date part from.
array
$types optional-
list of types to bind to the arguments
Returns
\Cake\Database\Expression\FunctionExpression
dayOfWeek() public
dayOfWeek(mixed $expression, mixed $types)
Returns a FunctionExpression representing a call to SQL WEEKDAY function.
1 - Sunday, 2 - Monday, 3 - Tuesday...
Parameters
string|\Cake\Database\ExpressionInterface
$expression-
the function argument
array
$types optional-
list of types to bind to the arguments
Returns
\Cake\Database\Expression\FunctionExpression
extract() public
extract(mixed $part, mixed $expression, mixed $types)
Returns the specified date part from the SQL expression.
Parameters
string
$part-
Part of the date to return.
string|\Cake\Database\ExpressionInterface
$expression-
Expression to obtain the date part from.
array
$types optional-
list of types to bind to the arguments
Returns
\Cake\Database\Expression\FunctionExpression
max() public
max(mixed $expression, mixed $types)
Returns a FunctionExpression representing a call to SQL MAX function.
Parameters
string|\Cake\Database\ExpressionInterface
$expression-
the function argument
array
$types optional-
list of types to bind to the arguments
Returns
\Cake\Database\Expression\FunctionExpression
min() public
min(mixed $expression, mixed $types)
Returns a FunctionExpression representing a call to SQL MIN function.
Parameters
string|\Cake\Database\ExpressionInterface
$expression-
the function argument
array
$types optional-
list of types to bind to the arguments
Returns
\Cake\Database\Expression\FunctionExpression
now() public
now(mixed $type)
Returns a FunctionExpression representing a call that will return the current date and time. By default it returns both date and time, but you can also make it generate only the date or only the time.
Parameters
string
$type optional-
(datetime|date|time)
Returns
\Cake\Database\Expression\FunctionExpression
rand() public
rand()
Returns a FunctionExpression representing a call to SQL RAND function.
Returns
\Cake\Database\Expression\FunctionExpression
sum() public
sum(mixed $expression, mixed $types)
Returns a FunctionExpression representing a call to SQL SUM function.
Parameters
string|\Cake\Database\ExpressionInterface
$expression-
the function argument
array
$types optional-
list of types to bind to the arguments
Returns
\Cake\Database\Expression\FunctionExpression
weekday() public
weekday(mixed $expression, mixed $types)
Returns a FunctionExpression representing a call to SQL WEEKDAY function.
1 - Sunday, 2 - Monday, 3 - Tuesday...
Parameters
string|\Cake\Database\ExpressionInterface
$expression-
the function argument
array
$types optional-
list of types to bind to the arguments
Returns
\Cake\Database\Expression\FunctionExpression
© 2005–present 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.9/class-Cake.Database.FunctionsBuilder.html