@@ -4413,6 +4413,7 @@ public function testNonStrictModeWithTemporaryTable(): void {
4413
4413
public function testNonStrictModeWithOnDuplicateKeyUpdate (): void {
4414
4414
$ this ->assertQuery ( "SET SESSION sql_mode = '' " );
4415
4415
4416
+ // Create table and insert a row:
4416
4417
$ this ->assertQuery ( 'CREATE TABLE t1 (id INT PRIMARY KEY, name TEXT NOT NULL, size INT DEFAULT 123, color TEXT) ' );
4417
4418
$ this ->assertQuery ( "INSERT INTO t1 VALUES (1, 'A', 10, 'red') " );
4418
4419
$ result = $ this ->assertQuery ( 'SELECT * FROM t1 ' );
@@ -4421,12 +4422,18 @@ public function testNonStrictModeWithOnDuplicateKeyUpdate(): void {
4421
4422
$ this ->assertSame ( '10 ' , $ result [0 ]->size );
4422
4423
$ this ->assertSame ( 'red ' , $ result [0 ]->color );
4423
4424
4425
+ // Ensure ON DUPLICATE KEY UPDATE works:
4424
4426
$ this ->assertQuery ( "INSERT INTO t1 VALUES (1, 'B', 20, 'blue') ON DUPLICATE KEY UPDATE name = 'B' " );
4425
4427
$ result = $ this ->assertQuery ( 'SELECT * FROM t1 ' );
4426
4428
$ this ->assertCount ( 1 , $ result );
4427
4429
$ this ->assertSame ( 'B ' , $ result [0 ]->name );
4428
4430
$ this ->assertSame ( '10 ' , $ result [0 ]->size );
4429
4431
$ this ->assertSame ( 'red ' , $ result [0 ]->color );
4432
+
4433
+ // In MySQL, ON DUPLICATE KEY UPDATE ignores non-strict mode UPDATE behavior:
4434
+ $ this ->expectException ( PDOException::class );
4435
+ $ this ->expectExceptionMessage ( 'SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: t1.name ' );
4436
+ $ this ->assertQuery ( "INSERT INTO t1 VALUES (1, 'C', 30, 'green') ON DUPLICATE KEY UPDATE name = NULL " );
4430
4437
}
4431
4438
4432
4439
public function testNonStrictModeWithReplaceStatement (): void {
0 commit comments