classAlterAddColumn
final class AlterAddColumn
implements Statement, Relation
uses Snapshot
@visibility public.A request to add a column at the end of a table.
Rule: SQLITE-ALTER-ADD-COLUMN-001. The resolution of the table is the relation fact of the statement node. The node is the relation occurrence the expressions of the new column definition are derived against: its row shape is the columns of the existing table followed by the new column, which has the declared type SQLite records and is never NULL only when it is declared NOT NULL. Diagnostics, besides those of the table resolution and of the expressions: a view (SQLITE-RELATION-KIND-001), which SQLite refuses before it reads the new column; otherwise a column name the completely known table already has; a PRIMARY KEY or UNIQUE column; a STORED generated column; a NOT NULL column without a default value other than NULL; in a STRICT table a type that is not one of the six standard names. The optional COLUMN keyword is not written. The statement changes no declaration and provides none. Source: https://sqlite.org/lang_altertable.html#alter_table_add_column. Status: Implemented.
$semantics = new \SqlSemantics\Platform\Sqlite\Semantics();
$table = $semantics->analyze('CREATE TABLE t (a INTEGER)');
$alter = $semantics->analyze('ALTER TABLE t ADD COLUMN b TEXT CHECK (b <> a)', [$table]);
[count($alter->facts->relation($alter->statement)->shape->slots), $alter->toString()] // => [2, 'ALTER TABLE t ADD b TEXT CHECK (b <> a)']Properties§
public QualifiedName $tablepublic ColumnDefinition $columnMethods§
public function __construct(public QualifiedName $table, public ColumnDefinition $column)Parameters
$table | QualifiedName | The table to change |
$column | ColumnDefinition | The definition of the new column |
Calls 1
- static-call Check::input() line 59
public function deriveStatement(Derivation $derivation): voidResolves the table, reports what rules the addition out and derives the expressions of the new column.
Parameters
$derivation | Derivation |
Calls 12
- new TableShapes line 67
- method-call TableShapes::target() line 68
- method-call RelationKinds::refuse() line 69
- new RelationKinds line 69
- class-const KindRefusal::AddColumn() line 69
- method-call AlterationProblems::added() line 70
- new AlterationProblems line 70
- method-call Derivation::relation() line 72
- method-call Derivation::environment() line 72
- method-call ColumnDefinition::deriveColumn() line 73
- method-call TableShapes::scope() line 73
- method-call TableShapes::implicitOf() line 73
public function deriveRelation(Derivation $derivation, Environment $environment): RelationFactDerives the row shape of the table with the new column.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 6
- method-call TableShapes::target() line 81
- new TableShapes line 81
- new RelationFact line 83
- new RowShape line 83
- method-call AlterationProblems::slot() line 83
- new AlterationProblems line 83
public function render(Output $out): voidWrites the request.
Parameters
$out | Output |
Calls 3
- method-call Output::keyword() line 91
- method-call ObjectNames::write() line 92
- new ObjectNames line 92
Test cases 5§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.