classDefaultWord
final class DefaultWord
implements ColumnConstraint
uses Snapshot
@visibility public.A DEFAULT column constraint whose value is written as an identifier.
Rule: SQLITE-COLUMN-DEFAULT-WORD-001. SQLite reads an identifier after DEFAULT as the text of its name, never as a column. The unquoted words TRUE and FALSE are the exception: they are the integers 1 and 0. A quoted "true" is the text again, so the word is kept with its quoting. Source: https://sqlite.org/lang_createtable.html#the_default_clause (grammar ccons ::= DEFAULT scantok id), https://sqlite.org/lang_expr.html#boolean_expressions. Status: Implemented.
$semantics = new \SqlSemantics\Platform\Sqlite\Semantics();
$text = $semantics->analyze('CREATE TABLE t (a DEFAULT unknown)')->statement->columns[0]->constraints[0];
$truth = $semantics->analyze('CREATE TABLE t (a DEFAULT TRUE)')->statement->columns[0]->constraints[0];
[$text->truth(), $text->word->name->value, $truth->truth()] // => [null, 'unknown', true]Properties§
public Word $wordMethods§
public function __construct(public Word $word)Parameters
$word | Word | The identifier with its quoting |
Calls 2
- static-call Check::input() line 42
- class-const WordQuote::Single() line 42
public function truth(): ?boolAnswers the truth value of an unquoted TRUE or FALSE, or null when the word is a text default.
Returns
?boolTest cases 2
Calls 1
- method-call Word::is() line 50
public function deriveConstraint(Derivation $derivation, ConstraintScope $scope): voidDerives nothing: the word is a constant.
Parameters
$derivation | Derivation | |
$scope | ConstraintScope |
public function render(Output $out): voidTest cases 8§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 3
Other tests reaching this symbol 5
ColumnRuleTest::testDefaultLowersEveryFormOfDefaultcallsWordRuleTest::testWordKeepsTheQuotingOfTheTokencallsLiteralDefaultsTest::testDefaultsAnswersTheDefaultClausesInWrittenOrdercallsLiteralDefaultsTest::testLiteralTellsTheDefaultsSqliteComputesWhenAColumnIsAddedcallsLiteralDefaultsTest::testNullIsTheLiteralNullWithOrWithoutParenthesescalls
Relations§
Instantiated in 1
Type checks 3
- instanceof SqlSemantics\Platform\Sqlite\Rules\Definition\Expression\LiteralDefaults::defaults() packages/sql-semantics-sqlite/src/Rules/Definition/Expression/LiteralDefaults.php:50
- instanceof SqlSemantics\Platform\Sqlite\Rules\Definition\Expression\LiteralDefaults::literal() packages/sql-semantics-sqlite/src/Rules/Definition/Expression/LiteralDefaults.php:79
- instanceof SqlSemantics\Platform\Sqlite\Statement\Schema\Column\ColumnDefinition::deriveColumn() packages/sql-semantics-sqlite/src/Statement/Schema/Column/ColumnDefinition.php:116
Type declarations 2
- type SqlSemantics\Platform\Sqlite\Rules\Definition\Expression\LiteralDefaults packages/sql-semantics-sqlite/src/Rules/Definition/Expression/LiteralDefaults.php:61
- type SqlSemantics\Platform\Sqlite\Rules\Definition\Expression\LiteralDefaults packages/sql-semantics-sqlite/src/Rules/Definition/Expression/LiteralDefaults.php:73