Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1835,6 +1835,11 @@ private function execute_insert_or_replace_statement( WP_Parser_Node $node ): vo
$is_node = $child instanceof WP_Parser_Node;

if ( $child instanceof WP_Parser_Node && 'tableRef' === $child->rule_name ) {
// MySQL supports INSERT without the INTO keyword; SQLite requires it.
if ( ! $node->has_child_token( WP_MySQL_Lexer::INTO_SYMBOL ) ) {
$parts[] = 'INTO';
}

$database = $this->get_database_name( $child );
if ( 'information_schema' === strtolower( $database ) ) {
throw $this->new_access_denied_to_information_schema_exception();
Expand Down
28 changes: 28 additions & 0 deletions packages/mysql-on-sqlite/tests/WP_SQLite_Driver_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -9986,6 +9986,34 @@ public function testCastExpression(): void {
);
}

public function testInsertWithoutInto(): void {
$this->assertQuery( 'CREATE TABLE t (id INT PRIMARY KEY, name VARCHAR(255))' );

// INSERT ... VALUES
$this->assertQuery( "INSERT t (id, name) VALUES (1, 'a')" );

// INSERT IGNORE
$this->assertQuery( "INSERT IGNORE t (id, name) VALUES (1, 'a')" );

// INSERT ... SET
$this->assertQuery( "INSERT t SET id = 2, name = 'b'" );

// INSERT IGNORE ... SET
$this->assertQuery( "INSERT IGNORE t SET id = 2, name = 'b'" );

// INSERT ... SELECT
$this->assertQuery( "INSERT t (id, name) SELECT 3, 'c'" );

// INSERT IGNORE ... SELECT
$this->assertQuery( "INSERT IGNORE t (id, name) SELECT 3, 'c'" );

$res = $this->assertQuery( 'SELECT * FROM t ORDER BY id' );
$this->assertCount( 3, $res );
$this->assertEquals( 'a', $res[0]->name );
$this->assertEquals( 'b', $res[1]->name );
$this->assertEquals( 'c', $res[2]->name );
}

public function testInsertIntoSetSyntax(): void {
$this->assertQuery(
'CREATE TABLE t (
Expand Down
Loading