Skip to content

Commit d7819c5

Browse files
committed
Fix binary default migration tests on SQLite < 3.37
Older driver versions created STRICT tables only on SQLite 3.37.0 and newer, and older SQLite can't parse them. Their non-STRICT tables accept the TEXT defaults, so expect the failing insert only with STRICT tables.
1 parent f563d54 commit d7819c5

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

‎packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ private function createBinaryDefaultTablesFromOlderVersion(): void {
193193
$statement->execute( array( "b'01000001'", 'bit_string' ) );
194194
$statement->execute( array( 'abcd', 'plain_text' ) );
195195

196+
$is_legacy_sqlite = version_compare( $this->engine->get_sqlite_version(), WP_MySQL_On_SQLite::MINIMUM_SQLITE_VERSION, '<' );
197+
$strict = $is_legacy_sqlite ? '' : ' STRICT';
198+
196199
$this->sqlite->exec( 'DROP TABLE t' );
197200
$this->sqlite->exec(
198201
"CREATE TABLE `t` (
@@ -204,10 +207,10 @@ private function createBinaryDefaultTablesFromOlderVersion(): void {
204207
`empty_text` BLOB NOT NULL DEFAULT '',
205208
`expression` BLOB DEFAULT ('abc'),
206209
PRIMARY KEY (`id`)
207-
) STRICT"
210+
)$strict"
208211
);
209212
$this->sqlite->exec( 'DROP TABLE t_expression' );
210-
$this->sqlite->exec( "CREATE TABLE `t_expression` (`id` INT NOT NULL, `expression` BLOB DEFAULT ('abc'), PRIMARY KEY (`id`)) STRICT" );
213+
$this->sqlite->exec( "CREATE TABLE `t_expression` (`id` INT NOT NULL, `expression` BLOB DEFAULT ('abc'), PRIMARY KEY (`id`))$strict" );
211214
}
212215

213216
public function testRegexp() {
@@ -980,10 +983,14 @@ public function testConfigurationMigratesBinaryDefaultsFromOlderVersions(): void
980983
$tables_query = "SELECT name, sql FROM sqlite_master WHERE name IN ('t', 't_expression', 't_current') ORDER BY name";
981984
$tables = $this->sqlite->query( $tables_query )->fetchAll( PDO::FETCH_KEY_PAIR );
982985

983-
$this->assertQueryError(
984-
'INSERT INTO t (id) VALUES (1)',
985-
'SQLSTATE[23000]: Integrity constraint violation: 19 cannot store TEXT value in BLOB column t.hex_string'
986-
);
986+
// STRICT tables reject the TEXT defaults of older versions.
987+
$is_legacy_sqlite = version_compare( $this->engine->get_sqlite_version(), WP_MySQL_On_SQLite::MINIMUM_SQLITE_VERSION, '<' );
988+
if ( ! $is_legacy_sqlite ) {
989+
$this->assertQueryError(
990+
'INSERT INTO t (id) VALUES (1)',
991+
'SQLSTATE[23000]: Integrity constraint violation: 19 cannot store TEXT value in BLOB column t.hex_string'
992+
);
993+
}
987994

988995
$this->reconnectAfterDriverUpgrade();
989996

0 commit comments

Comments
 (0)