classInsertQuery
final class InsertQuery
implements Statement
uses Snapshot
Public API: explicitly declared with
@visibility public.INSERT or REPLACE of the rows of a query (SELECT, TABLE, VALUES or a set operation), with the optional ON DUPLICATE KEY UPDATE.
Rule: MYSQL-INSERT-QUERY-001. The facts follow MYSQL-INSERT-001 with the query as the source. Source: https://dev.mysql.com/doc/refman/8.4/en/insert-select.html. Status: Implemented.
$insert = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('INSERT INTO t (a) SELECT b FROM u');
[$insert->statement->source instanceof \SqlSemantics\Platform\MySql\Statement\Query\Select, $insert->toString()] // => [true, 'INSERT INTO t (a) SELECT b FROM u']Properties§
public list<Assignment> $onDuplicatepublic InsertInto $intopublic Query $sourceMethods§
public function __construct(
public InsertInto $into,
public Query $source,
list<Assignment> $onDuplicate = [],
)Parameters
$into | InsertInto | The head: verb, modifiers, table and column list |
$source | Query | The query whose rows are written |
$onDuplicate | list<Assignment> | The assignments of ON DUPLICATE KEY UPDATE |
Throws
InvalidConstruction When REPLACE has ON DUPLICATE KEY UPDATECalls 3
- static-call Check::listOf() line 46
- class-const Assignment::class() line 46
- static-call Check::input() line 47
public function deriveStatement(Derivation $derivation): voidDerives the written table, the columns, the query and the assignments; the statement returns no rows.
Parameters
$derivation | Derivation |
Calls 3
- method-call InsertFacts::query() line 55
- new InsertFacts line 55
- method-call Derivation::environment() line 55
public function render(Output $out): voidWrites the statement.
Parameters
$out | Output |
Calls 2
- method-call Output::node() line 63
- method-call Output::keyword() line 65
Test cases 2§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 1
InsertQueryTestcalls