classTableDeclaration
final class TableDeclaration
Derives the declaration a table or view definition provides.
Rule: MYSQL-TABLE-DECLARATION-001. A CREATE TABLE declares one column per column definition, in order, with the type as written and the NULL fact of MYSQL-COLUMN-FLAGS-001; a column a table-level PRIMARY KEY names is NOT NULL. A generated column (VIRTUAL or STORED) is an ordinary column for reading and is declared generated: the server computes its value and accepts only DEFAULT for it in a write. An INVISIBLE column is found by name but not by * ("not part of SELECT *"): it is an implicit column of the declaration.
CREATE TABLE ... SELECT: "columns named only in the CREATE TABLE part come
- first. Columns named in both parts or only in the SELECT part come after
- that. The data type of SELECT columns can be overridden by also specifying
- the column in the CREATE TABLE part." A column named in both parts takes
its name from the SELECT part and the rest from the CREATE TABLE part. A column of the SELECT part takes the name, the type and the NULL fact of its output field and is not generated, also when the field reads a generated column; the column list stops, and the declaration is incomplete, at the first field that has no determined name or type or that an unexpanded star leaves open.
CREATE VIEW: a view (RelationKind::View) with one column per output field, named by the column list when one is written, with the type and NULL fact of the field, never generated; incomplete under the same conditions and when the column list has another length. Every other declaration is a base table.
CREATE TABLE ... LIKE: the columns of the source table, as new declarations with the same names, types, NULL facts and generation (the copy keeps the generation expressions); an undeclared source leaves the declaration empty and incomplete. Terminates: one pass over the elements and the fields. Source: https://dev.mysql.com/doc/refman/8.4/en/create-table.html, https://dev.mysql.com/doc/refman/8.4/en/create-table-select.html, https://dev.mysql.com/doc/refman/8.4/en/create-table-like.html, https://dev.mysql.com/doc/refman/8.4/en/create-view.html, https://dev.mysql.com/doc/refman/8.4/en/invisible-columns.html. Status: Implemented.
Methods§
public function column(ColumnDefinition $definition, bool $keyed = false): ColumnAnswers the declaration of one column definition; $keyed tells whether a table-level primary key includes it.
Parameters
$definition | ColumnDefinition | |
$keyed | bool |
Returns
Test cases 1
Called from 2
- method-call SqlSemantics\Platform\MySql\Rules\TableDefinition\ElementFacts::declaration() packages/sql-semantics-mysql/src/Rules/TableDefinition/ElementFacts.php:76
- method-call SqlSemantics\Platform\MySql\Rules\TableDefinition\TableDeclaration::table() packages/sql-semantics-mysql/src/Rules/TableDefinition/TableDeclaration.php:110
Calls 3
- new Column line 76
- method-call ColumnFlags::nullability() line 76
- new ColumnFlags line 76
public function primaryColumns(CreateTable $definition): list<Name>Answers the column names the table-level primary keys of a definition name.
Parameters
$definition | CreateTable |
Returns
list<Name>Test cases 1
Called from 2
- method-call SqlSemantics\Platform\MySql\Rules\TableDefinition\TableDeclaration::table() packages/sql-semantics-mysql/src/Rules/TableDefinition/TableDeclaration.php:106
- method-call SqlSemantics\Platform\MySql\Rules\TableDefinition\TableProblems::report() packages/sql-semantics-mysql/src/Rules/TableDefinition/TableProblems.php:59
Calls 1
- class-const IndexKind::Primary() line 88
public function table(
CreateTable $definition,
?QueryFact $output,
Derivation $derivation,
): TableBuilds the declaration of a CREATE TABLE; $output is the output of its query, when it has one.
Parameters
$definition | CreateTable | |
$output | ?QueryFact | |
$derivation | Derivation |
Returns
Called from 1
Calls 8
- method-call TableDeclaration::primaryColumns() line 106
- method-call TableDeclaration::column() line 110
- method-call TableDeclaration::named() line 110
- method-call TableDeclaration::settled() line 116
- method-call TableDeclaration::find() line 117
- method-call TableDeclaration::fieldColumn() line 118
- method-call TableDeclaration::renamed() line 118
- method-call TableDeclaration::split() line 136
public function split(
QualifiedName $name,
list<array{ColumnDefinition|null, Column}> $columns,
LanguageProfile $profile,
bool $complete,
): TableBuilds a declaration from columns, keeping INVISIBLE columns as implicit columns.
Parameters
$name | QualifiedName | |
$columns | list<array{ColumnDefinition|null, Column}> | Each column with the definition it comes from, if any |
$profile | LanguageProfile | |
$complete | bool |
Returns
Test cases 1
Called from 1
Calls 4
- new ColumnFlags line 148
- method-call ColumnFlags::invisible() line 150
- new ImplicitColumn line 151
- new Table line 157
public function view(
QualifiedName $name,
QueryFact $output,
list<Name|null> $names,
bool $listed,
LanguageProfile $profile,
): TableBuilds the declaration of a view from the output of its query and the names of its columns.
Parameters
$name | QualifiedName | |
$output | QueryFact | |
$names | list<Name|null> | The name of each column: the column list when one is written, else the names the query gives |
$listed | bool | Whether the names are a written column list, whose length must match the query |
$profile | LanguageProfile |
Returns
Called from 1
Calls 5
- method-call TableDeclaration::settled() line 168
- function-call
countline 169 - method-call TableDeclaration::fieldColumn() line 172
- new Table line 180
- class-const RelationKind::View() line 180
public function like(QualifiedName $name, ?Table $source, LanguageProfile $profile): TableBuilds the declaration of CREATE TABLE ... LIKE from the declaration of the source table, when it is declared.
Parameters
$name | QualifiedName | |
$source | ?Table | |
$profile | LanguageProfile |
Returns
Test cases 1
Called from 1
Answers a defined column under the name a field of the SELECT part gives it.
Returns
Called from 1
Answers the leading output fields of a query whose position is determined: those before the first unexpanded star.
Parameters
$output | QueryFact |
Returns
list<Field>Test cases 2
Called from 5
- method-call SqlSemantics\Platform\MySql\Rules\Dml\GeneratedWrites::query() packages/sql-semantics-mysql/src/Rules/Dml/GeneratedWrites.php:110
- method-call SqlSemantics\Platform\MySql\Rules\TableDefinition\TableDeclaration::table() packages/sql-semantics-mysql/src/Rules/TableDefinition/TableDeclaration.php:116
- method-call SqlSemantics\Platform\MySql\Rules\TableDefinition\TableDeclaration::view() packages/sql-semantics-mysql/src/Rules/TableDefinition/TableDeclaration.php:168
- method-call SqlSemantics\Platform\MySql\Rules\TableDefinition\TableProblems::selected() packages/sql-semantics-mysql/src/Rules/TableDefinition/TableProblems.php:120
- method-call SqlSemantics\Platform\MySql\Rules\TableDefinition\ViewFacts::derive() packages/sql-semantics-mysql/src/Rules/TableDefinition/ViewFacts.php:40
Answers the column an output field makes under a name, or null when its name or type is not determined.
Returns
Test cases 1
Called from 2
- method-call SqlSemantics\Platform\MySql\Rules\TableDefinition\TableDeclaration::table() packages/sql-semantics-mysql/src/Rules/TableDefinition/TableDeclaration.php:118
- method-call SqlSemantics\Platform\MySql\Rules\TableDefinition\TableDeclaration::view() packages/sql-semantics-mysql/src/Rules/TableDefinition/TableDeclaration.php:172
public function find(
Name $name,
list<array{ColumnDefinition, Column}> $defined,
Comparison $comparison,
): ?intAnswers the position of the defined column with a name.
Parameters
$name | Name | |
$defined | list<array{ColumnDefinition, Column}> | |
$comparison | Comparison |
Returns
?intTest cases 1
Called from 1
Calls 1
- method-call Comparison::equal() line 245
public function named(Name $name, list<Name> $names, Comparison $comparison): boolTells whether a list of names holds a name.
Parameters
$name | Name | |
$names | list<Name> | |
$comparison | Comparison |
Returns
boolTest cases 1
Called from 3
- method-call SqlSemantics\Platform\MySql\Rules\TableDefinition\TableDeclaration::table() packages/sql-semantics-mysql/src/Rules/TableDefinition/TableDeclaration.php:110
- method-call SqlSemantics\Platform\MySql\Rules\TableDefinition\TableProblems::report() packages/sql-semantics-mysql/src/Rules/TableDefinition/TableProblems.php:67
- method-call SqlSemantics\Platform\MySql\Rules\TableDefinition\TableProblems::duplicates() packages/sql-semantics-mysql/src/Rules/TableDefinition/TableProblems.php:107
Calls 1
- method-call Comparison::equal() line 261
Test cases 8§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 8
TableDeclarationTest::testColumnDeclaresOneColumnDefinitioncallsTableDeclarationTest::testFieldColumnNeedsAKnownTypecallsTableDeclarationTest::testFindAnswersThePositionOfADefinedColumncallsTableDeclarationTest::testLikeLeavesAnUndeclaredSourceIncompletecallsTableDeclarationTest::testNamedComparesNamescallsTableDeclarationTest::testPrimaryColumnsNamesTheTableLevelKeyColumnscallsTableDeclarationTest::testSettledStopsAtAnOpenStarcallsTableDeclarationTest::testSplitKeepsInvisibleColumnsImplicitcalls
Relations§
Instantiated in 8
- new SqlSemantics\Platform\MySql\Rules\Dml\GeneratedWrites::query() packages/sql-semantics-mysql/src/Rules/Dml/GeneratedWrites.php:110
- new SqlSemantics\Platform\MySql\Rules\TableDefinition\ElementFacts::declaration() packages/sql-semantics-mysql/src/Rules/TableDefinition/ElementFacts.php:76
- new SqlSemantics\Platform\MySql\Rules\TableDefinition\TableProblems::report() packages/sql-semantics-mysql/src/Rules/TableDefinition/TableProblems.php:58
- new SqlSemantics\Platform\MySql\Rules\TableDefinition\TableProblems::duplicates() packages/sql-semantics-mysql/src/Rules/TableDefinition/TableProblems.php:107
- new SqlSemantics\Platform\MySql\Rules\TableDefinition\TableProblems::selected() packages/sql-semantics-mysql/src/Rules/TableDefinition/TableProblems.php:120
- new SqlSemantics\Platform\MySql\Rules\TableDefinition\ViewFacts::derive() packages/sql-semantics-mysql/src/Rules/TableDefinition/ViewFacts.php:39
- new SqlSemantics\Platform\MySql\Statement\Table\CreateTable::deriveRelation() packages/sql-semantics-mysql/src/Statement/Table/CreateTable.php:131
- new SqlSemantics\Platform\MySql\Statement\Table\CreateTableLike::deriveStatement() packages/sql-semantics-mysql/src/Statement/Table/CreateTableLike.php:66
Method calls 10
- method-call SqlSemantics\Platform\MySql\Rules\Dml\GeneratedWrites::query() packages/sql-semantics-mysql/src/Rules/Dml/GeneratedWrites.php:110
- method-call SqlSemantics\Platform\MySql\Rules\TableDefinition\ElementFacts::declaration() packages/sql-semantics-mysql/src/Rules/TableDefinition/ElementFacts.php:76
- method-call SqlSemantics\Platform\MySql\Rules\TableDefinition\TableProblems::report() packages/sql-semantics-mysql/src/Rules/TableDefinition/TableProblems.php:59
- method-call SqlSemantics\Platform\MySql\Rules\TableDefinition\TableProblems::report() packages/sql-semantics-mysql/src/Rules/TableDefinition/TableProblems.php:67
- method-call SqlSemantics\Platform\MySql\Rules\TableDefinition\TableProblems::duplicates() packages/sql-semantics-mysql/src/Rules/TableDefinition/TableProblems.php:107
- method-call SqlSemantics\Platform\MySql\Rules\TableDefinition\TableProblems::selected() packages/sql-semantics-mysql/src/Rules/TableDefinition/TableProblems.php:120
- method-call SqlSemantics\Platform\MySql\Rules\TableDefinition\ViewFacts::derive() packages/sql-semantics-mysql/src/Rules/TableDefinition/ViewFacts.php:40
- method-call SqlSemantics\Platform\MySql\Rules\TableDefinition\ViewFacts::derive() packages/sql-semantics-mysql/src/Rules/TableDefinition/ViewFacts.php:41
- method-call SqlSemantics\Platform\MySql\Statement\Table\CreateTable::deriveRelation() packages/sql-semantics-mysql/src/Statement/Table/CreateTable.php:131
- method-call SqlSemantics\Platform\MySql\Statement\Table\CreateTableLike::deriveStatement() packages/sql-semantics-mysql/src/Statement/Table/CreateTableLike.php:66