From 285bebf9f049a944c1e2155abdf31f8813d1cabe Mon Sep 17 00:00:00 2001 From: noruzzamans Date: Sat, 24 Oct 2026 17:29:12 +0600 Subject: [PATCH] Fix '0' column default preservation during non-strict INSERT In non-strict mode, omitted columns are filtered from synthetic subqueries when they have a default value. A loose truthiness check previously caused string '0' to be evaluated as false, substituting an implicit default empty string instead of preserving the column default. Use strict null check consistent with the rest of the codebase, and add regression assertions in testNonStrictSqlModeNotNullWithDefault. --- .../src/sqlite/class-wp-mysql-on-sqlite.php | 2 +- .../mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/mysql-on-sqlite/src/sqlite/class-wp-mysql-on-sqlite.php b/packages/mysql-on-sqlite/src/sqlite/class-wp-mysql-on-sqlite.php index 2205634f6..36f045da9 100644 --- a/packages/mysql-on-sqlite/src/sqlite/class-wp-mysql-on-sqlite.php +++ b/packages/mysql-on-sqlite/src/sqlite/class-wp-mysql-on-sqlite.php @@ -6071,7 +6071,7 @@ function ( $column ) use ( $is_strict_mode, $insert_map ) { return false; } $is_nullable = 'YES' === $column['IS_NULLABLE']; - $has_default = $column['COLUMN_DEFAULT']; + $has_default = null !== $column['COLUMN_DEFAULT']; $is_generated = str_contains( $column['EXTRA'], 'auto_increment' ); return ! ( $is_nullable || $has_default || $is_generated ); } diff --git a/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php b/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php index fa0ff7b1c..5d36d7a5c 100644 --- a/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php +++ b/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php @@ -8626,6 +8626,14 @@ public function testNonStrictSqlModeNotNullWithDefault(): void { $result = $this->assertQuery( 'SELECT * FROM t3' ); $this->assertCount( 1, $result ); $this->assertSame( '', $result[0]->value ); + + // No value saves DEFAULT '0' (issue #552): + $this->assertQuery( "CREATE TABLE t4 (id INT NOT NULL, label VARCHAR(10) NOT NULL DEFAULT '0', count INT NOT NULL DEFAULT 0)" ); + $this->assertQuery( 'INSERT INTO t4 (id) VALUES (1)' ); + $result = $this->assertQuery( 'SELECT * FROM t4 WHERE id = 1' ); + $this->assertCount( 1, $result ); + $this->assertSame( '0', $result[0]->label ); + $this->assertSame( '0', $result[0]->count ); } public function testNonStrictModeWithDefaultCurrentTimestamp(): void {