Skip to content

Commit ccb3ef0

Browse files
committed
Preserve charset while disconnected
Return the requested charset and collation unchanged when the wpdb instance has no active SQLite handle. Re-enable the WordPress charset tests that this behavior now satisfies.
1 parent 50c1a29 commit ccb3ef0

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

‎.github/workflows/wp-tests-phpunit-run.js‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,10 @@ const expectedFailures = [
6666
'Tests_DB_Charset::test_strip_invalid_text with data set #41',
6767
'Tests_DB_Charset::test_strip_invalid_text_for_column_bails_if_ascii_input_too_long',
6868
'Tests_DB_dbDelta::test_spatial_indices',
69-
'Tests_DB::test_charset_switched_to_utf8mb4',
7069
'Tests_DB::test_delete_value_too_long_for_field with data set "too long"',
7170
'Tests_DB::test_has_cap',
7271
'Tests_DB::test_insert_value_too_long_for_field with data set "too long"',
7372
'Tests_DB::test_mysqli_flush_sync',
74-
'Tests_DB::test_non_unicode_collations',
7573
'Tests_DB::test_pre_get_col_charset_filter',
7674
'Tests_DB::test_process_fields_on_nonexistent_table',
7775
'Tests_DB::test_process_fields_value_too_long_for_field with data set "too long"',

‎packages/plugin-sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-db.php‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ public function close() {
247247
* }
248248
*/
249249
public function determine_charset( $charset, $collate ) {
250+
if ( ! $this->dbh ) {
251+
return compact( 'charset', 'collate' );
252+
}
253+
250254
if ( 'utf8' === $charset ) {
251255
$charset = 'utf8mb4';
252256
}
@@ -406,7 +410,9 @@ public function db_connect( $allow_bail = true ) {
406410
}
407411

408412
$this->last_error = '';
409-
$this->init_charset();
413+
if ( ! isset( $this->charset ) ) {
414+
$this->init_charset();
415+
}
410416

411417
$this->is_pdo_external = isset( $GLOBALS['@pdo'] );
412418
$pdo = $this->is_pdo_external ? $GLOBALS['@pdo'] : null;
@@ -467,8 +473,11 @@ public function db_connect( $allow_bail = true ) {
467473
if ( $this->last_error ) {
468474
return false;
469475
}
470-
$this->ready = true;
476+
471477
$this->has_connected = true;
478+
$this->set_charset( $this->dbh );
479+
480+
$this->ready = true;
472481
$this->set_sql_mode();
473482
return true;
474483
}

0 commit comments

Comments
 (0)