Class WindowExpression
This represents a SQL window expression used by aggregate and window functions.
Constants summary
-
string
FOLLOWING'FOLLOWING'
-
string
GROUPS'GROUPS'
-
string
PRECEDING'PRECEDING'
-
string
RANGE'RANGE'
-
string
ROWS'ROWS'
Properties summary
- $exclusion protected
string|null
- $frame protected
array|null
- $name protected
\Cake\Database\Expression\IdentifierExpression
- $order protected
\Cake\Database\Expression\OrderByExpression|null
- $partitions protected
\Cake\Database\ExpressionInterface[]
Method Summary
- __construct() public
- traverse() public
Iterates over each part of the expression recursively for every level of the expressions tree and executes the $visitor callable passing as first parameter the instance of the expression currently being iterated.
Method Detail
__clone() public
__clone()
Clone this object and its subtree of expressions.
__construct() public
__construct(string $name)
Parameters
-
string
$name optional Window name
buildOffsetSql() protected
buildOffsetSql(\Cake\Database\ValueBinder $generator, mixed $offset, string $direction)
Builds frame offset sql.
Parameters
-
\Cake\Database\ValueBinder
$generator Value binder
-
int|string|\Cake\Database\ExpressionInterface|null
$offset Frame offset
-
string
$direction Frame offset direction
Returns
string
excludeCurrent() public
excludeCurrent()
Adds current row frame exclusion.
Returns
$this
excludeGroup() public
excludeGroup()
Adds group frame exclusion.
Returns
$this
excludeTies() public
excludeTies()
Adds ties frame exclusion.
Returns
$this
frame() public
frame(string $type, mixed $startOffset, string $startDirection, mixed $endOffset, string $endDirection)
Adds a frame to the window.
Use the range()
, rows()
or groups()
helpers if you need simple 'BETWEEN offset PRECEDING and offset FOLLOWING' frames.
You can specify any direction for both frame start and frame end.
With both $startOffset
and $endOffset
:
-
0
- 'CURRENT ROW' -
null
- 'UNBOUNDED'
Parameters
-
string
$type Frame type
-
int|string|\Cake\Database\ExpressionInterface|null
$startOffset Frame start offset
-
string
$startDirection Frame start direction
-
int|string|\Cake\Database\ExpressionInterface|null
$endOffset Frame end offset
-
string
$endDirection Frame end direction
Returns
$this
Throws
InvalidArgumentException
WHen offsets are negative.
groups() public
groups(?int $start, ?int $end)
Adds a simple groups frame to the window.
See range()
for details.
Parameters
-
int|null
$start Frame start
-
int|null
$end optional Frame end If not passed in, only frame start SQL will be generated.
Returns
$this
isNamedOnly() public
isNamedOnly()
Return whether is only a named window expression.
These window expressions only specify a named window and do not specify their own partitions, frame or order.
Returns
bool
name() public
name(string $name)
Sets the window name.
Parameters
-
string
$name Window name
Returns
$this
order() public
order(mixed $fields)
Adds one or more order clauses to the window.
Parameters
-
\Closure|(\Cake\Database\ExpressionInterface|string)[]|\Cake\Database\ExpressionInterface|string
$fields Order expressions
Returns
$this
partition() public
partition(mixed $partitions)
Adds one or more partition expressions to the window.
Parameters
-
\Closure|(\Cake\Database\ExpressionInterface|string)[]|\Cake\Database\ExpressionInterface|string
$partitions Partition expressions
Returns
$this
range() public
range(mixed $start, mixed $end)
Adds a simple range frame to the window.
$start
:
-
0
- 'CURRENT ROW' -
null
- 'UNBOUNDED PRECEDING' - offset - 'offset PRECEDING'
$end
:
-
0
- 'CURRENT ROW' -
null
- 'UNBOUNDED FOLLOWING' - offset - 'offset FOLLOWING'
If you need to use 'FOLLOWING' with frame start or 'PRECEDING' with frame end, use frame()
instead.
Parameters
-
int|string|\Cake\Database\ExpressionInterface|null
$start Frame start
-
int|string|\Cake\Database\ExpressionInterface|null
$end optional Frame end If not passed in, only frame start SQL will be generated.
Returns
$this
rows() public
rows(?int $start, ?int $end)
Adds a simple rows frame to the window.
See range()
for details.
Parameters
-
int|null
$start Frame start
-
int|null
$end optional Frame end If not passed in, only frame start SQL will be generated.
Returns
$this
sql() public
sql(\Cake\Database\ValueBinder $generator)
Converts the Node into a SQL string fragment.
Parameters
-
\Cake\Database\ValueBinder
$generator Placeholder generator object
Returns
string
traverse() public
traverse(\Closure $visitor)
Iterates over each part of the expression recursively for every level of the expressions tree and executes the $visitor callable passing as first parameter the instance of the expression currently being iterated.
Parameters
-
\Closure
$visitor The callable to apply to all nodes.
Returns
$this
Property Detail
$exclusion protected
Type
string|null
$frame protected
Type
array|null
$name protected
Type
\Cake\Database\Expression\IdentifierExpression
$order protected
Type
\Cake\Database\Expression\OrderByExpression|null
$partitions protected
Type
\Cake\Database\ExpressionInterface[]
© 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/4.1/class-Cake.Database.Expression.WindowExpression.html