dbDelta() fails upgrading a table when DB prefix contains one or more capitalized letters
|Reported by:||maxidirienzo||Owned by:||dirienzo@…|
In line 1471:
$cqueries[trim( strtolower($matches), '`' )] = $qry;
The table name is converted to lower case to be used as the array key, this array's key is later used for the alter table.... statements, which fails when mysql is configured to be case sensitive for tables names ("lower_case_table_names" system option) which usually differs from Unix to Windows servers.
The bug appears when on these circumstances only:
- MySql configured to be case sensitive on tables names
- WordPress DB prefix contains at least one capital letter
- dbDelta() is invoked with a CREATE TABLE statement and the table DOES EXISTS in the database
Due to the strtolower in line 1471, the DESCRIBE (line 1494) that's being executed won't detect the table already exists and will try to run the CREATE TABLE instead of the ALTER TABLE to add each missing field.
A proposed patch is attached.