Skip to content
This repository was archived by the owner on Jun 2, 2025. It is now read-only.

Commit 079166d

Browse files
committed
Add a test to ensure ON DUPLICATE KEY UPDATE clause ignores non-strict mode
1 parent d39df53 commit 079166d

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

tests/WP_SQLite_Driver_Tests.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4413,6 +4413,7 @@ public function testNonStrictModeWithTemporaryTable(): void {
44134413
public function testNonStrictModeWithOnDuplicateKeyUpdate(): void {
44144414
$this->assertQuery( "SET SESSION sql_mode = ''" );
44154415

4416+
// Create table and insert a row:
44164417
$this->assertQuery( 'CREATE TABLE t1 (id INT PRIMARY KEY, name TEXT NOT NULL, size INT DEFAULT 123, color TEXT)' );
44174418
$this->assertQuery( "INSERT INTO t1 VALUES (1, 'A', 10, 'red')" );
44184419
$result = $this->assertQuery( 'SELECT * FROM t1' );
@@ -4421,12 +4422,18 @@ public function testNonStrictModeWithOnDuplicateKeyUpdate(): void {
44214422
$this->assertSame( '10', $result[0]->size );
44224423
$this->assertSame( 'red', $result[0]->color );
44234424

4425+
// Ensure ON DUPLICATE KEY UPDATE works:
44244426
$this->assertQuery( "INSERT INTO t1 VALUES (1, 'B', 20, 'blue') ON DUPLICATE KEY UPDATE name = 'B'" );
44254427
$result = $this->assertQuery( 'SELECT * FROM t1' );
44264428
$this->assertCount( 1, $result );
44274429
$this->assertSame( 'B', $result[0]->name );
44284430
$this->assertSame( '10', $result[0]->size );
44294431
$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" );
44304437
}
44314438

44324439
public function testNonStrictModeWithReplaceStatement(): void {

0 commit comments

Comments
 (0)