final class QueryColumns
Restricted visibility: declared "@visibility SqlSemantics\Platform\Sqlite". Code outside that scope must not name this declaration.

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§

public function named(Query $query, QueryFact $output, Facts $facts): list<Name|null>

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.

Parameters

$queryQueryThe query; its output must be the given fact
$outputQueryFact
$factsFacts

Returns

list<Name|null>
Test cases 1
Called from 2
Calls 8
public function unique(list<Name|null> $names, Comparison $comparison): list<Name>
public function taken(string $name, list<Name> $names, Comparison $comparison): bool

Tells whether an earlier column has a name.

Parameters

$namestring
$nameslist<Name>
$comparisonComparison

Returns

bool
Test cases 1
Called from 1
Calls 1
public function stem(string $name): string

Answers a name without a trailing colon and digits.

Parameters

$namestring

Returns

string
Test cases 1
Called from 1
Calls 3
public function viewColumns(
    Query $query,
    QueryFact $output,
    Facts $facts,
    list<Name>|null $listed,
    Comparison $comparison,
    bool $typed = true,
): list<Column>

Test cases 13§

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

Dedicated tests 13

Relations§

Instantiated in 2
Method calls 2