final class Select
    implements Statement, Query, Selection
    uses Snapshot
Public API: explicitly declared with @visibility public.

A selection: result columns over an optional input, with its filter, grouping, windows, ordering and limit.

Rule: SQLITE-SELECT-001. The facts are derived by SQLITE-SELECT-SCOPE-001. An ORDER BY or GROUP BY term that is an integer constant must be given as a result column position, because that is how SQLite reads it. Source: https://sqlite.org/lang_select.html. Status: Implemented.

Reading the parts of a selectiondoctest
$query = (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze('SELECT a FROM t WHERE a > 1 GROUP BY a HAVING count(*) > 1 ORDER BY a LIMIT 3');
    [count($query->statement->columns), $query->statement->where !== null, count($query->statement->groupBy), $query->statement->having !== null, count($query->statement->orderBy), $query->statement->limit !== null] // => [1, true, 1, true, 1, true]
Refusing an integer constant as an ordinary ordering expressiondoctest
new \SqlSemantics\Platform\Sqlite\Statement\Query\Select([new \SqlSemantics\Platform\Sqlite\Statement\Query\Star()], null, null, [], null, [], [new \SqlSemantics\Platform\Sqlite\Statement\Query\Ordering\SortTerm(new \SqlSemantics\Platform\Sqlite\Statement\Expression\Literal\IntegerLiteral('1'))]) // throws \SqlSemantics\Platform\Sqlite\Model\Diagnostic\InvalidConstruction

Properties§

public non-empty-list<ResultColumn|Star|TableStar> $columns
public list<Scalar> $groupBy
public list<WindowDefinition> $windows
public list<SortTerm> $orderBy
public Relation|null $from = null
public Scalar|null $where = null
public Scalar|null $having = null
public Limit|null $limit = null
public SetQuantifier|null $quantifier = null

Methods§

public function __construct(
    list<ResultColumn|Star|TableStar> $columns,
    public Relation|null $from = null,
    public Scalar|null $where = null,
    list<Scalar> $groupBy = [],
    public Scalar|null $having = null,
    list<WindowDefinition> $windows = [],
    list<SortTerm> $orderBy = [],
    public Limit|null $limit = null,
    public SetQuantifier|null $quantifier = null,
)

Parameters

$columnslist<ResultColumn|Star|TableStar>The result columns in written order; at least one
$fromRelation|nullThe input relation
$whereScalar|nullThe row predicate
$groupBylist<Scalar>The GROUP BY terms
$havingScalar|nullThe group predicate
$windowslist<WindowDefinition>The named windows
$orderBylist<SortTerm>The ORDER BY terms
$limitLimit|nullThe LIMIT clause
$quantifierSetQuantifier|nullThe written DISTINCT or ALL

Throws

InvalidConstruction When a part is not what the clause admits
Calls 13
public function input(): ?Relation

Answers the input relation.

Returns

public function deriveStatement(Derivation $derivation): void

Derives the selection as a statement root and records its rows as the output.

Parameters

$derivationDerivation
Calls 5
public function deriveQuery(Derivation $derivation, Environment $outer): QueryFact

Derives the input, every clause and the output fields.

Parameters

$derivationDerivation
$outerEnvironment

Returns

Calls 2
public function render(Output $out): void

Writes the clauses in grammar order.

Parameters

$outOutput
Calls 3

Test cases 317§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 9
Other tests reaching this symbol 308

Relations§

Instantiated in 1
Constant reads 1
Type checks 8
Type declarations 17