classColumnTyping
final class ColumnTyping
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 textAffinity(string $text): AffinityAnswers the affinity SQLite derives from a type text by the ordered substring rules; an empty text gives NUMERIC.
Parameters
$text | string |
Returns
Test cases 1
Called from 2
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\Query\ColumnTyping::viewType() packages/sql-semantics-sqlite/src/Rules/Definition/Query/ColumnTyping.php:180
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\Query\ExpressionAffinity::declared() packages/sql-semantics-sqlite/src/Rules/Definition/Query/ExpressionAffinity.php:155
Calls 7
- function-call
strtrline 72 - function-call
str_containsline 75 - class-const Affinity::Integer() line 75
- class-const Affinity::Text() line 76
- class-const Affinity::Blob() line 77
- class-const Affinity::Real() line 78
- class-const Affinity::Numeric() line 79
Answers the declared type text an expression carries, or null when it carries none.
Returns
?stringCalled from 2
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\Query\ColumnTyping::arm() packages/sql-semantics-sqlite/src/Rules/Definition/Query/ColumnTyping.php:145
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\Query\ColumnTyping::field() packages/sql-semantics-sqlite/src/Rules/Definition/Query/ColumnTyping.php:166
Calls 7
- method-call ExpressionAffinity::arms() line 92
- new ExpressionAffinity line 92
- method-call ColumnTyping::arm() line 94
- function-call
countline 94 - method-call Facts::covers() line 97
- method-call Facts::scalar() line 97
- method-call ColumnTyping::resolved() line 99
public function resolved(ResolvedColumn $resolution, Facts $facts): ?stringAnswers the declared type text a resolved column carries.
Parameters
$resolution | ResolvedColumn | |
$facts | Facts |
Returns
?stringTest cases 1
Called from 2
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\Query\ColumnTyping::text() packages/sql-semantics-sqlite/src/Rules/Definition/Query/ColumnTyping.php:99
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\Query\ColumnTyping::field() packages/sql-semantics-sqlite/src/Rules/Definition/Query/ColumnTyping.php:169
Calls 7
- method-call ColumnTyping::column() line 111
- new ExpressionAffinity line 113
- method-call ExpressionAffinity::computing() line 114
- method-call ExpressionAffinity::position() line 116
- method-call ExpressionAffinity::arms() line 117
- method-call ColumnTyping::arm() line 119
- function-call
countline 119
public function column(Column $column): ?stringAnswers the declared type text of a declared column, or null when it declares none.
Parameters
$column | Column |
Returns
?stringTest cases 1
Called from 2
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\Query\ColumnTyping::resolved() packages/sql-semantics-sqlite/src/Rules/Definition/Query/ColumnTyping.php:111
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\Query\ColumnTyping::resolved() packages/sql-semantics-sqlite/src/Rules/Definition/Query/ColumnTyping.php:123
Answers the declared type text the result of an arm at a position carries; an expanded star is a column reference.
Returns
?stringTest cases 2
Called from 3
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\Query\ColumnTyping::text() packages/sql-semantics-sqlite/src/Rules/Definition/Query/ColumnTyping.php:94
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\Query\ColumnTyping::resolved() packages/sql-semantics-sqlite/src/Rules/Definition/Query/ColumnTyping.php:119
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\Query\ColumnTyping::leftmost() packages/sql-semantics-sqlite/src/Rules/Definition/Query/ColumnTyping.php:157
Calls 4
- method-call ColumnTyping::text() line 145
- method-call Facts::covers() line 147
- method-call Facts::query() line 147
- method-call ColumnTyping::field() line 149
Answers the declared type text a column of a defining query carries: that of the leftmost arm at its position.
Returns
?stringTest cases 1
Called from 1
Calls 3
- method-call ColumnTyping::arm() line 157
- method-call ExpressionAffinity::arms() line 157
- new ExpressionAffinity line 157
Answers the declared type text an output field carries: that of its expression, or of the column an expanded star exposes.
Returns
?stringCalled from 1
Calls 2
- method-call ColumnTyping::text() line 166
- method-call ColumnTyping::resolved() line 169
public function viewType(DerivedAffinity $affinity, ?string $text): TypeDescriptorAnswers the type a view records for a column with the given affinity and carried text.
Parameters
$affinity | DerivedAffinity | |
$text | ?string |
Returns
Test cases 1
Called from 1
Calls 4
- new NoAffinity line 178
- method-call ColumnTyping::textAffinity() line 180
- new ColumnDomain line 181
- class-const ColumnTyping::VIEW() line 184
public function tableType(DerivedAffinity $affinity): ColumnDomainAnswers the type CREATE TABLE ... AS writes for a column with the given affinity.
Parameters
$affinity | DerivedAffinity |
Returns
Test cases 1
Called from 1
Calls 2
- new ColumnDomain line 192
- class-const ColumnTyping::TABLE() line 192
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
ColumnTypingTest::testArmReadsAnExpandedStarAndARowValuecallsColumnTypingTest::testColumnReadsEachKindOfTypeDescriptorcallsColumnTypingTest::testFieldReadsTheExpressionOrTheColumnAnExpandedStarExposescallsColumnTypingTest::testLeftmostReadsTheLeftmostArmOfADefiningQuerycallsColumnTypingTest::testResolvedReadsTheRightmostArmThroughADerivedTableAndACommonTablecallsColumnTypingTest::testTableTypeWritesTheAffinityAlonecallsColumnTypingTest::testTextAffinityFollowsTheSubstringRulesAndIsNumericForAnEmptyTextcallsColumnTypingTest::testTextReadsTheDeclaredTypeAColumnReferenceCarriescallsColumnTypingTest::testViewTypeRecordsTheCarriedTextOrTheStandardNamecalls
Relations§
Instantiated in 3
- new SqlSemantics\Platform\Sqlite\Rules\Definition\Query\ExpressionAffinity::declared() packages/sql-semantics-sqlite/src/Rules/Definition/Query/ExpressionAffinity.php:155
- new SqlSemantics\Platform\Sqlite\Rules\Definition\Query\QueryColumns::tableColumns() packages/sql-semantics-sqlite/src/Rules/Definition/Query/QueryColumns.php:175
- new SqlSemantics\Platform\Sqlite\Rules\Definition\Query\QueryColumns::viewColumns() packages/sql-semantics-sqlite/src/Rules/Definition/Query/QueryColumns.php:210
Method calls 4
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\Query\ExpressionAffinity::declared() packages/sql-semantics-sqlite/src/Rules/Definition/Query/ExpressionAffinity.php:155
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\Query\QueryColumns::tableColumns() packages/sql-semantics-sqlite/src/Rules/Definition/Query/QueryColumns.php:175
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\Query\QueryColumns::viewColumns() packages/sql-semantics-sqlite/src/Rules/Definition/Query/QueryColumns.php:210
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\Query\QueryColumns::viewColumns() packages/sql-semantics-sqlite/src/Rules/Definition/Query/QueryColumns.php:210