classLiteralColumn
final class LiteralColumn
implements Scalar
uses Snapshot
@visibility public.A column named by a string literal in a key constraint or an index term.
Rule: SQLITE-LITERAL-COLUMN-001. For compatibility with old databases, SQLite reads a string literal written as a term of a PRIMARY KEY or UNIQUE constraint (under any parentheses and COLLATE clauses) or of CREATE INDEX (under parentheses and at most one COLLATE clause) as an identifier, which must name a column of the table. The literal keeps its spelling; the name is its value. Facts: those of the column the name resolves to in the table being defined or indexed (SQLITE-COLUMN-LOOKUP-001); a name that is no column is a missing column, as "no such column" is for SQLite. A string at any other position, a doubly collated string in an index term included, is the text constant it is. Source: https://sqlite.org/lang_createtable.html#the_primary_key, https://sqlite.org/lang_createindex.html (and sqlite3StringToId() in build.c of the release). Status: Implemented.
$create = (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze("CREATE TABLE t (a INTEGER, PRIMARY KEY ('a'))");
$term = $create->statement->constraints[0]->items[0]->terms[0]->expression;
[$term->literal->value, $create->facts->scalar($term)->resolution->slot->column === $create->declarations()[0]->columns[0], $create->declarations()[0]->implicit[0]->column === $create->declarations()[0]->columns[0], $create->toString()] // => ['a', true, true, "CREATE TABLE t (a INTEGER, PRIMARY KEY ('a'))"]Properties§
public TextLiteral $literalMethods§
public function __construct(public TextLiteral $literal)Parameters
$literal | TextLiteral | The string literal whose value is the column name |
public function name(): NameAnswers the column name the literal spells.
Returns
Test cases 1
Called from 1
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFactDerives the facts of the column the name resolves to; the literal itself keeps the facts of the text it spells.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 6
- method-call Derivation::scalar() line 65
- method-call ColumnFacts::of() line 67
- new ColumnFacts line 67
- method-call ColumnResolver::find() line 67
- new ColumnResolver line 67
- method-call LiteralColumn::name() line 67
public function render(Output $out): voidTest cases 7§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 2
Other tests reaching this symbol 5
KeyTermRuleTest::testExpressionRebuildsTheWrappersInOrderAroundTheLiteralcallsKeyTermRuleTest::testIndexTermsWrapAStringUnderAtMostOneCollationcallsKeyTermRuleTest::testKeyTermsWrapAStringUnderAnyParenthesesAndCollationscallsKeyTermsTest::testColumnReadsAPlainNameAStringAndADoubleQuotedWordcallsKeyTermsTest::testReferenceAcceptsEveryColumnReferenceAndNoOtherExpressioncalls
Relations§
Instantiated in 1
Type checks 5
- instanceof SqlSemantics\Platform\Sqlite\Rules\Definition\KeyTerms::column() packages/sql-semantics-sqlite/src/Rules/Definition/KeyTerms.php:86
- instanceof SqlSemantics\Platform\Sqlite\Rules\Definition\KeyTerms::reference() packages/sql-semantics-sqlite/src/Rules/Definition/KeyTerms.php:96
- instanceof SqlSemantics\Platform\Sqlite\Rules\Definition\Query\ColumnTyping::text() packages/sql-semantics-sqlite/src/Rules/Definition/Query/ColumnTyping.php:96
- instanceof SqlSemantics\Platform\Sqlite\Rules\Definition\Query\ExpressionAffinity::of() packages/sql-semantics-sqlite/src/Rules/Definition/Query/ExpressionAffinity.php:91
- instanceof SqlSemantics\Platform\Sqlite\Rules\Definition\Query\ValueKinds::of() packages/sql-semantics-sqlite/src/Rules/Definition/Query/ValueKinds.php:103