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
arrayCake\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 by clauses to the window.
-
orderBy() public
Adds one or more order by 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 callback, passing as first parameter the instance of the expression currently being iterated.
Method Detail
buildOffsetSql() ¶ protected
buildOffsetSql(Cake\Database\ValueBinder $binder, Cake\Database\ExpressionInterface|string|int|null $offset, string $direction): string
Builds frame offset sql.
Parameters
-
Cake\Database\ValueBinder
$binder Value binder
-
Cake\Database\ExpressionInterface|string|int|null
$offset Frame offset
-
string
$direction Frame offset direction
Returns
string
frame() ¶ public
frame(string $type, Cake\Database\ExpressionInterface|string|int|null $startOffset, string $startDirection, Cake\Database\ExpressionInterface|string|int|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 -
Cake\Database\ExpressionInterface|string|int|null
$startOffset -
string
$startDirection -
Cake\Database\ExpressionInterface|string|int|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(Cake\Database\ExpressionInterfaceClosure|arrayCake\Database\ExpressionInterface|string>|string $fields): $this
Adds one or more order by clauses to the window.
Parameters
-
Cake\Database\ExpressionInterfaceClosure|arrayCake\Database\ExpressionInterface|string>|string
$fields
Returns
$this
orderBy() ¶ public
orderBy(Cake\Database\ExpressionInterfaceClosure|arrayCake\Database\ExpressionInterface|string>|string $fields): $this
Adds one or more order by clauses to the window.
Parameters
-
Cake\Database\ExpressionInterfaceClosure|arrayCake\Database\ExpressionInterface|string>|string
$fields
Returns
$this
partition() ¶ public
partition(Cake\Database\ExpressionInterfaceClosure|arrayCake\Database\ExpressionInterface|string>|string $partitions): $this
Adds one or more partition expressions to the window.
Parameters
-
Cake\Database\ExpressionInterfaceClosure|arrayCake\Database\ExpressionInterface|string>|string
$partitions
Returns
$this
range() ¶ public
range(Cake\Database\ExpressionInterface|string|int|null $start, Cake\Database\ExpressionInterface|string|int|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
-
Cake\Database\ExpressionInterface|string|int|null
$start -
Cake\Database\ExpressionInterface|string|int|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 $binder): string
Converts the Node into a SQL string fragment.
Parameters
-
Cake\Database\ValueBinder
$binder
Returns
string
traverse() ¶ public
traverse(Closure $callback): $this
Iterates over each part of the expression recursively for every level of the expressions tree and executes the callback, passing as first parameter the instance of the expression currently being iterated.
Parameters
-
Closure
$callback
Returns
$this