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 {