classCreateTable
final class CreateTable
implements Statement, Relation
uses Snapshot
@visibility public.A request to create a table from column definitions.
Rule: SQLITE-CREATE-TABLE-001. The statement provides one table declaration (SQLITE-TABLE-DECLARATION-001); it executes nothing and changes no context, and IF NOT EXISTS does not change what it declares. The statement node is the one relation occurrence of the new table: its relation fact resolves to the declaration the statement provides, the same object, and holds the row shape of the new table, whose slots are the declared columns. A comma the grammar admits before the first table option is kept as written. The expressions inside the definition are derived in the scope of SQLITE-DEFINITION-SCOPE-001, whose only visible relation is that occurrence, so a column resolved inside the definition reaches the declared column. Diagnostics: SQLITE-TABLE-PROBLEMS-001 and those of the columns and constraints. Source: https://sqlite.org/lang_createtable.html. Status: Implemented.
$create = (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze('CREATE TABLE t (id INTEGER PRIMARY KEY, name TEXT NOT NULL)');
$table = $create->declarations()[0];
[count($table->columns), $table->columns[1]->nullability, $table->implicit[0]->column === $table->columns[0]] // => [2, \SqlSemantics\Platform\Sqlite\Model\Statement\Type\Nullability::NotNull, true]$create = (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze('CREATE TABLE t (a, b CHECK (a > 0))');
$check = $create->statement->columns[1]->constraints[0];
[$create->facts->relation($create->statement)->table->table === $create->declarations()[0], $create->facts->scalar($check->expression->left)->resolution->slot->column === $create->declarations()[0]->columns[0]] // => [true, true]Properties§
public non-empty-list<ColumnDefinition> $columnspublic list<ConstraintRun> $constraintspublic list<TableOption> $optionspublic QualifiedName $namepublic bool $temporary = falsepublic bool $ifNotExists = falsepublic bool $optionsComma = falseMethods§
public function __construct(
public QualifiedName $name,
list<ColumnDefinition> $columns,
list<ConstraintRun> $constraints = [],
list<TableOption> $options = [],
public bool $temporary = false,
public bool $ifNotExists = false,
public bool $optionsComma = false,
)Parameters
$name | QualifiedName | The table name |
$columns | list<ColumnDefinition> | The column definitions in order; at least one |
$constraints | list<ConstraintRun> | The table constraints as comma-separated runs, in order |
$options | list<TableOption> | The table options in order |
$temporary | bool | Whether TEMP or TEMPORARY is written |
$ifNotExists | bool | Whether IF NOT EXISTS is written |
$optionsComma | bool | Whether a comma is written between the closing parenthesis and the first table option; the grammar admits one and SQLite ignores it |
Calls 5
- static-call Check::input() line 91
- static-call Check::listOf() line 92
- class-const ColumnDefinition::class() line 92
- class-const ConstraintRun::class() line 93
- class-const TableOption::class() line 94
public function withoutRowid(): boolTells whether the table is defined WITHOUT ROWID.
Returns
boolTest cases 1
Called from 5
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\TableDeclaration::table() packages/sql-semantics-sqlite/src/Rules/Definition/TableDeclaration.php:82
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\TableDeclaration::table() packages/sql-semantics-sqlite/src/Rules/Definition/TableDeclaration.php:83
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\TableDeclaration::table() packages/sql-semantics-sqlite/src/Rules/Definition/TableDeclaration.php:90
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\TableProblems::report() packages/sql-semantics-sqlite/src/Rules/Definition/TableProblems.php:62
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\TableProblems::report() packages/sql-semantics-sqlite/src/Rules/Definition/TableProblems.php:64
Calls 1
- class-const TableOptionKind::WithoutRowid() line 104
public function strict(): boolTells whether the table is defined STRICT.
Returns
boolTest cases 1
Called from 3
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\TableDeclaration::domains() packages/sql-semantics-sqlite/src/Rules/Definition/TableDeclaration.php:61
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\TableDeclaration::table() packages/sql-semantics-sqlite/src/Rules/Definition/TableDeclaration.php:83
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\TableProblems::report() packages/sql-semantics-sqlite/src/Rules/Definition/TableProblems.php:55
Calls 1
- class-const TableOptionKind::Strict() line 118
public function deriveStatement(Derivation $derivation): voidDerives the definition: its declaration, its problems and the expressions inside it.
Parameters
$derivation | Derivation |
Calls 5
- method-call Derivation::relation() line 131
- method-call Derivation::environment() line 131
- new TableShapes line 132
- method-call TableShapes::scope() line 133
- method-call TableShapes::implicitOf() line 133
public function deriveRelation(Derivation $derivation, Environment $environment): RelationFactProvides the declaration and reports the problems of the definition; the fact resolves to that declaration and holds its row shape.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 12
- new TableDeclaration line 149
- method-call TableDeclaration::domains() line 150
- method-call PrimaryKeyRule::key() line 151
- new PrimaryKeyRule line 151
- method-call TableDeclaration::table() line 152
- method-call Derivation::declare() line 153
- method-call TableProblems::report() line 154
- new TableProblems line 154
- new RelationFact line 156
- method-call TableShapes::shape() line 156
- new TableShapes line 156
- new DeclaredTable line 156
public function render(Output $out): voidWrites the definition.
Parameters
$out | Output |
Calls 5
- method-call Output::keyword() line 164
- method-call ObjectNames::write() line 172
- new ObjectNames line 172
- method-call Output::symbol() line 173
- method-call Output::list() line 177
Test cases 83§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 6
CreateTableTest::testDeriveRelationDeclaresTheTableAndAnswersItsShapecallsCreateTableTest::testRefusesACommaWithoutAnOptionAfterItcallsCreateTableTest::testRenderKeepsACommaWrittenBeforeTheFirstOptioncallsCreateTableTest::testRenderWritesANewlyBuiltDefinitioncallsCreateTableTest::testStrictIgnoresAnOptionSqliteRejectscallsCreateTableTest::testWithoutRowidAndStrictReadTheKnownOptionscalls
Other tests reaching this symbol 77
ColumnRuleTest::testAutoincrementLowersTheOptionalKeywordcallsColumnRuleTest::testColumnLowersTheNameTheTypeAndTheConstraintscallsColumnRuleTest::testConstraintLowersEveryKindOfConstraintcallsColumnRuleTest::testConstraintsKeepTheirWrittenOrdercallsColumnRuleTest::testDefaultLowersEveryFormOfDefaultcallsColumnRuleTest::testGeneratedLowersTheExpressionAndTheOptionalWordcallsCreateTableRuleTest::testColumnsKeepTheirWrittenOrdercallsCreateTableRuleTest::testCommandKeepsTheHeaderFlagsAndTheNamecallsCreateTableRuleTest::testCommandLowersBothFormsOfATableDefinitioncallsDefinitionCommandsTest::testCommandLowersACommandOfEveryFamilycallsForeignKeyRuleTest::testArgumentLowersEveryEventAndReactioncallsForeignKeyRuleTest::testArgumentsKeepTheirWrittenOrdercallsForeignKeyRuleTest::testClauseLowersTheParentAndItsOptionalColumnscallsForeignKeyRuleTest::testDeferrabilityLowersBothFormscallsForeignKeyRuleTest::testInitiallyLowersTheOptionalModecallsForeignKeyRuleTest::testOptionalDeferrabilityIsNullWhenNoClauseIsWrittencallsKeyTermRuleTest::testKeyTermsWrapAStringUnderAnyParenthesesAndCollationscallsTableConstraintRuleTest::testConstraintLowersEveryKindOfTableConstraintcallsTableConstraintRuleTest::testLeadingCommaTellsACommaWrittenBeforeTheFirstOptioncallsTableConstraintRuleTest::testOptionsKeepTheirWrittenOrdercallsTableConstraintRuleTest::testOptionTellsTheWithoutFormFromTheBareFormcallsTableConstraintRuleTest::testRunsAreEmptyWithoutTableConstraintscallsTableConstraintRuleTest::testRunsSplitTheConstraintsAtTheWrittenCommascallsWordRuleTest::testNameReadsAnIdentifierOrAStringTokencallsWordRuleTest::testWordDecodesTheNamecallsWordRuleTest::testWordKeepsTheQuotingOfTheTokencallsConflictRuleTest::testOnConflictLowersTheAlgorithmOfAConstraintAndNullWithoutTheClausecallsNameRuleTest::testNameAcceptsAStringAtANamePositioncallsTypeNameRuleTest::testNamedIsNullWhenNoTypeIsWrittencallsTypeNameRuleTest::testNamedKeepsTheWordsOfATypeNameInWrittenOrdercallsLoweringTest::testCommandLowersAQueryCommandAndADefinitionCommandcallsLiteralDefaultsTest::testDefaultsAnswersTheDefaultClausesInWrittenOrdercallsLiteralDefaultsTest::testLiteralTellsTheDefaultsSqliteComputesWhenAColumnIsAddedcallsLiteralDefaultsTest::testNullIsTheLiteralNullWithOrWithoutParenthesescallsPrimaryKeyRuleTest::testKeyCountsEveryPrimaryKeyConstraintAndUsesTheFirstcallsPrimaryKeyRuleTest::testKeyDoesNotMakeADescendingColumnConstraintTheRowidcallsPrimaryKeyRuleTest::testKeyDoesNotMakeAnotherTypeTheRowidcallsPrimaryKeyRuleTest::testKeyIsEmptyWithoutAPrimaryKeycallsPrimaryKeyRuleTest::testKeyMakesAnIntegerPrimaryKeyColumnTheRowidcallsPrimaryKeyRuleTest::testTableKeyListsTheColumnsOfACompositeKeyInKeyOrdercallsPrimaryKeyRuleTest::testTableKeyMakesASingleIntegerColumnTheRowidWhateverItsSortOrdercallsTableDeclarationTest::testDomainsRecordTheDeclaredTypeOfEachColumncallsTableDeclarationTest::testTableBuildsTheDeclarationFromAnEstablishedKeycallsTypeRecordingTest::testWrittenIsTheTextTheRenderedSqlSpellscallsCollationTest::testRenderKeepsTheCollationNamecallsColumnCheckTest::testDeriveConstraintResolvesColumnsOfTheTableBeingDefinedcallsColumnCheckTest::testDeriveConstraintSeesTheRowIdentifiercallsColumnConstraintTest::testDeriveConstraintDerivesEachKindOfOperandInItsOwnScopecallsColumnDefinitionTest::testDeriveColumnDerivesTheTypeArgumentsAndTheConstraintscallsColumnPrimaryKeyTest::testRenderKeepsTheSortOrderTheConflictResolutionAndAutoincrementcallsColumnPrimaryKeyTest::testRenderWritesABareKeycallsColumnUniqueTest::testRenderKeepsTheConflictResolutioncallsConstraintNameTest::testRenderKeepsTheNameAtItsPlaceAmongTableConstraintscallsConstraintNameTest::testRenderKeepsTheNameAtItsPlaceInAColumncallsDefaultExpressionTest::testDeriveConstraintAcceptsAConstantExpressioncallsDefaultLiteralTest::testDeriveConstraintDerivesTheLiteralcallsDefaultLiteralTest::testRenderKeepsTheWrittenSigncallsDefaultLiteralTest::testRenderWritesEveryKindOfLiteralcallsDefaultWordTest::testRenderKeepsTheQuotingThatDecidesTheMeaningcallsGeneratedTest::testDeriveConstraintResolvesColumnsOfTheTableBeingDefinedcallsNotNullTest::testRenderKeepsTheConflictResolutioncallsNullAllowedTest::testRenderKeepsTheConflictResolutioncallsLiteralColumnTest::testDeriveScalarResolvesTheColumnOfTheTableBeingDefinedcallsDeferrabilityTest::testRenderKeepsTheClauseAsAColumnConstraintOfItsOwncallsForeignKeyClauseTest::testRenderKeepsAnAbsentColumnListAbsentcallsForeignKeyClauseTest::testRenderWritesTheParentTheColumnsAndTheClausescallsReferenceArgumentTest::testRenderWritesEveryKindOfClauseInWrittenOrdercallsConstraintRunTest::testRenderKeepsACommaThatCutsAConstraintNameOffcallsConstraintRunTest::testRenderWritesTheConstraintsOfARunWithoutCommascallsForeignKeyTest::testRenderWritesTheColumnsTheParentAndTheDeferrabilitycallsTableCheckTest::testDeriveConstraintResolvesColumnsAndTheRowIdentifiercallsTableCheckTest::testRenderKeepsTheIgnoredConflictResolutioncallsTableConstraintTest::testDeriveConstraintDerivesTheOperandsOfEachConstraintcallsTablePrimaryKeyTest::testDeriveConstraintResolvesTheKeyColumnscallsTablePrimaryKeyTest::testRenderWritesAutoincrementInsideTheParenthesescallsTableUniqueTest::testDeriveConstraintResolvesTheKeyColumnscallsTableUniqueTest::testRenderKeepsTheTermsAndTheConflictResolutioncalls
Relations§
Instantiated in 1
Method calls 8
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\TableDeclaration::domains() packages/sql-semantics-sqlite/src/Rules/Definition/TableDeclaration.php:61
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\TableDeclaration::table() packages/sql-semantics-sqlite/src/Rules/Definition/TableDeclaration.php:82
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\TableDeclaration::table() packages/sql-semantics-sqlite/src/Rules/Definition/TableDeclaration.php:83
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\TableDeclaration::table() packages/sql-semantics-sqlite/src/Rules/Definition/TableDeclaration.php:83
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\TableDeclaration::table() packages/sql-semantics-sqlite/src/Rules/Definition/TableDeclaration.php:90
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\TableProblems::report() packages/sql-semantics-sqlite/src/Rules/Definition/TableProblems.php:55
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\TableProblems::report() packages/sql-semantics-sqlite/src/Rules/Definition/TableProblems.php:62
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\TableProblems::report() packages/sql-semantics-sqlite/src/Rules/Definition/TableProblems.php:64
Type declarations 6
- type SqlSemantics\Platform\Sqlite\Rules\Definition\PrimaryKeyRule packages/sql-semantics-sqlite/src/Rules/Definition/PrimaryKeyRule.php:38
- type SqlSemantics\Platform\Sqlite\Rules\Definition\PrimaryKeyRule packages/sql-semantics-sqlite/src/Rules/Definition/PrimaryKeyRule.php:67
- type SqlSemantics\Platform\Sqlite\Rules\Definition\TableDeclaration packages/sql-semantics-sqlite/src/Rules/Definition/TableDeclaration.php:57
- type SqlSemantics\Platform\Sqlite\Rules\Definition\TableDeclaration packages/sql-semantics-sqlite/src/Rules/Definition/TableDeclaration.php:80
- type SqlSemantics\Platform\Sqlite\Rules\Definition\TableProblems packages/sql-semantics-sqlite/src/Rules/Definition/TableProblems.php:46
- type SqlSemantics\Platform\Sqlite\Rules\Definition\TableProblems packages/sql-semantics-sqlite/src/Rules/Definition/TableProblems.php:77