Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The documentation of db_find_tables() is wrong:
/**
* Finds all tables that are like the specified base table name.
*
* @param $table_expression
* An SQL expression, for example "simpletest%" (without the quotes).
* BEWARE: this is not prefixed, the caller should take care of that.
*
* @return
* Array, both the keys and the values are the matching tables.
*/
The base implementation of this (DatabaseSchema::findTables()), used by MySQL and PostgreSQL, pipes the $table_expression
through buildTableNameCondition(), and then to getPrefixInfo(). As a consequence, $table_expression is *actually* prefixed.
More over, ModuleTestCase relies on this to verify that modules are installed correctly. As a consequence those tests fail on SQLite, which doesn't prefix $table_expression.
Let's pick one. Critical for the failure on SQLite.
Comment | File | Size | Author |
---|---|---|---|
#8 | 851168-reroll.patch | 6.27 KB | Stevel |
#7 | 851168-param-default.patch | 6.27 KB | Stevel |
#5 | 851168-leave-unprefixed-alone.patch | 6.26 KB | Stevel |
#3 | 851168-find-tables.patch | 1.67 KB | Stevel |
Comments
Comment #1
Damien Tournoud CreditAttribution: Damien Tournoud commentedThis was changed by #302327: Support cross-schema/database prefixing like we claim to. I originally made $table_expression not prefixed for a reason: it's *really hard* to support both prefixes and a LIKE expression.
This function was supposed to be used for one thing, and one thing only, the "clean-up" feature of Simpletest. I would recommend we remove that, and try to find a better solution for Simpletest. The Module tests should query the Drupal schema, not the SQL tables directly.
Comment #2
Stevel CreditAttribution: Stevel commentedI would go for changing the documentation, as it's more consistent with other DBTNG functions that prefix the table name as well.
Comment #3
Stevel CreditAttribution: Stevel commentedAnd here's a patch. The simpletest cleanup currently assumes that the table name must be prefixed, so changed that too.
Comment #4
Damien Tournoud CreditAttribution: Damien Tournoud commented@Stevel: yes, but in that case, this function is *completely* broken.
Suppose you have:
Then,
db_find_tables('users%');
anddb_find_tables('user%');
will never find anything. Onlydb_find_tables('users');
will find the table.Comment #5
Stevel CreditAttribution: Stevel commentedThe other way around: make sure that the table name is not prefixed for db_find_tables().
db_find_tables (or at least findTables()) needs to stay within the database abstraction layer because the listing tables is database-dependent.
Comment #7
Stevel CreditAttribution: Stevel commentedForgot the default parameter in the mysql schema.
Comment #8
Stevel CreditAttribution: Stevel commentedReroll because #851140: DatabaseSchema::getPrefixInfo() is *severely* broken just got committed, so the previous patch didn't apply any more.
Comment #9
chx CreditAttribution: chx commentedYay for choice.
Comment #10
marcingy CreditAttribution: marcingy commented#8: 851168-reroll.patch queued for re-testing.
Comment #11
webchickSince this touches /includes/database/schema.inc, do we need Larry's sign-off here?
Comment #12
webchickWhen I talked to Damien the other day, he said the answer to that question was "yes".
Comment #13
Damien Tournoud CreditAttribution: Damien Tournoud commentedActually, I'm happy with this patch.
We might consider renaming DatabaseConnection::getPrefixInfo() to DatabaseConnection::getTableInfo(), but that's out of the scope of this particular patch.
Comment #14
Crell CreditAttribution: Crell commentedI'm Larry Crell, and I approve of this patch. *Makes a patriotic pose for the camera*
Comment #15
webchickGood enough. ;)
Committed to HEAD.