Problem/Motivation
Documentation on SelectInterface::leftJoin():
* @param $table
* The table against which to join. May be a string or another SelectQuery
* object. If a query object is passed, it will be used as a subselect.
* Unless the table name starts with the database / schema name and a dot
* it will be prefixed.
Which means you can pass the fully qualified table name to this method, inlcuding the database name. If your database name is "drupal-8" (valid in MySQL) you should be able to pass in "drupal-8.node" if you want to join to the node table for example. The problem is that some escape*() method on Drupal\Core\Database\Connection strips the "-" character from that string. Your query will have a join to "drupal8.node", which of course refers to a completely different database and MySQL will throw an access denied error or an exception that the database does not exist.
Proposed resolution
Never use "-" in your MySQL database names, although it is allowed!
Or we could fix the MySQL driver to properly support "-".
Remaining tasks
?
User interface changes
none.
API changes
none.
Data model changes
none.
Comments
Comment #2
andypostAs docs said dash is allowed only if quoted, so maybe better to change strategy from removing chars to proper quoting?
http://dev.mysql.com/doc/refman/5.7/en/identifiers.html
https://www.postgresql.org/docs/9.0/static/sql-syntax-lexical.html
https://www.sqlite.org/lang_keywords.html
Comment #5
joachim CreditAttribution: joachim commentedDuplicate of #1426084: Provide backtick escaping for MySQL in DB abstraction layer, which is a more comprehensive fix?
Comment #6
alexpottThis is not quite addressed by #2986452: Database reserved keywords need to be quoted as per the ANSI standard which is a new issue that addresses a lot of #1426084: Provide backtick escaping for MySQL in DB abstraction layer for an non-db specific point of view. But 2986452 does add the necessary quoting of table names so is an essential first step. This issue will be postponed on that and then once that lands should be used to add test coverage for all supported databases to ensure that we can handle hyphens in table names in all of them.
Comment #7
sjerdoComment #8
kriboogh CreditAttribution: kriboogh at Calibrate commentedThis is fixed by 2 patches:
https://www.drupal.org/project/drupal/issues/2986452
https://www.drupal.org/project/drupal/issues/3011987