You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit f9bdc0f
Browse filesBrowse the repository at this point in the historyBrowse files
Fix utf8mb4_0900_ai_ci collation in tables created by WordPress (#514)
## Summary
With the SQLite driver, `$wpdb->collate` is empty, so
`$wpdb->get_charset_collate()` returns `DEFAULT CHARACTER SET utf8mb4`
without a `COLLATE` clause. Tables created with it (for example, via
`dbDelta()`) therefore use the emulated MySQL 8 default,
**`utf8mb4_0900_ai_ci`**. MariaDB doesn't support this collation, so
these tables fail to import there, including when pushing a WordPress
Studio site to WordPress.com.
This PR makes `$wpdb` use the same charset and collation as WordPress on
MySQL:
- **`$wpdb->charset` is always `utf8mb4`**, matching the emulated
connection. `DB_CHARSET` is ignored.
- **`$wpdb->collate` is `utf8mb4_unicode_520_ci`**, unless `DB_COLLATE`
specifies another UTF-8 collation. For example, `utf8_bin` becomes
`utf8mb4_bin`, as in `wpdb::determine_charset()`.
- **`utf8mb4_unicode_520_ci` is listed** in
`INFORMATION_SCHEMA.COLLATIONS` and `SHOW COLLATION`.
## Why
Previously, `WP_SQLite_DB` initialized the charset only before
connecting. At that point, `wpdb::determine_charset()` leaves the values
unchanged, so the collation stayed empty. The values are now resolved
**without a connection**, since SQLite always uses UTF-8 and needs no
server capability checks. This also makes them available while
connecting, when the driver may reconstruct WordPress tables with
`wp_get_db_schema()`.
Calling `init_charset()` again after connecting, as `wpdb::db_connect()`
does, wouldn't be enough: WordPress Studio may define `DB_CHARSET` in a
mu-plugin that loads later.
This PR leaves the following unchanged:
- **Tables created without a collation** (for example, a plain `CREATE
TABLE`) still use `utf8mb4_0900_ai_ci`, the emulated MySQL 8 default.
- **Existing tables** keep their recorded collation.
- **Column collations** in the information schema remain
`utf8mb4_0900_ai_ci`. Exports use only the table collation.
Broader charset and collation support is tracked in #456.
Alternative to #511.
Related to Automattic/studio#4737.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Improved compatibility with WordPress charset and collation settings
by consistently resolving to `utf8mb4` and the appropriate collation,
including `utf8mb4_unicode_520_ci`.
* Added support for the `utf8mb4_unicode_520_ci` collation in collation
metadata.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
0 commit comments