Closed (fixed)
Project:
Drupal core
Version:
9.2.x-dev
Component:
mysql db driver
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
15 Jun 2021 at 19:42 UTC
Updated:
30 Nov 2021 at 20:19 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
effulgentsia commentedComment #4
mcdruid commentedThis is a great fallback / safety net.
However, should we consider simply changing the identifierQuotes to backticks by default? Perhaps there would need to be a deprecation dance (although not sure what that would look like in this case).
We went with backticks in D7 - having originally intended to backport the double quotes implementation - in order to avoid the risk of contrib or custom code conflicting with the ANSI_QUOTES requirement or similar (e.g. #3172388: backup_migrate resets sql_mode causing problems with D7's MySQL 8 support).
Comment #5
effulgentsia commentedGood question. Asked in #2966523-78: MySQL 8 Support.
Comment #6
effulgentsia commentedMeanwhile, I'm curious what else breaks without our other default sql_mode options. Here's a patch to find that out for all of our kernel and functional tests.
Comment #8
effulgentsia commentedOnly 18 failures in #6, that's fewer than I expected. I'll open separate issues for them.
In the meantime, back to the scope of this issue. This goes back to the patch in #2, but removes the call to
str_contains(), since that's a PHP 8 only function.This does not address #4 yet, since I'd like others to weigh in on that.
Comment #9
mcdruid commentedLooks like the double quotes are very hard-coded in D8:
https://git.drupalcode.org/project/drupal/-/blob/8.9.16/core/lib/Drupal/...
I don't see any mention of case (in)sensitivity in the MySQL docs, but a quick experiment suggests that the sql_mode value is not case sensitive.
Perhaps we should cater for the (perhaps somewhat unlikely) scenario of a custom sql_mode not being all uppercase?
Comment #10
wim leersSeems like this problem is even worse when database or tables names consists solely of digits:
— https://dev.mysql.com/doc/refman/8.0/en/identifiers.html
IOW: On MySQL, you should always quote identifiers, either using
"whenANSI_QUOTESis on, otherwise using`.That makes this at least major IMHO, bordering on critical. Any site that turns off
ANSI_QUOTESwhich uses a fully numerical database name will get a SQL error, and fail to work.Worse, counter to the docs, I can confirm that even database names that just start with a digit reproduce this behavior:
⇒
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '101.foo f ON f.id = u.uid' at line 1⇒
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '73829e0c4090444f85fbae2e92f8925a.foo f ON f.id = u.uid' at line 1e(the letter "e") in the database name, which makes MySQL interpret it as a number in exponential notation! 🤪🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯 Check yourself:⇒
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '1e0.foo f ON f.id = u.uid' at line 1… yet
1a0works fine!To reproduce:
footable like so in each:⚠️ Databases named using only digits (unlikely) or named with a hash (kinda likely) that happen to contain the letter "e" (unlikely) will fail hard! ⚠️
Comment #11
daffie commentedThe test for 'ANSI' only works because there are only 2 sql_modes that have the text 'ANSI' in it and they are the 2 we are testing for. Maybe we should add a comment for that.
Can we change this code to:
As I would very much like to test that backticks are being used for MySQL.
Comment #12
effulgentsia commentedComment #13
effulgentsia commented#12 addresses #9 and #11.
Comment #14
daffie commentedTestbot is failing for PostgreSQL and SQLite. Maybe doing:
$info['default']['init_commands']['sql_mode'] = "SET sql_mode = ''";only for MySQL.Comment #15
effulgentsia commentedThis skips the test for non-mysql.
Comment #16
daffie commentedThe testbot is still not happy.
Comment #17
effulgentsia commentedComment #18
daffie commentedBugfix with testing.
For me it is RTBC.
Comment #19
wim leersNice work! 😊
Comment #22
catchCommitted/pushed to 9.3.x and cherry-picked to 9.2.x, thanks!
Comment #24
teodyseguinI was still able to reproduce this one. After upgrading to 9.2.9 it started to throw an error message
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"users_field_data" SET "access"='1638221696' WHERE "uid" = '1'' at line 1: UPDATE "users_field_data" SET "access"=:db_update_placeholder_0 WHERE "uid" = :db_condition_placeholder_0; Array ( [:db_update_placeholder_0] => 1638221696 [:db_condition_placeholder_0] => 1 ) in Drupal\user\UserStorage->updateLastAccessTimestamp()
Site is broken because of this.
I got this while running in a
landosetup and the version of mysql server is (mysql Ver 14.14 Distrib 5.7.29).Comment #25
teodyseguinComment #26
mcdruid commented@teodyseguin what do you have your
sql_modeset to when your site has problems? (It's typically a key/value pair underinit_commandsin the$databasesconfiguration in settings.php)Comment #27
teodyseguinHi @mcdruid.. I don't have the
init_commandsbeing set the from thesettings.php