DatabaseSchema_mysql::createTableSql() can't set table collation

Created on 10 February 2014, about 11 years ago
Updated 29 May 2024, 11 months ago

Problem/Motivation

Setting collation in the table schema for MySQL tables has no effect. Per the original report:

I would very much like to see it fixed in D7 ASAP, because it's causing major problems for my module, S3 File System. I define a table with utf8_bin collation, since I need case-sensitive primary keys, but the collation setting gets ignored, and I have to run db_query("ALTER TABLE {s3fs_file} CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin"); manually to fix it.

This bug also makes it clear that the tests for the database creation code are incomplete.

Proposed resolution

Apply any explicit collation settings in the table schema before checking for collation settings in the connection info.

Remaining tasks

Write tests (MySQL-specific, presumably - do the other core db engines purport to support table-specific collations?).

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

TBD

Original issue summary

There's a typo in DatabaseSchema_mysql::createTableSql() which makes the 'collation' setting in schema definitions get silently ignored. The schema info variable is called $table, but it's referenced in the collation code as $info. Since it's wrapped in a !empty() check, PHP happily confirms that $info['collation'] is always empty, because $info is undefined.

The fix is simply to rename $info to $table, which I've done in the attached patches (this bug exists in D8 and D7).

I would very much like to see it fixed in D7 ASAP, because it's causing major problems for my module, S3 File System. I define a table with utf8_bin collation, since I need case-sensitive primary keys, but the collation setting gets ignored, and I have to run db_query("ALTER TABLE {s3fs_file} CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin"); manually to fix it.

This bug also makes it clear that the tests for the database creation code are incomplete. Unfortunately, I know nothing about drupal testing, so I can't write a patch for that.

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
MySQL driverΒ  β†’

Last updated 11 days ago

Created by

πŸ‡ΊπŸ‡ΈUnited States coredumperror

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024