Class WindowExpression
This represents a SQL window expression used by aggregate and window functions.
Constants
Property 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
-
__clone() public
Clone this object and its subtree of expressions.
-
__construct() public
-
buildOffsetSql() protected
Builds frame offset sql.
-
excludeCurrent() public
Adds current row frame exclusion.
-
excludeGroup() public
Adds group frame exclusion.
-
excludeTies() public
Adds ties frame exclusion.
-
frame() public
Adds a frame to the window.
-
groups() public
Adds a simple groups frame to the window.
-
isNamedOnly() public
Return whether is only a named window expression.
-
name() public
Sets the window name.
-
order() public
Adds one or more order clauses to the window.
-
partition() public
Adds one or more partition expressions to the window.
-
range() public
Adds a simple range frame to the window.
-
rows() public
Adds a simple rows frame to the window.
-
sql() public
Converts the Node into a SQL string fragment.
-
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
buildOffsetSql() ¶ protected
buildOffsetSql(Cake\Database\ValueBinder $generator, int|stringCake\Database\ExpressionInterface|null $offset, string $direction): string
Builds frame offset sql.
Parameters
-
Cake\Database\ValueBinder
$generator Value binder
-
int|stringCake\Database\ExpressionInterface|null
$offset Frame offset
-
string
$direction Frame offset direction
Returns
string
frame() ¶ public
frame(string $type, int|stringCake\Database\ExpressionInterface|null $startOffset, string $startDirection, int|stringCake\Database\ExpressionInterface|null $endOffset, string $endDirection): $this
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 -
int|stringCake\Database\ExpressionInterface|null
$startOffset -
string
$startDirection -
int|stringCake\Database\ExpressionInterface|null
$endOffset -
string
$endDirection
Returns
$this
groups() ¶ public
groups(int|null $start, int|null $end = 0): $this
Adds a simple groups frame to the window.
See range()
for details.
Parameters
-
int|null
$start -
int|null
$end optional
Returns
$this
isNamedOnly() ¶ public
isNamedOnly(): bool
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): $this
Sets the window name.
Parameters
-
string
$name Window name
Returns
$this
order() ¶ public
order(Closure|Cake\Database\ExpressionInterface|string)[]Cake\Database\ExpressionInterface|string $fields): $this
Adds one or more order clauses to the window.
Parameters
-
Closure|Cake\Database\ExpressionInterface|string)[]Cake\Database\ExpressionInterface|string
$fields
Returns
$this
partition() ¶ public
partition(Closure|Cake\Database\ExpressionInterface|string)[]Cake\Database\ExpressionInterface|string $partitions): $this
Adds one or more partition expressions to the window.
Parameters
-
Closure|Cake\Database\ExpressionInterface|string)[]Cake\Database\ExpressionInterface|string
$partitions
Returns
$this
range() ¶ public
range(int|stringCake\Database\ExpressionInterface|null $start, int|stringCake\Database\ExpressionInterface|null $end = 0): $this
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|stringCake\Database\ExpressionInterface|null
$start -
int|stringCake\Database\ExpressionInterface|null
$end optional
Returns
$this
rows() ¶ public
rows(int|null $start, int|null $end = 0): $this
Adds a simple rows frame to the window.
See range()
for details.
Parameters
-
int|null
$start -
int|null
$end optional
Returns
$this
sql() ¶ public
sql(Cake\Database\ValueBinder $generator): string
Converts the Node into a SQL string fragment.
Parameters
-
Cake\Database\ValueBinder
$generator
Returns
string
traverse() ¶ public
traverse(Closure $visitor): $this
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
Returns
$this