final class GeneratedWrites
Restricted visibility: declared "@visibility SqlSemantics\Platform\MySql". Code outside that scope must not name this declaration.

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,
): void
public function assignments(
    list<Assignment> $assignments,
    list<Field> $fields,
    Derivation $derivation,
): void
public function query(
    list<Field> $written,
    Query $source,
    QueryFact $rows,
    Name|null $table,
    Derivation $derivation,
): void

Reports each generated written column that the rows of a query source fill with something else than a default value item.

Parameters

$writtenlist<Field>The written columns
$sourceQuery
$rowsQueryFact
$tableName|nullThe declared name of the written table, or null when the table is not a declared table
$derivationDerivation
Called from 1
Calls 4
public function valueRows(Query $source): ?ValuesQuery

Answers 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

$sourceQuery

Returns

Test cases 1
Called from 1
public function default(?Scalar $value): bool

Tells whether a value is a default value item: DEFAULT or DEFAULT(col), inside any parentheses; no value is none.

Parameters

$value?Scalar

Returns

bool
Test cases 1
Called from 1

Test cases 2§

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

Dedicated tests 2

Relations§

Instantiated in 5
Method calls 7