classInsertFacts
final class InsertFacts
Derives the facts of INSERT and REPLACE.
Rule: MYSQL-INSERT-001. The written table is the one visible relation of the columns, the rows and the assignments; a value may refer to a column of the table (insert.html: a value may refer to a column set earlier in the row). The written columns are the column list, or every column of the table; they must be distinct. Each row of VALUES has one value per written column, except an empty row without a column list, which writes the defaults; rows also agree with each other, an empty row included. A query source is derived where the table is not visible and must return one column per written column. ON DUPLICATE KEY UPDATE assigns columns of the written table; its values see the written table, the row alias (MYSQL-DML-ROW-ALIAS-001), whose name may not be the table name, and, for a query source that is one query block without GROUP BY, the relations of its FROM clause. Generated columns take only DEFAULT (MYSQL-GENERATED-WRITE-001); a row or a query whose count does not match is reported for the count only, as the server stops there. A qualified star in a 5.x column list is reported as the server's unknown column '*'. Statements return no rows. Terminates: one pass over finite lists; the source query is derived once. Source: https://dev.mysql.com/doc/refman/8.4/en/insert.html, https://dev.mysql.com/doc/refman/8.4/en/insert-select.html, https://dev.mysql.com/doc/refman/8.4/en/insert-on-duplicate.html, https://dev.mysql.com/doc/refman/8.4/en/replace.html. Status: Implemented.
Methods§
public function rows(InsertRows $insert, Derivation $derivation, Environment $outer): voidDerives INSERT ... VALUES.
Parameters
$insert | InsertRows | |
$derivation | Derivation | |
$outer | Environment |
Called from 1
Calls 12
- method-call InsertFacts::open() line 65
- new Environment line 66
- new WriteScope line 67
- new GeneratedWrites line 68
- method-call GeneratedWrites::table() line 69
- function-call
countline 72 - new ValueCountMismatch line 78
- method-call Derivation::report() line 79
- method-call InsertFacts::column() line 83
- method-call WriteScope::value() line 84
- method-call GeneratedWrites::value() line 85
- method-call InsertFacts::duplicates() line 88
public function set(InsertSet $insert, Derivation $derivation, Environment $outer): voidDerives INSERT ... SET.
Parameters
$insert | InsertSet | |
$derivation | Derivation | |
$outer | Environment |
Called from 1
Calls 7
- method-call InsertFacts::open() line 96
- new Environment line 97
- method-call WriteScope::assign() line 98
- new WriteScope line 98
- method-call GeneratedWrites::assignments() line 99
- new GeneratedWrites line 99
- method-call InsertFacts::duplicates() line 100
public function query(InsertQuery $insert, Derivation $derivation, Environment $outer): voidDerives INSERT ... SELECT, TABLE or VALUES.
Parameters
$insert | InsertQuery | |
$derivation | Derivation | |
$outer | Environment |
Called from 1
Calls 11
- method-call InsertFacts::open() line 108
- method-call Derivation::query() line 109
- function-call
countline 110 - method-call Derivation::report() line 111
- new ValueCountMismatch line 111
- new GeneratedWrites line 113
- method-call GeneratedWrites::query() line 114
- method-call GeneratedWrites::table() line 114
- method-call SourceRelations::visible() line 116
- new SourceRelations line 116
- method-call InsertFacts::duplicates() line 117
public function open(
InsertInto $into,
Derivation $derivation,
Environment $outer,
): array{VisibleRelation, list<Field>|null}Derives the written table and the written columns.
Parameters
$into | InsertInto | |
$derivation | Derivation | |
$outer | Environment |
Returns
array{VisibleRelation, list<Field>|null} The table as a visible relation, and the written columns, or null when the table is not declared completely and no column list is writtenCalled from 3
- method-call SqlSemantics\Platform\MySql\Rules\Dml\InsertFacts::rows() packages/sql-semantics-mysql/src/Rules/Dml/InsertFacts.php:65
- method-call SqlSemantics\Platform\MySql\Rules\Dml\InsertFacts::set() packages/sql-semantics-mysql/src/Rules/Dml/InsertFacts.php:96
- method-call SqlSemantics\Platform\MySql\Rules\Dml\InsertFacts::query() packages/sql-semantics-mysql/src/Rules/Dml/InsertFacts.php:108
Calls 14
- method-call Derivation::relation() line 127
- new VisibleRelation line 128
- new Field line 135
- new OutputSlot line 135
- new Environment line 140
- new WriteScope line 141
- method-call WriteScope::field() line 145
- method-call Derivation::scalar() line 145
- new WriteMisuse line 148
- class-const WriteRule::WildcardColumn() line 148
- method-call Derivation::report() line 149
- new Invalid line 150
- class-const Nullability::Dependent() line 150
- method-call WriteScope::distinct() line 152
public function column(
list<Field>|null $written,
int $position,
VisibleRelation $target,
?Diagnostic $mismatch,
): FieldAnswers the field a value at a position of a row is assigned to.
Parameters
$written | list<Field>|null | |
$position | int | |
$target | VisibleRelation | |
$mismatch | ?Diagnostic |
Returns
Called from 1
Calls 6
- new Field line 168
- new OutputSlot line 168
- new Dependent line 168
- class-const Nullability::Dependent() line 168
- static-call Check::invariant() line 170
- new Invalid line 172
public function duplicates(
list<Assignment> $assignments,
?RowAlias $alias,
InsertInto $into,
VisibleRelation $target,
list<Field>|null $written,
list<VisibleRelation> $sources,
Derivation $derivation,
Environment $outer,
): voidDerives the row alias and the assignments of ON DUPLICATE KEY UPDATE.
Parameters
$assignments | list<Assignment> | |
$alias | ?RowAlias | |
$into | InsertInto | |
$target | VisibleRelation | |
$written | list<Field>|null | |
$sources | list<VisibleRelation> | The relations of the FROM clause of a query source |
$derivation | Derivation | |
$outer | Environment |
Called from 3
- method-call SqlSemantics\Platform\MySql\Rules\Dml\InsertFacts::rows() packages/sql-semantics-mysql/src/Rules/Dml/InsertFacts.php:88
- method-call SqlSemantics\Platform\MySql\Rules\Dml\InsertFacts::set() packages/sql-semantics-mysql/src/Rules/Dml/InsertFacts.php:100
- method-call SqlSemantics\Platform\MySql\Rules\Dml\InsertFacts::query() packages/sql-semantics-mysql/src/Rules/Dml/InsertFacts.php:117
Calls 10
- method-call Derivation::report() line 187
- new Misuse line 187
- class-const MisuseRule::DuplicateAlias() line 187
- new Environment line 189
- new VisibleRelation line 190
- method-call Derivation::relation() line 190
- method-call WriteScope::assign() line 195
- new WriteScope line 195
- method-call GeneratedWrites::assignments() line 196
- new GeneratedWrites line 196
Test cases 1§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 1
InsertFactsTestcalls
Relations§
Instantiated in 3
- new SqlSemantics\Platform\MySql\Statement\Dml\Insert\InsertQuery::deriveStatement() packages/sql-semantics-mysql/src/Statement/Dml/Insert/InsertQuery.php:55
- new SqlSemantics\Platform\MySql\Statement\Dml\Insert\InsertRows::deriveStatement() packages/sql-semantics-mysql/src/Statement/Dml/Insert/InsertRows.php:61
- new SqlSemantics\Platform\MySql\Statement\Dml\Insert\InsertSet::deriveStatement() packages/sql-semantics-mysql/src/Statement/Dml/Insert/InsertSet.php:62
Method calls 3
- method-call SqlSemantics\Platform\MySql\Statement\Dml\Insert\InsertQuery::deriveStatement() packages/sql-semantics-mysql/src/Statement/Dml/Insert/InsertQuery.php:55
- method-call SqlSemantics\Platform\MySql\Statement\Dml\Insert\InsertRows::deriveStatement() packages/sql-semantics-mysql/src/Statement/Dml/Insert/InsertRows.php:61
- method-call SqlSemantics\Platform\MySql\Statement\Dml\Insert\InsertSet::deriveStatement() packages/sql-semantics-mysql/src/Statement/Dml/Insert/InsertSet.php:62