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

Derives the declared type SQLite records for a column of a view or of a table made from a query.

Rule: SQLITE-QUERY-COLUMN-TYPE-001. A result expression carries a declared type text when it is a column reference, in parentheses or not: the declared type of a table column (none when the column declares no type), INTEGER for the row identifier, the type a view records for its column, or, for a column of a derived table or a common table, the text carried by the expression at that position in the rightmost arm of its query; a scalar subquery carries the text of the first result of its rightmost arm; COLLATE and every other expression carry none. A column of the view or table being defined carries the text of the expression at its position in the leftmost arm of the defining query.

A view records the carried text when the affinity SQLite derives from that text (the five substring rules, NUMERIC for an empty text) is the affinity of the column (SQLITE-QUERY-COLUMN-AFFINITY-001) and that affinity is not the flexible numeric one; otherwise it records NUM for a numeric affinity, the standard name of any other affinity, and no type (NoAffinity) for a column without affinity. A table made from a query is written from the affinity alone: INT, TEXT, REAL, NUM, and no type for BLOB or no affinity. Precision: exact. Terminates: each step enters a strictly nested query or a strict sub-expression. Source: https://sqlite.org/lang_createtable.html#create_table_as_select_statements, https://sqlite.org/lang_createview.html, https://sqlite.org/datatype3.html#determination_of_column_affinity (and columnType(), sqlite3SubqueryColumnTypes() and createTableStmt() in select.c and build.c of the release). Status: Implemented.

Methods§

public function leftmost(Query $query, int $position, Facts $facts): ?string

Answers the declared type text a column of a defining query carries: that of the leftmost arm at its position.

Parameters

$queryQuery
$positionint
$factsFacts

Returns

?string
Test cases 1
Called from 1
Calls 3
public function field(Field $field, Facts $facts): ?string

Answers the declared type text an output field carries: that of its expression, or of the column an expanded star exposes.

Parameters

$fieldField
$factsFacts

Returns

?string
Test cases 1
Called from 1
Calls 2
public function viewType(DerivedAffinity $affinity, ?string $text): TypeDescriptor
public function tableType(DerivedAffinity $affinity): ColumnDomain

Private surface 2§

Implementation details, listed for orientation only.

private const VIEW = ['Integer' => 'INT', 'Text' => 'TEXT', 'Blob' => 'BLOB', 'Real' => 'REAL', 'Num…
private const TABLE = ['Integer' => 'INT', 'Text' => 'TEXT', 'Blob' => '', 'Real' => 'REAL', 'Numeric…

Test cases 9§

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

Dedicated tests 9

Relations§

Instantiated in 3
Method calls 4