classRelationNames
final class RelationNames
Names the columns a query result has when the query is used as a relation.
Rule: SQLITE-RELATION-NAME-001. SQLite names the columns of a subquery in FROM and of a common table before it resolves the query (sqlite3ColumnsFromExprList() in select.c of release 3.47.2), from the leftmost arm of a compound query. A column takes the alias of its result column; without an alias, a result column that is one word (a column name with or without qualifier, a double-quoted word or a truth word, possibly in parentheses or under COLLATE) takes that word as written, whatever it resolves to, and any other result column takes the span of its expression (SQLITE-RESULT-NAME-001). A column a star contributes keeps the name of the column it copies. An expression of a VALUES row is named by its word, or columnN after its position when it is no word. A column that would be named TRUE or FALSE is renamed columnN. A name that repeats an earlier one, compared without regard to ASCII case, has its trailing :digits replaced by :1, :2, :3 and :4 in turn; after the fourth attempt SQLite picks the digits at random, so such a name is not fixed (a random name is taken not to repeat a later one). After a star that missing declarations prevent from expanding, or after a name that depends on missing inputs, the positions or the earlier names are unknown, so no later name is fixed: each depends on those inputs (OutputSlot::$unnamed). Every column refers to the result column it comes from. Terminates: one pass over the fields with at most four renames each. Source: https://sqlite.org/lang_select.html#the_from_clause, https://sqlite.org/c3ref/column_name.html. Status: Implemented.
Methods§
public function shape(QueryFact $fact, Query $query, Derivation $derivation): RowShapeAnswers the row shape a query result contributes as a relation.
Parameters
$fact | QueryFact | The output of the query |
$query | Query | The query |
$derivation | Derivation | The derivation that recorded the output of the arms of the query |
Returns
Test cases 4
RelationNamesTest::testShapeKeepsAnUndecidedNameAndTheNamesAfterItDependentcallsRelationNamesTest::testShapeKeepsTheMissingInputsAndLeavesTheNamesAfterAnOpenStarUnnamedcallsRelationNamesTest::testShapeLetsAnAliasWinAndCountsItAmongTheDuplicatescallsRelationNamesTest::testShapeNamesTheColumnsAsSqliteDoesBeforeResolutioncalls
Called from 3
- method-call SqlSemantics\Platform\Sqlite\Rules\Query\CommonTables::shape() packages/sql-semantics-sqlite/src/Rules/Query/CommonTables.php:130
- method-call SqlSemantics\Platform\Sqlite\Rules\Query\CompoundFacts::rebound() packages/sql-semantics-sqlite/src/Rules/Query/CompoundFacts.php:181
- method-call SqlSemantics\Platform\Sqlite\Statement\Relation\DerivedQuery::deriveRelation() packages/sql-semantics-sqlite/src/Statement/Relation/DerivedQuery.php:53
Calls 12
- new ResultNames line 58
- method-call ResultNames::leftmost() line 59
- method-call Derivation::facts() line 60
- function-call
spl_object_idline 67 - function-call
countline 71 - method-call ResultNames::truth() line 73
- method-call RelationNames::named() line 73
- method-call RelationNames::unique() line 74
- function-call
array_valuesline 75 - class-const Comparison::AsciiInsensitive() line 77
- new OutputSlot line 82
- new RowShape line 85
public function named(Field $field, Select|ValuesClause $arm, int $position): ?NameAnswers the name of a column of the leftmost arm before TRUE and FALSE are renamed and duplicates are told apart.
Parameters
$field | Field | The output field of the arm |
$arm | Select|ValuesClause | |
$position | int | The position of the field, from zero |
Returns
?NameTest cases 2
Called from 1
Calls 5
- new ResultNames line 96
- method-call ResultNames::written() line 98
- new Name line 98
- method-call ResultNames::column() line 100
- method-call ResultNames::relation() line 102
Answers the names of a column list, as SQLite gives them to the columns of a common table.
Parameters
$listed | list<Name> | The names as written |
Returns
list<Name|null>Test cases 1
Called from 3
- method-call SqlSemantics\Platform\Sqlite\Rules\Query\CommonTables::provisional() packages/sql-semantics-sqlite/src/Rules/Query/CommonTables.php:118
- method-call SqlSemantics\Platform\Sqlite\Rules\Query\CommonTables::shape() packages/sql-semantics-sqlite/src/Rules/Query/CommonTables.php:131
- method-call SqlSemantics\Platform\Sqlite\Rules\Query\CompoundFacts::rebound() packages/sql-semantics-sqlite/src/Rules/Query/CompoundFacts.php:180
Calls 4
- method-call RelationNames::unique() line 116
- method-call ResultNames::truth() line 116
- new ResultNames line 116
- class-const Comparison::AsciiInsensitive() line 118
Answers a name that repeats none of the names seen, or null when SQLite would pick it at random.
Parameters
$name | ?Name | |
$seen | array<string, true> | The names already used, folded |
Returns
?NameTest cases 2
Called from 2
Calls 3
- class-const Comparison::AsciiInsensitive() line 133
- function-call
preg_replaceline 138 - new Name line 140
Test cases 9§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 9
RelationNamesTest::testListedRenamesTruthWordsAndRepeatedNamescallsRelationNamesTest::testNamedPrefersTheAliasThenTheWrittenWordThenTheTextcallsRelationNamesTest::testNamedReadsTheWordOfAValuesColumnOrItsPositioncallsRelationNamesTest::testShapeKeepsAnUndecidedNameAndTheNamesAfterItDependentcallsRelationNamesTest::testShapeKeepsTheMissingInputsAndLeavesTheNamesAfterAnOpenStarUnnamedcallsRelationNamesTest::testShapeLetsAnAliasWinAndCountsItAmongTheDuplicatescallsRelationNamesTest::testShapeNamesTheColumnsAsSqliteDoesBeforeResolutioncallsRelationNamesTest::testUniqueAppendsACounterUntilTheFourthAttemptcallsRelationNamesTest::testUniqueDropsAnExistingCounterAndComparesWithoutCasecalls
Relations§
Instantiated in 6
- new SqlSemantics\Platform\Sqlite\Rules\Query\CommonTables::provisional() packages/sql-semantics-sqlite/src/Rules/Query/CommonTables.php:118
- new SqlSemantics\Platform\Sqlite\Rules\Query\CommonTables::shape() packages/sql-semantics-sqlite/src/Rules/Query/CommonTables.php:130
- new SqlSemantics\Platform\Sqlite\Rules\Query\CommonTables::shape() packages/sql-semantics-sqlite/src/Rules/Query/CommonTables.php:131
- new SqlSemantics\Platform\Sqlite\Rules\Query\CompoundFacts::rebound() packages/sql-semantics-sqlite/src/Rules/Query/CompoundFacts.php:180
- new SqlSemantics\Platform\Sqlite\Rules\Query\CompoundFacts::rebound() packages/sql-semantics-sqlite/src/Rules/Query/CompoundFacts.php:181
- new SqlSemantics\Platform\Sqlite\Statement\Relation\DerivedQuery::deriveRelation() packages/sql-semantics-sqlite/src/Statement/Relation/DerivedQuery.php:53
Method calls 6
- method-call SqlSemantics\Platform\Sqlite\Rules\Query\CommonTables::provisional() packages/sql-semantics-sqlite/src/Rules/Query/CommonTables.php:118
- method-call SqlSemantics\Platform\Sqlite\Rules\Query\CommonTables::shape() packages/sql-semantics-sqlite/src/Rules/Query/CommonTables.php:130
- method-call SqlSemantics\Platform\Sqlite\Rules\Query\CommonTables::shape() packages/sql-semantics-sqlite/src/Rules/Query/CommonTables.php:131
- method-call SqlSemantics\Platform\Sqlite\Rules\Query\CompoundFacts::rebound() packages/sql-semantics-sqlite/src/Rules/Query/CompoundFacts.php:180
- method-call SqlSemantics\Platform\Sqlite\Rules\Query\CompoundFacts::rebound() packages/sql-semantics-sqlite/src/Rules/Query/CompoundFacts.php:181
- method-call SqlSemantics\Platform\Sqlite\Statement\Relation\DerivedQuery::deriveRelation() packages/sql-semantics-sqlite/src/Statement/Relation/DerivedQuery.php:53