classCommonTables
final class CommonTables
Binds the common table expressions of a WITH clause.
Rule: SQLITE-COMMON-TABLE-001. Every table of the clause is visible in every query of the clause and in the statement the clause belongs to, whether or not RECURSIVE is written. A table is derived after the tables of the clause it refers to; while its own query is derived it is bound to its column list, with columns that can hold any storage class or NULL (see SQLITE-COMPOUND-SCOPE-001 for recursive queries). The columns of a table are the result columns of its query (SQLITE-RELATION-NAME-001), renamed by the column list when one is written; a column list of another length, a collation or direction in the list and a repeated table name are reported. A table that refers to a table that refers back cannot be ordered; SQLite rejects it as a circular reference, which is reported, and the reference then falls through to the declared relations. Terminates: each table is derived once. Source: https://sqlite.org/lang_with.html. Status: Implemented.
Methods§
public function bind(WithClause $with, Derivation $derivation, Environment $outer): EnvironmentDerives the tables and answers the environment in which they are visible.
Parameters
$with | WithClause | |
$derivation | Derivation | |
$outer | Environment |
Returns
Test cases 3
Called from 2
- method-call SqlSemantics\Platform\Sqlite\Rules\Mutation\MutationScope::open() packages/sql-semantics-sqlite/src/Rules/Mutation/MutationScope.php:55
- method-call SqlSemantics\Platform\Sqlite\Statement\Query\With\WithQuery::deriveQuery() packages/sql-semantics-sqlite/src/Statement/Query/With/WithQuery.php:59
Calls 11
- method-call CommonTables::uses() line 58
- method-call Derivation::report() line 60
- new Misuse line 60
- class-const MisuseRule::DuplicateCommonTable() line 60
- function-call
array_key_firstline 80 - class-const MisuseRule::CircularReference() line 82
- method-call Derivation::query() line 88
- new Environment line 88
- new CommonBinding line 88
- method-call CommonTables::provisional() line 88
- method-call CommonTables::shape() line 89
public function uses(CommonTable $table): array<string, true>Answers the unqualified table names the query of a common table reads from, folded.
Parameters
$table | CommonTable |
Returns
array<string, true>Test cases 1
Called from 1
Calls 3
- method-call ValueGraph::objects() line 103
- new ValueGraph line 103
- function-call
strtrline 105
public function provisional(CommonTable $table): RowShapeAnswers the shape a common table has while its own query is derived.
Parameters
$table | CommonTable |
Returns
Called from 1
Calls 8
- method-call RelationNames::listed() line 118
- new RelationNames line 118
- function-call
array_mapline 118 - new OutputSlot line 119
- new Choice line 119
- static-call Storage::cases() line 119
- class-const Nullability::Nullable() line 119
- new RowShape line 122
public function shape(CommonTable $table, QueryFact $fact, Derivation $derivation): RowShapeAnswers the shape of a common table from the output of its query and its column list.
Parameters
$table | CommonTable | |
$fact | QueryFact | |
$derivation | Derivation |
Returns
Test cases 3
Called from 1
Calls 17
- method-call RelationNames::shape() line 130
- new RelationNames line 130
- method-call RelationNames::listed() line 131
- function-call
array_mapline 131 - function-call
countline 135 - method-call Derivation::report() line 136
- new ArityMismatch line 136
- class-const ArityRule::CommonTableColumns() line 136
- new OutputSlot line 144
- new Choice line 144
- static-call Storage::cases() line 144
- new Dependent line 144
- class-const Nullability::Nullable() line 144
- class-const Nullability::Dependent() line 144
- new Misuse line 148
- class-const MisuseRule::DecoratedColumnName() line 148
- new RowShape line 151
Test cases 8§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 8
CommonTablesTest::testBindMakesEveryTableVisibleWhateverTheWrittenOrdercallsCommonTablesTest::testBindReportsARepeatedNameAndACircularReferencecallsCommonTablesTest::testBindTypesARecursiveReferenceAsAnyStorageClasscallsCommonTablesTest::testProvisionalHasOneSlotPerListedColumnThatCanHoldAnythingcallsCommonTablesTest::testShapeDependsOnTheMissingInputsOfAnOpenQuerycallsCommonTablesTest::testShapeKeepsTheQueryNamesWithoutAListAndReportsADecoratedNamecallsCommonTablesTest::testShapeRenamesTheColumnsByTheListAndReportsAnotherLengthcallsCommonTablesTest::testUsesAnswersTheUnqualifiedTableNamesFoldedcalls
Relations§
Instantiated in 2
Method calls 2
- method-call SqlSemantics\Platform\Sqlite\Rules\Mutation\MutationScope::open() packages/sql-semantics-sqlite/src/Rules/Mutation/MutationScope.php:55
- method-call SqlSemantics\Platform\Sqlite\Statement\Query\With\WithQuery::deriveQuery() packages/sql-semantics-sqlite/src/Statement/Query/With/WithQuery.php:59