File tree Expand file tree Collapse file tree 2 files changed +26
-6
lines changed Expand file tree Collapse file tree 2 files changed +26
-6
lines changed Original file line number Diff line number Diff line change @@ -10522,6 +10522,25 @@ public function testCastValuesOnInsertInNonStrictMode(): void {
1052210522 $ this ->assertQuery ( 'DROP TABLE t ' );
1052310523 }
1052410524
10525+ public function testCastValuesOnDuplicateKeyUpdate (): void {
10526+ $ this ->assertQuery ( 'CREATE TABLE t (value TEXT UNIQUE) ' );
10527+ $ this ->assertQuery ( "INSERT INTO t VALUES ('test') " );
10528+
10529+ // Ensure that type casting is applied to ON DUPLICATE KEY UPDATE clause.
10530+ $ this ->assertQuery ( "INSERT INTO t VALUES ('test') ON DUPLICATE KEY UPDATE value = 0x61 " );
10531+ $ this ->assertSame ( 'a ' , $ this ->assertQuery ( 'SELECT * FROM t ' )[0 ]->value );
10532+ }
10533+
10534+ public function testCastValuesOnDuplicateKeyUpdateInNonStrictMode (): void {
10535+ $ this ->assertQuery ( "SET SESSION sql_mode = '' " );
10536+ $ this ->assertQuery ( 'CREATE TABLE t (value INT UNIQUE) ' );
10537+ $ this ->assertQuery ( "INSERT INTO t VALUES (123) " );
10538+
10539+ // Ensure that type casting is applied to ON DUPLICATE KEY UPDATE clause.
10540+ $ this ->assertQuery ( "INSERT INTO t VALUES (123) ON DUPLICATE KEY UPDATE value = 'test' " );
10541+ $ this ->assertSame ( '0 ' , $ this ->assertQuery ( 'SELECT * FROM t ' )[0 ]->value );
10542+ }
10543+
1052510544 public function testCastValuesOnUpdate (): void {
1052610545 // INTEGER
1052710546 $ this ->assertQuery ( 'CREATE TABLE t (value INT) ' );
Original file line number Diff line number Diff line change @@ -1531,6 +1531,13 @@ private function execute_insert_or_replace_statement( WP_Parser_Node $node ): vo
15311531 $ table_ref = $ node ->get_first_child_node ( 'tableRef ' );
15321532 $ table_name = $ this ->unquote_sqlite_identifier ( $ this ->translate ( $ table_ref ) );
15331533 $ parts [] = $ this ->translate_insert_or_replace_body ( $ table_name , $ child );
1534+ } elseif ( $ is_node && 'insertUpdateList ' === $ child ->rule_name ) {
1535+ // Translate "ON DUPLICATE KEY UPDATE" to "ON CONFLICT DO UPDATE SET".
1536+ $ parts [] = 'ON CONFLICT DO UPDATE SET ' ;
1537+ $ parts [] = $ this ->translate_update_list (
1538+ $ table_name ,
1539+ $ child ->get_first_child_node ( 'updateList ' )
1540+ );
15341541 } else {
15351542 $ parts [] = $ this ->translate ( $ child );
15361543 }
@@ -3241,12 +3248,6 @@ private function translate( $node ): ?string {
32413248 return null ;
32423249 }
32433250 return $ this ->translate_sequence ( $ node ->get_children () );
3244- case 'insertUpdateList ' :
3245- // Translate "ON DUPLICATE KEY UPDATE" to "ON CONFLICT DO UPDATE SET".
3246- return sprintf (
3247- 'ON CONFLICT DO UPDATE SET %s ' ,
3248- $ this ->translate ( $ node ->get_first_child_node ( 'updateList ' ) )
3249- );
32503251 case 'simpleExpr ' :
32513252 return $ this ->translate_simple_expr ( $ node );
32523253 case 'predicateOperations ' :
You can’t perform that action at this time.
0 commit comments