final class CreateTable
    implements Statement, Relation
    uses Snapshot
Public API: explicitly declared with @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.

Providing a declaration to a contextdoctest
$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]
The relation fact of the statement resolves to the declaration it providesdoctest
$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> $columns
public list<ConstraintRun> $constraints
public list<TableOption> $options
public bool $temporary = false
public bool $ifNotExists = false
public bool $optionsComma = false

Methods§

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

$nameQualifiedNameThe table name
$columnslist<ColumnDefinition>The column definitions in order; at least one
$constraintslist<ConstraintRun>The table constraints as comma-separated runs, in order
$optionslist<TableOption>The table options in order
$temporaryboolWhether TEMP or TEMPORARY is written
$ifNotExistsboolWhether IF NOT EXISTS is written
$optionsCommaboolWhether a comma is written between the closing parenthesis and the first table option; the grammar admits one and SQLite ignores it
Calls 5
public function deriveStatement(Derivation $derivation): void

Derives the definition: its declaration, its problems and the expressions inside it.

Parameters

$derivationDerivation
Calls 5
public function deriveRelation(Derivation $derivation, Environment $environment): RelationFact

Provides the declaration and reports the problems of the definition; the fact resolves to that declaration and holds its row shape.

Parameters

$derivationDerivation
$environmentEnvironment
Calls 12
public function render(Output $out): void

Writes the definition.

Parameters

$outOutput
Calls 5

Test cases 83§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 6
Other tests reaching this symbol 77

Relations§

Instantiated in 1
Method calls 8
Type declarations 6