classResultNames
final class ResultNames
Names a result column the way SQLite does.
Rule: SQLITE-RESULT-NAME-001. An alias always names its column. Without one, SQLite keeps the span of the expression, the text from its first token to the start of the token that follows it, without the whitespace at its end, so with the comments between its tokens and after it, and names the column in one of three ways (release 3.47.2, select.c): (1) the rows a statement returns, of a SELECT or of RETURNING (sqlite3GenerateColumnNames(), short_column_names on): an expression that is a column reference, possibly in parentheses, which resolves to a column takes the name of that column as it is declared (rowid and its synonyms take the name of the integer primary key column, or rowid); any other expression is named by its span; (2) a subquery in FROM and a common table (sqlite3ExpandSubquery() and withExpand()), named before resolution: an expression that is one word, possibly qualified, in parentheses or under COLLATE, takes the word as written; any other expression is named by its span; (3) a view and a table created from a query (sqlite3ResultSetOfSelect()), named after resolution: like (1), but COLLATE and the likely(), unlikely() and likelihood() functions are looked through as well. The span is the layout the column keeps (CORE-SPELLING-001); a column built without a layout is rendered canonically and named after that rendering, which is the text the database reads. Of a compound query the leftmost arm names the columns; the expressions of a VALUES row have no span. Source: https://sqlite.org/c3ref/column_name.html, https://sqlite.org/lang_select.html. Status: Implemented.
Constants§
public const LIKELIHOOD = ['likely' => 1, 'unlikely' => 1, 'likelihood' => 2]The functions SQLite looks through when it names a view column, by lower-case name, with their argument count.
Methods§
public function span(ResultColumn $column): NameAnswers the span of a result column: its expression as written, from the first token to the start of the next, without the whitespace at the end.
Parameters
$column | ResultColumn |
Returns
Test cases 1
Called from 4
- method-call SqlSemantics\Platform\Sqlite\Rules\Query\ResultNames::output() packages/sql-semantics-sqlite/src/Rules/Query/ResultNames.php:91
- method-call SqlSemantics\Platform\Sqlite\Rules\Query\ResultNames::resolved() packages/sql-semantics-sqlite/src/Rules/Query/ResultNames.php:140
- method-call SqlSemantics\Platform\Sqlite\Rules\Query\ResultNames::relation() packages/sql-semantics-sqlite/src/Rules/Query/ResultNames.php:166
- method-call SqlSemantics\Platform\Sqlite\Rules\Query\ResultNames::declared() packages/sql-semantics-sqlite/src/Rules/Query/ResultNames.php:184
Calls 4
- new Name line 73
- method-call Canonical::span() line 73
- new Canonical line 73
- method-call Canonical::layout() line 73
public function output(ResultColumn $column, Resolution|null $resolution): ?NameAnswers the name a result column has in the rows a statement returns, or null when it depends on a missing declaration.
Parameters
$column | ResultColumn | |
$resolution | Resolution|null | The resolution of the expression, looked through parentheses |
Returns
?NameCalled from 2
Calls 2
- method-call ResultNames::span() line 91
- method-call ResultNames::resolved() line 94
public function unnamed(ResultColumn $column, Resolution|null $resolution): list<MissingInput>Answers the missing inputs that leave the name of a result column in the rows a statement returns undecided; empty when the name is decided or depends on nothing missing.
A word that may be a column of an undeclared table or a literal is named either after the column or after its span; a column reference takes over an undecided name of the column it resolves to.
Parameters
$column | ResultColumn | |
$resolution | Resolution|null | The resolution of the expression, looked through parentheses |
Returns
list<MissingInput>Test cases 1
Called from 1
Calls 1
- method-call ResultNames::output() line 109
public function resolved(
ResultColumn $column,
ColumnUse|DoubleQuotedWord|TruthWord $expression,
?Resolution $resolution,
): ?NameAnswers the name of a result column that is a name use from its resolution.
A column takes its declared name. A plain column name that resolves to nothing, which SQLite refuses, keeps the name as written; a double-quoted word or a truth word that resolves to nothing is a literal and is named by its span. Where the resolution is conditional on a missing declaration, so is the name of a word that may still be a literal.
Parameters
$column | ResultColumn | |
$expression | ColumnUse|DoubleQuotedWord|TruthWord | |
$resolution | ?Resolution |
Returns
?NameCalled from 2
Calls 1
- method-call ResultNames::span() line 140
public function relation(ResultColumn $column): NameAnswers the name of a result column of a subquery or common table, which SQLite gives before resolution.
Parameters
$column | ResultColumn |
Returns
Called from 1
Calls 2
- method-call ResultNames::written() line 166
- method-call ResultNames::span() line 166
public function declared(ResultColumn $column, Facts $facts): ?NameAnswers the name of a result column of a view or created table, or null when it depends on a missing declaration.
Parameters
$column | ResultColumn | |
$facts | Facts | The facts of the query, which include the expressions of the column |
Returns
?NameCalled from 1
Calls 4
- method-call ResultNames::inner() line 180
- method-call ResultNames::span() line 184
- method-call ResultNames::resolved() line 186
- method-call Facts::scalar() line 186
Answers the operand SQLite looks through when it names a view column: of parentheses, of COLLATE, and the first argument of likely(), unlikely() and likelihood(); null for any other expression.
Parameters
$expression | Scalar |
Returns
Called from 1
Calls 3
- class-const ResultNames::LIKELIHOOD() line 197
- function-call
strtolowerline 197 - function-call
countline 197
public function leftmost(Query $query): Select|ValuesClause|nullAnswers the arm of a query that names its columns: the leftmost selection or VALUES clause.
Parameters
$query | Query |
Returns
Select|ValuesClause|nullTest cases 1
Called from 2
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\Query\QueryColumns::named() packages/sql-semantics-sqlite/src/Rules/Definition/Query/QueryColumns.php:96
- method-call SqlSemantics\Platform\Sqlite\Rules\Query\RelationNames::shape() packages/sql-semantics-sqlite/src/Rules/Query/RelationNames.php:59
public function column(Select $select, Field $field): ?ResultColumnAnswers the result column of a selection a field projects, or null for a field a star contributes.
Returns
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:101
- method-call SqlSemantics\Platform\Sqlite\Rules\Query\CompoundFacts::spelled() packages/sql-semantics-sqlite/src/Rules/Query/CompoundFacts.php:158
- method-call SqlSemantics\Platform\Sqlite\Rules\Query\RelationNames::named() packages/sql-semantics-sqlite/src/Rules/Query/RelationNames.php:100
Applies the rule that a column SQLite would name TRUE or FALSE, in any letter case, is named columnN after its position.
Parameters
$name | ?Name | |
$position | int | The position of the column, from zero |
Returns
?NameTest cases 1
Called from 4
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\Query\QueryColumns::named() packages/sql-semantics-sqlite/src/Rules/Definition/Query/QueryColumns.php:103
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\Query\QueryColumns::viewColumns() packages/sql-semantics-sqlite/src/Rules/Definition/Query/QueryColumns.php:194
- method-call SqlSemantics\Platform\Sqlite\Rules\Query\RelationNames::shape() packages/sql-semantics-sqlite/src/Rules/Query/RelationNames.php:73
- method-call SqlSemantics\Platform\Sqlite\Rules\Query\RelationNames::listed() packages/sql-semantics-sqlite/src/Rules/Query/RelationNames.php:116
Calls 3
- function-call
in_arrayline 237 - class-const Comparison::AsciiInsensitive() line 237
- new Name line 238
Test cases 9§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 9
ResultNamesTest::testColumnFindsTheResultColumnOfAFieldAndNoneForAStarcallsResultNamesTest::testInnerLooksThroughParenthesesCollateAndTheLikelihoodFunctionscallsResultNamesTest::testLeftmostFindsTheArmThatNamesTheColumnscallsResultNamesTest::testRelationPrefersTheAliasThenTheWrittenWordThenTheTextcallsResultNamesTest::testResolvedLeavesAWordConditionalOnAMissingDeclarationUnnamedcallsResultNamesTest::testSpanAnswersTheLayoutTextOrTheCanonicalRenderingcallsResultNamesTest::testTruthRenamesTrueAndFalseAfterThePositioncallsResultNamesTest::testUnnamedAnswersTheInputsAnUndecidedNameDependsOncallsResultNamesTest::testWrittenAnswersTheOneWordAnExpressionConsistsOfcalls
Relations§
Instantiated in 7
- new SqlSemantics\Platform\Sqlite\Rules\Definition\Query\QueryColumns::named() packages/sql-semantics-sqlite/src/Rules/Definition/Query/QueryColumns.php:95
- new SqlSemantics\Platform\Sqlite\Rules\Definition\Query\QueryColumns::viewColumns() packages/sql-semantics-sqlite/src/Rules/Definition/Query/QueryColumns.php:194
- new SqlSemantics\Platform\Sqlite\Rules\Query\CompoundFacts::spelled() packages/sql-semantics-sqlite/src/Rules/Query/CompoundFacts.php:158
- new SqlSemantics\Platform\Sqlite\Rules\Query\Projection::items() packages/sql-semantics-sqlite/src/Rules/Query/Projection.php:65
- new SqlSemantics\Platform\Sqlite\Rules\Query\RelationNames::shape() packages/sql-semantics-sqlite/src/Rules/Query/RelationNames.php:58
- new SqlSemantics\Platform\Sqlite\Rules\Query\RelationNames::named() packages/sql-semantics-sqlite/src/Rules/Query/RelationNames.php:96
- new SqlSemantics\Platform\Sqlite\Rules\Query\RelationNames::listed() packages/sql-semantics-sqlite/src/Rules/Query/RelationNames.php:116
Method calls 14
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\Query\QueryColumns::named() packages/sql-semantics-sqlite/src/Rules/Definition/Query/QueryColumns.php:96
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\Query\QueryColumns::named() packages/sql-semantics-sqlite/src/Rules/Definition/Query/QueryColumns.php:101
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\Query\QueryColumns::named() packages/sql-semantics-sqlite/src/Rules/Definition/Query/QueryColumns.php:102
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\Query\QueryColumns::named() packages/sql-semantics-sqlite/src/Rules/Definition/Query/QueryColumns.php:103
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\Query\QueryColumns::viewColumns() packages/sql-semantics-sqlite/src/Rules/Definition/Query/QueryColumns.php:194
- method-call SqlSemantics\Platform\Sqlite\Rules\Query\CompoundFacts::spelled() packages/sql-semantics-sqlite/src/Rules/Query/CompoundFacts.php:158
- method-call SqlSemantics\Platform\Sqlite\Rules\Query\Projection::items() packages/sql-semantics-sqlite/src/Rules/Query/Projection.php:66
- method-call SqlSemantics\Platform\Sqlite\Rules\Query\Projection::items() packages/sql-semantics-sqlite/src/Rules/Query/Projection.php:66
- method-call SqlSemantics\Platform\Sqlite\Rules\Query\RelationNames::shape() packages/sql-semantics-sqlite/src/Rules/Query/RelationNames.php:59
- method-call SqlSemantics\Platform\Sqlite\Rules\Query\RelationNames::shape() packages/sql-semantics-sqlite/src/Rules/Query/RelationNames.php:73
- method-call SqlSemantics\Platform\Sqlite\Rules\Query\RelationNames::named() packages/sql-semantics-sqlite/src/Rules/Query/RelationNames.php:98
- method-call SqlSemantics\Platform\Sqlite\Rules\Query\RelationNames::named() packages/sql-semantics-sqlite/src/Rules/Query/RelationNames.php:100
- method-call SqlSemantics\Platform\Sqlite\Rules\Query\RelationNames::named() packages/sql-semantics-sqlite/src/Rules/Query/RelationNames.php:102
- method-call SqlSemantics\Platform\Sqlite\Rules\Query\RelationNames::listed() packages/sql-semantics-sqlite/src/Rules/Query/RelationNames.php:116