classGeneratedWrites
final class GeneratedWrites
Reports the values a write gives to generated columns.
Rule: MYSQL-GENERATED-WRITE-001. "The only value permitted for a
- generated column in an INSERT, REPLACE or UPDATE statement is DEFAULT":
a written column whose declaration is generated (VIRTUAL or STORED) takes only a default value item, the keyword DEFAULT or the function DEFAULT(col) (parentheses do not make an item), else the statement is rejected with ER_NON_DEFAULT_VALUE_FOR_GENERATED_COLUMN, naming the declared column and table. This holds for each row of VALUES (with or without a column list), INSERT ... SET, the assignments of ON DUPLICATE KEY UPDATE and of a single- or multiple-table UPDATE; IGNORE and sql_mode do not change it. A query source that is a VALUES statement (inside parentheses, WITH, ORDER BY or LIMIT) is turned into the rows of INSERT ... VALUES (sql/parse_tree_nodes.cc PT_insert::make_cmd), so each of its values is checked as a value of a row. Another query source gives a default value item only when it is one query block whose select item at that position is DEFAULT(col); the field of a set operation, of TABLE or of an expanded star is not one. A column of a view, a derived table or a common table is not a declared generated column here. LOAD DATA computes generated columns and ignores the values it reads or assigns for them (fill_record skips them), so it is not checked. Terminates: one pass over the finite lists. Source: sql/sql_resolver.cc validate_gc_assignment (5.7.44, 8.0.44, 8.4.7, 9.1.0), called from sql/sql_insert.cc Sql_cmd_insert_base::prepare_inner and sql/sql_update.cc Sql_cmd_update::prepare_inner; https://dev.mysql.com/doc/refman/8.4/en/create-table-generated-columns.html. Status: Implemented.
Methods§
public function value(
Field $column,
Scalar|null $value,
Name|null $table,
Derivation $derivation,
): voidReports a value other than a default value item written into a generated column of a declared table.
Parameters
$column | Field | |
$value | Scalar|null | The value, or null for a field no single expression computes |
$table | Name|null | The declared name of the written table, or null when the table is not a declared table |
$derivation | Derivation |
Called from 4
- method-call SqlSemantics\Platform\MySql\Rules\Dml\GeneratedWrites::assignments() packages/sql-semantics-mysql/src/Rules/Dml/GeneratedWrites.php:85
- method-call SqlSemantics\Platform\MySql\Rules\Dml\GeneratedWrites::query() packages/sql-semantics-mysql/src/Rules/Dml/GeneratedWrites.php:103
- method-call SqlSemantics\Platform\MySql\Rules\Dml\GeneratedWrites::query() packages/sql-semantics-mysql/src/Rules/Dml/GeneratedWrites.php:112
- method-call SqlSemantics\Platform\MySql\Rules\Dml\InsertFacts::rows() packages/sql-semantics-mysql/src/Rules/Dml/InsertFacts.php:85
Calls 4
- method-call Field::column() line 68
- method-call GeneratedWrites::default() line 69
- method-call Derivation::report() line 70
- new GeneratedColumnWrite line 70
public function assignments(
list<Assignment> $assignments,
list<Field> $fields,
Derivation $derivation,
): voidReports the assignments that write a value other than a default value item into a generated column.
Parameters
$assignments | list<Assignment> | |
$fields | list<Field> | The assigned columns, one per assignment in written order |
$derivation | Derivation |
Called from 3
- method-call SqlSemantics\Platform\MySql\Rules\Dml\ChangeFacts::update() packages/sql-semantics-mysql/src/Rules/Dml/ChangeFacts.php:65
- method-call SqlSemantics\Platform\MySql\Rules\Dml\InsertFacts::set() packages/sql-semantics-mysql/src/Rules/Dml/InsertFacts.php:99
- method-call SqlSemantics\Platform\MySql\Rules\Dml\InsertFacts::duplicates() packages/sql-semantics-mysql/src/Rules/Dml/InsertFacts.php:196
Calls 2
- method-call GeneratedWrites::value() line 85
- method-call GeneratedWrites::table() line 85
public function query(
list<Field> $written,
Query $source,
QueryFact $rows,
Name|null $table,
Derivation $derivation,
): voidReports each generated written column that the rows of a query source fill with something else than a default value item.
Parameters
$written | list<Field> | The written columns |
$source | Query | |
$rows | QueryFact | |
$table | Name|null | The declared name of the written table, or null when the table is not a declared table |
$derivation | Derivation |
Called from 1
Calls 4
- method-call GeneratedWrites::valueRows() line 98
- method-call GeneratedWrites::value() line 103
- method-call TableDeclaration::settled() line 110
- new TableDeclaration line 110
public function valueRows(Query $source): ?ValuesQueryAnswers the VALUES statement a query source consists of, inside parentheses, WITH, ORDER BY, LIMIT or locking clauses; the server inserts its rows as the rows of INSERT ... VALUES.
Parameters
$source | Query |
Returns
Test cases 1
public function default(?Scalar $value): boolTells whether a value is a default value item: DEFAULT or DEFAULT(col), inside any parentheses; no value is none.
Parameters
$value | ?Scalar |
Returns
boolTest cases 1
public function table(Relation $relation, Derivation $derivation): ?NameAnswers the declared name of the table or view a relation occurrence reads, or null when it reads no declared table.
Parameters
$relation | Relation | |
$derivation | Derivation |
Returns
?NameCalled from 3
- method-call SqlSemantics\Platform\MySql\Rules\Dml\GeneratedWrites::assignments() packages/sql-semantics-mysql/src/Rules/Dml/GeneratedWrites.php:85
- method-call SqlSemantics\Platform\MySql\Rules\Dml\InsertFacts::rows() packages/sql-semantics-mysql/src/Rules/Dml/InsertFacts.php:69
- method-call SqlSemantics\Platform\MySql\Rules\Dml\InsertFacts::query() packages/sql-semantics-mysql/src/Rules/Dml/InsertFacts.php:114
Calls 1
- method-call Derivation::facts() line 146
Test cases 2§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Relations§
Instantiated in 5
- new SqlSemantics\Platform\MySql\Rules\Dml\ChangeFacts::update() packages/sql-semantics-mysql/src/Rules/Dml/ChangeFacts.php:65
- new SqlSemantics\Platform\MySql\Rules\Dml\InsertFacts::rows() packages/sql-semantics-mysql/src/Rules/Dml/InsertFacts.php:68
- new SqlSemantics\Platform\MySql\Rules\Dml\InsertFacts::set() packages/sql-semantics-mysql/src/Rules/Dml/InsertFacts.php:99
- new SqlSemantics\Platform\MySql\Rules\Dml\InsertFacts::query() packages/sql-semantics-mysql/src/Rules/Dml/InsertFacts.php:113
- new SqlSemantics\Platform\MySql\Rules\Dml\InsertFacts::duplicates() packages/sql-semantics-mysql/src/Rules/Dml/InsertFacts.php:196
Method calls 7
- method-call SqlSemantics\Platform\MySql\Rules\Dml\ChangeFacts::update() packages/sql-semantics-mysql/src/Rules/Dml/ChangeFacts.php:65
- method-call SqlSemantics\Platform\MySql\Rules\Dml\InsertFacts::rows() packages/sql-semantics-mysql/src/Rules/Dml/InsertFacts.php:69
- method-call SqlSemantics\Platform\MySql\Rules\Dml\InsertFacts::rows() packages/sql-semantics-mysql/src/Rules/Dml/InsertFacts.php:85
- method-call SqlSemantics\Platform\MySql\Rules\Dml\InsertFacts::set() packages/sql-semantics-mysql/src/Rules/Dml/InsertFacts.php:99
- method-call SqlSemantics\Platform\MySql\Rules\Dml\InsertFacts::query() packages/sql-semantics-mysql/src/Rules/Dml/InsertFacts.php:114
- method-call SqlSemantics\Platform\MySql\Rules\Dml\InsertFacts::query() packages/sql-semantics-mysql/src/Rules/Dml/InsertFacts.php:114
- method-call SqlSemantics\Platform\MySql\Rules\Dml\InsertFacts::duplicates() packages/sql-semantics-mysql/src/Rules/Dml/InsertFacts.php:196