classQueryColumns
final class QueryColumns
Derives the columns of a table or view that is defined by a query.
Rule: SQLITE-QUERY-COLUMNS-001. The object has one column per output field of the query, in order.
Names: a column takes the name SQLite gives the result column after resolution (SQLITE-RESULT-NAME-001): its alias, the declared name of the column a column reference denotes (looking through parentheses, COLLATE, likely(), unlikely() and likelihood()), or the span of its expression; a column a star contributes keeps the name of the column it copies, and a column of a VALUES row is named columnN after its position. A name TRUE or FALSE, in any letter case, becomes columnN. A name an earlier column already has, compared without regard to ASCII case, is made unique by replacing a trailing :digits with :1, :2, :3, :4 in turn; after four attempts SQLite picks random digits, so the name is not determined. A view with a column list takes its names from the list instead, made unique the same way.
Types: the affinity of each field is derived by SQLITE-QUERY-COLUMN-AFFINITY-001 and the recorded type by SQLITE-QUERY-COLUMN-TYPE-001: a created table is written from the affinity alone, a view keeps the declared type of a column it simply refers to. A view whose column list has another length than its query gets no types at all.
NULL facts: a column of a created table has no NOT NULL constraint and can hold NULL whatever the query returns; a view column has the NULL fact of its field.
Minimum precision: the listed columns are exact. The column list is incomplete, and stops at the first undetermined position, when the query shape is open, when a field has no determined name (a word that may be a column of an undeclared table or a literal), when a unique name is not determined, or when the affinity of a field depends on a declaration the context lacks. Terminates: one pass over the fields with at most four renames each. Source: https://sqlite.org/lang_createtable.html#create_table_as_select_statements, https://sqlite.org/lang_createview.html (and sqlite3ColumnsFromExprList() in select.c of the release). Status: Implemented.
Methods§
Answers the leading output fields of a query whose position is determined: those before the first unexpanded star.
Parameters
$query | QueryFact |
Returns
list<Field>Test cases 1
Called from 3
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\Query\QueryColumns::named() packages/sql-semantics-sqlite/src/Rules/Definition/Query/QueryColumns.php:97
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\Query\QueryColumns::named() packages/sql-semantics-sqlite/src/Rules/Definition/Query/QueryColumns.php:98
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\Query\QueryColumns::viewColumns() packages/sql-semantics-sqlite/src/Rules/Definition/Query/QueryColumns.php:191
Answers the names SQLite gives the leading fields of a query that defines a view or a table, before duplicates are told apart.
The leftmost arm of the query names the fields after resolution (SQLITE-RESULT-NAME-001); a field a star contributes keeps the name of the column it copies, a field of a VALUES row is named columnN, and a name TRUE or FALSE becomes columnN.
Returns
list<Name|null>Test cases 1
Called from 2
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\Query\QueryColumns::tableColumns() packages/sql-semantics-sqlite/src/Rules/Definition/Query/QueryColumns.php:170
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\Query\QueryColumns::viewColumns() packages/sql-semantics-sqlite/src/Rules/Definition/Query/QueryColumns.php:198
Calls 8
- new ResultNames line 95
- method-call ResultNames::leftmost() line 96
- method-call QueryColumns::settled() line 97
- method-call Facts::query() line 98
- method-call ResultNames::column() line 101
- method-call ResultNames::declared() line 102
- method-call ResultNames::truth() line 103
- new Name line 103
public function unique(list<Name|null> $names, Comparison $comparison): list<Name>Makes column names unique as SQLite does; the list ends before the first name that is not determined.
Parameters
$names | list<Name|null> | The name of each column in order; null when a name is not determined |
$comparison | Comparison |
Returns
list<Name>Test cases 2
Called from 2
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\Query\QueryColumns::tableColumns() packages/sql-semantics-sqlite/src/Rules/Definition/Query/QueryColumns.php:170
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\Query\QueryColumns::viewColumns() packages/sql-semantics-sqlite/src/Rules/Definition/Query/QueryColumns.php:200
Calls 3
- method-call QueryColumns::taken() line 120
- new Name line 121
- method-call QueryColumns::stem() line 121
public function taken(string $name, list<Name> $names, Comparison $comparison): boolTells whether an earlier column has a name.
Parameters
$name | string | |
$names | list<Name> | |
$comparison | Comparison |
Returns
boolTest cases 1
Called from 1
Calls 1
- method-call Comparison::equal() line 140
public function stem(string $name): stringAnswers a name without a trailing colon and digits.
Parameters
$name | string |
Returns
stringTest cases 1
Called from 1
public function tableColumns(
Query $query,
QueryFact $output,
Facts $facts,
Comparison $comparison,
): list<Column>Answers the columns of a table created from a query.
Parameters
$query | Query | The query; its output must be the given fact |
$output | QueryFact | |
$facts | Facts | |
$comparison | Comparison |
Returns
list<Column>Test cases 3
Called from 1
Calls 8
- method-call QueryColumns::unique() line 170
- method-call QueryColumns::named() line 170
- method-call ExpressionAffinity::column() line 171
- new ExpressionAffinity line 171
- new Column line 175
- method-call ColumnTyping::tableType() line 175
- new ColumnTyping line 175
- class-const Nullability::Nullable() line 175
public function viewColumns(
Query $query,
QueryFact $output,
Facts $facts,
list<Name>|null $listed,
Comparison $comparison,
bool $typed = true,
): list<Column>Answers the columns of a view.
Parameters
$query | Query | The query; its output must be the given fact |
$output | QueryFact | |
$facts | Facts | |
$listed | list<Name>|null | The names of the column list of the view, when it has one |
$comparison | Comparison | |
$typed | bool | Whether SQLite assigns the column types; it does not when a column list has another length than the query result |
Returns
list<Column>Test cases 4
QueryColumnsTest::testViewColumnsGiveNoTypesWhenTheColumnListDoesNotFitTheQuerycallsQueryColumnsTest::testViewColumnsKeepTheDeclaredTypeAndTheNullFactOfAReferencedColumncallsQueryColumnsTest::testViewColumnsRecordACompoundFromItsArmscallsQueryColumnsTest::testViewColumnsTakeTheirNamesFromAColumnListAndStopAtANameWithoutAFieldcalls
Called from 1
Calls 13
- method-call QueryColumns::settled() line 191
- method-call ResultNames::truth() line 194
- new ResultNames line 194
- method-call QueryColumns::named() line 198
- method-call QueryColumns::unique() line 200
- new Column line 203
- new NoAffinity line 203
- class-const Nullability::Dependent() line 203
- method-call ExpressionAffinity::column() line 206
- new ExpressionAffinity line 206
- method-call ColumnTyping::viewType() line 210
- new ColumnTyping line 210
- method-call ColumnTyping::leftmost() line 210
Test cases 13§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 13
QueryColumnsTest::testNamedGivesTheNamesSqliteGivesAfterResolutioncallsQueryColumnsTest::testSettledStopsBeforeTheFirstUnexpandedStarcallsQueryColumnsTest::testStemDropsATrailingColonAndDigitscallsQueryColumnsTest::testTableColumnsRecordACompoundFromItsArmscallsQueryColumnsTest::testTableColumnsRecordTheTypeOfTheExpressionAffinitycallsQueryColumnsTest::testTableColumnsStopAtAFieldWithoutADeterminedNameOrAffinitycallsQueryColumnsTest::testTakenComparesNamesWithoutRegardToCasecallsQueryColumnsTest::testUniqueEndsBeforeANameThatIsNotDeterminedcallsQueryColumnsTest::testUniqueRenamesARepeatedNameAsSqliteDoescallsQueryColumnsTest::testViewColumnsGiveNoTypesWhenTheColumnListDoesNotFitTheQuerycallsQueryColumnsTest::testViewColumnsKeepTheDeclaredTypeAndTheNullFactOfAReferencedColumncallsQueryColumnsTest::testViewColumnsRecordACompoundFromItsArmscallsQueryColumnsTest::testViewColumnsTakeTheirNamesFromAColumnListAndStopAtANameWithoutAFieldcalls
Relations§
Instantiated in 2
- new SqlSemantics\Platform\Sqlite\Statement\Schema\CreateTableAs::deriveStatement() packages/sql-semantics-sqlite/src/Statement/Schema/CreateTableAs.php:66
- new SqlSemantics\Platform\Sqlite\Statement\Schema\CreateView::deriveStatement() packages/sql-semantics-sqlite/src/Statement/Schema/CreateView.php:91
Method calls 2
- method-call SqlSemantics\Platform\Sqlite\Statement\Schema\CreateTableAs::deriveStatement() packages/sql-semantics-sqlite/src/Statement/Schema/CreateTableAs.php:66
- method-call SqlSemantics\Platform\Sqlite\Statement\Schema\CreateView::deriveStatement() packages/sql-semantics-sqlite/src/Statement/Schema/CreateView.php:91