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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Damien Tournoud’s picture

This 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.

Stevel’s picture

I would go for changing the documentation, as it's more consistent with other DBTNG functions that prefix the table name as well.

Stevel’s picture

Status: Active » Needs review
FileSize
1.67 KB

And here's a patch. The simpletest cleanup currently assumes that the table name must be prefixed, so changed that too.

Damien Tournoud’s picture

@Stevel: yes, but in that case, this function is *completely* broken.

Suppose you have:

$prefixes = array(
  'default' => 'default_',
  'users' => 'shared_',
);

Then, db_find_tables('users%'); and db_find_tables('user%'); will never find anything. Only db_find_tables('users'); will find the table.

Stevel’s picture

The 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.

Status: Needs review » Needs work

The last submitted patch, 851168-leave-unprefixed-alone.patch, failed testing.

Stevel’s picture

Status: Needs work » Needs review
FileSize
6.27 KB

Forgot the default parameter in the mysql schema.

Stevel’s picture

FileSize
6.27 KB

Reroll because #851140: DatabaseSchema::getPrefixInfo() is *severely* broken just got committed, so the previous patch didn't apply any more.

chx’s picture

Status: Needs review » Reviewed & tested by the community

Yay for choice.

marcingy’s picture

#8: 851168-reroll.patch queued for re-testing.

webchick’s picture

Since this touches /includes/database/schema.inc, do we need Larry's sign-off here?

webchick’s picture

Status: Reviewed & tested by the community » Needs review

When I talked to Damien the other day, he said the answer to that question was "yes".

Damien Tournoud’s picture

Status: Needs review » Reviewed & tested by the community

Actually, 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.

Crell’s picture

I'm Larry Crell, and I approve of this patch. *Makes a patriotic pose for the camera*

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Good enough. ;)

Committed to HEAD.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.