Skip to content

Commit cc3c494

Browse files
adamzielclaude
andcommitted
Test that UPDATE rejects zero dates in strict mode
Verify that UPDATE statements produce errors for zero dates and zero-in-dates when strict mode is combined with NO_ZERO_DATE or NO_ZERO_IN_DATE, matching the existing INSERT rejection tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7763982 commit cc3c494

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

tests/WP_SQLite_Driver_Tests.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2561,6 +2561,31 @@ public function testZeroDateInUpdate() {
25612561
$this->assertEquals( '0000-00-00 00:00:00', $results[0]->option_value );
25622562
}
25632563

2564+
/**
2565+
* Test that zero dates are rejected in UPDATE when NO_ZERO_DATE and strict mode are on.
2566+
*/
2567+
public function testZeroDateInUpdateRejectedWhenNoZeroDateAndStrictModeAreOn() {
2568+
// Default modes include both NO_ZERO_DATE and STRICT_TRANS_TABLES.
2569+
$this->assertQuery( "INSERT INTO _dates (option_value) VALUES ('2022-01-15 14:30:00');" );
2570+
$this->assertQueryError(
2571+
"UPDATE _dates SET option_value = '0000-00-00 00:00:00';",
2572+
"Incorrect datetime value: '0000-00-00 00:00:00'"
2573+
);
2574+
}
2575+
2576+
/**
2577+
* Test that dates with zero parts are rejected in UPDATE when
2578+
* NO_ZERO_IN_DATE and strict mode are on.
2579+
*/
2580+
public function testZeroInDateInUpdateRejectedWhenNoZeroInDateAndStrictModeAreOn() {
2581+
// Default modes include both NO_ZERO_IN_DATE and STRICT_TRANS_TABLES.
2582+
$this->assertQuery( "INSERT INTO _dates (option_value) VALUES ('2022-01-15 14:30:00');" );
2583+
$this->assertQueryError(
2584+
"UPDATE _dates SET option_value = '2020-00-15 00:00:00';",
2585+
"Incorrect datetime value: '2020-00-15 00:00:00'"
2586+
);
2587+
}
2588+
25642589
public function testCaseInsensitiveSelect() {
25652590
$this->assertQuery(
25662591
"CREATE TABLE _tmp_table (

0 commit comments

Comments
 (0)