Class FunctionsBuilder

Contains methods related to generating FunctionExpression objects with most commonly used SQL functions. This acts as a factory for FunctionExpression objects.

Method Detail

__callsource public

__call( string $name , array $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 2 arguments, first one being an array with parameters for the SQL function and second one a list of types to bind to those params

Returns

Cake\Database\Expression\FunctionExpression
\Cake\Database\Expression\FunctionExpression

_buildsource protected

_build( string $name , array $params [] , array $types [] )

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

Returns

Cake\Database\Expression\FunctionExpression
FunctionExpression

_literalArgumentFunctionsource protected

_literalArgumentFunction( string $name , mixed $expression , array $types [] )

Helper function to build a function expression that only takes one literal argument.

Parameters

string $name
name of the function to build
mixed $expression
the function argument
array $types optional []
list of types to bind to the arguments

Returns

Cake\Database\Expression\FunctionExpression
FunctionExpression

avgsource public

avg( mixed $expression , array $types [] )

Returns a FunctionExpression representing a call to SQL AVG function.

Parameters

mixed $expression
the function argument
array $types optional []
list of types to bind to the arguments

Returns

Cake\Database\Expression\FunctionExpression
FunctionExpression

coalescesource public

coalesce( array $args , array $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
FunctionExpression

concatsource public

concat( array $args , array $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
FunctionExpression

countsource public

count( mixed $expression , array $types [] )

Returns a FunctionExpression representing a call to SQL COUNT function.

Parameters

mixed $expression
the function argument
array $types optional []
list of types to bind to the arguments

Returns

Cake\Database\Expression\FunctionExpression
FunctionExpression

dateAddsource public

dateAdd( string $expression , string $value , string $unit , array $types [] )

Add the time unit to the date expression

Parameters

string $expression
Expression to obtain the date part from.
string $value
Value to be added. Use negative to substract.
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
\Cake\Database\Expression\FunctionExpression

dateDiffsource public

dateDiff( array $args , array $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
FunctionExpression

datePartsource public

datePart( string $part , string $expression , array $types [] )

Returns the specified date part from the SQL expression.

Parameters

string $part
Part of the date to return.
string $expression
Expression to obtain the date part from.
array $types optional []
list of types to bind to the arguments

Returns

Cake\Database\Expression\FunctionExpression
\Cake\Database\Expression\FunctionExpression

dayOfWeeksource public

dayOfWeek( mixed $expression , array $types [] )

Returns a FunctionExpression representing a call to SQL WEEKDAY function. 1 - Sunday, 2 - Monday, 3 - Tuesday...

Parameters

mixed $expression
the function argument
array $types optional []
list of types to bind to the arguments

Returns

Cake\Database\Expression\FunctionExpression
\Cake\Database\Expression\FunctionExpression

extractsource public

extract( string $part , string $expression , array $types [] )

Returns the specified date part from the SQL expression.

Parameters

string $part
Part of the date to return.
string $expression
Expression to obtain the date part from.
array $types optional []
list of types to bind to the arguments

Returns

Cake\Database\Expression\FunctionExpression
\Cake\Database\Expression\FunctionExpression

maxsource public

max( mixed $expression , array $types [] )

Returns a FunctionExpression representing a call to SQL MAX function.

Parameters

mixed $expression
the function argument
array $types optional []
list of types to bind to the arguments

Returns

Cake\Database\Expression\FunctionExpression
FunctionExpression

minsource public

min( mixed $expression , array $types [] )

Returns a FunctionExpression representing a call to SQL MIN function.

Parameters

mixed $expression
the function argument
array $types optional []
list of types to bind to the arguments

Returns

Cake\Database\Expression\FunctionExpression
FunctionExpression

nowsource public

now( string $type 'datetime' )

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'
(datetime|date|time)

Returns

Cake\Database\Expression\FunctionExpression
\Cake\Database\Expression\FunctionExpression

sumsource public

sum( mixed $expression , array $types [] )

Returns a FunctionExpression representing a call to SQL SUM function.

Parameters

mixed $expression
the function argument
array $types optional []
list of types to bind to the arguments

Returns

Cake\Database\Expression\FunctionExpression
FunctionExpression

weekdaysource public

weekday( mixed $expression , array $types [] )

Returns a FunctionExpression representing a call to SQL WEEKDAY function. 1 - Sunday, 2 - Monday, 3 - Tuesday...

Parameters

mixed $expression
the function argument
array $types optional []
list of types to bind to the arguments

Returns

Cake\Database\Expression\FunctionExpression
\Cake\Database\Expression\FunctionExpression

© 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.FunctionsBuilder.html