classInsertRows
final class InsertRows
implements Statement
uses Snapshot
Public API: explicitly declared with
@visibility public.INSERT or REPLACE of rows written in a VALUES clause, with the optional row alias and ON DUPLICATE KEY UPDATE.
Rule: MYSQL-INSERT-ROWS-001. The facts follow MYSQL-INSERT-001 with the rows of VALUES as the source; VALUE is a synonym of VALUES. Source: https://dev.mysql.com/doc/refman/8.4/en/insert.html. Status: Implemented.
$insert = (new \SqlSemantics\Platform\MySql\Semantics())->analyze("INSERT IGNORE INTO t (a, b) VALUE (1, 'x'), (2, DEFAULT) ON DUPLICATE KEY UPDATE b = VALUES(b)");
[count($insert->statement->rows), count($insert->statement->onDuplicate), $insert->toString()] // => [2, 1, "INSERT IGNORE INTO t (a, b) VALUES (1, 'x'), (2, DEFAULT) ON DUPLICATE KEY UPDATE b = VALUES(b)"]Properties§
public list<InsertedRow> $rowspublic list<Assignment> $onDuplicatepublic InsertInto $intopublic RowAlias|null $alias = nullMethods§
public function __construct(
public InsertInto $into,
list<InsertedRow> $rows,
public RowAlias|null $alias = null,
list<Assignment> $onDuplicate = [],
)Parameters
$into | InsertInto | The head: verb, modifiers, table and column list |
$rows | list<InsertedRow> | The rows; at least one |
$alias | RowAlias|null | The alias of the new row |
$onDuplicate | list<Assignment> | The assignments of ON DUPLICATE KEY UPDATE |
Throws
InvalidConstruction When there is no row, or REPLACE has an alias or ON DUPLICATE KEY UPDATECalls 4
- static-call Check::listOf() line 51
- class-const InsertedRow::class() line 51
- class-const Assignment::class() line 52
- static-call Check::input() line 53
public function deriveStatement(Derivation $derivation): voidDerives the written table, the columns, the rows and the assignments; the statement returns no rows.
Parameters
$derivation | Derivation |
Calls 3
- method-call InsertFacts::rows() line 61
- new InsertFacts line 61
- method-call Derivation::environment() line 61
public function render(Output $out): voidWrites the statement.
Parameters
$out | Output |
Calls 2
- method-call Output::node() line 69
- method-call Output::keyword() line 71
Test cases 7§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 1
Other tests reaching this symbol 6
GeneratedWritesTest::testDefaultTellsDefaultValueItemscallsInsertFactsTest::testColumnDependsOnAnUndeclaredTablecallsInsertFactsTest::testColumnIsInvalidBeyondTheWrittenColumnscallsDefaultRequestTest::testDeriveScalarTakesTheAssignedColumncallsRowAliasTest::testDeriveRelationDependsOnAnUndeclaredTablecallsRowAliasTest::testDeriveRelationNamesTheWrittenColumnscalls