File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1835,6 +1835,11 @@ private function execute_insert_or_replace_statement( WP_Parser_Node $node ): vo
18351835 $ is_node = $ child instanceof WP_Parser_Node;
18361836
18371837 if ( $ child instanceof WP_Parser_Node && 'tableRef ' === $ child ->rule_name ) {
1838+ // MySQL supports INSERT without the INTO keyword; SQLite requires it.
1839+ if ( ! $ node ->has_child_token ( WP_MySQL_Lexer::INTO_SYMBOL ) ) {
1840+ $ parts [] = 'INTO ' ;
1841+ }
1842+
18381843 $ database = $ this ->get_database_name ( $ child );
18391844 if ( 'information_schema ' === strtolower ( $ database ) ) {
18401845 throw $ this ->new_access_denied_to_information_schema_exception ();
Original file line number Diff line number Diff line change @@ -9986,6 +9986,34 @@ public function testCastExpression(): void {
99869986 );
99879987 }
99889988
9989+ public function testInsertWithoutInto (): void {
9990+ $ this ->assertQuery ( 'CREATE TABLE t (id INT PRIMARY KEY, name VARCHAR(255)) ' );
9991+
9992+ // INSERT ... VALUES
9993+ $ this ->assertQuery ( "INSERT t (id, name) VALUES (1, 'a') " );
9994+
9995+ // INSERT IGNORE
9996+ $ this ->assertQuery ( "INSERT IGNORE t (id, name) VALUES (1, 'a') " );
9997+
9998+ // INSERT ... SET
9999+ $ this ->assertQuery ( "INSERT t SET id = 2, name = 'b' " );
10000+
10001+ // INSERT IGNORE ... SET
10002+ $ this ->assertQuery ( "INSERT IGNORE t SET id = 2, name = 'b' " );
10003+
10004+ // INSERT ... SELECT
10005+ $ this ->assertQuery ( "INSERT t (id, name) SELECT 3, 'c' " );
10006+
10007+ // INSERT IGNORE ... SELECT
10008+ $ this ->assertQuery ( "INSERT IGNORE t (id, name) SELECT 3, 'c' " );
10009+
10010+ $ res = $ this ->assertQuery ( 'SELECT * FROM t ORDER BY id ' );
10011+ $ this ->assertCount ( 3 , $ res );
10012+ $ this ->assertEquals ( 'a ' , $ res [0 ]->name );
10013+ $ this ->assertEquals ( 'b ' , $ res [1 ]->name );
10014+ $ this ->assertEquals ( 'c ' , $ res [2 ]->name );
10015+ }
10016+
998910017 public function testInsertIntoSetSyntax (): void {
999010018 $ this ->assertQuery (
999110019 'CREATE TABLE t (
You can’t perform that action at this time.
0 commit comments