tripal/t4d8

Table prefixes applied twice on Updates

spficklin opened this issue · 2 comments

When using the TripalDBX to perform an update (either via the update() function or the query() function, the table name gets prefixed twice. Once with the prefix for the schema (which it should be) and then again with the prefix for the default (Drupal/public) schema.

For example, the following select statement runs just fine during functional testing:

$query = $this->chado->select('1:db', 'db')
      ->condition('db.name', 'GO', '=')
      ->fields('db', ['name', 'url', 'urlprefix', 'description']);
$result = $query->execute();

The insert statement runs just fine as well:

$query = $this->chado->insert('1:db')
        ->fields(['name' => 'GO')]);
$query->execute();

But the update does not work:

$query = $this->chado->update('1:db')
       ->fields(['description' => $description])
       ->condition('name', 'GO'), '=');
$query->execute();

I get the following error message on the update:

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation "test62341094_test_chado_b09ffaffa37966aa.db" does not exist
LINE 1: UPDATE "test62341094_test_chado_b09ffaffa37966aa.db" SET "de...
               ^: UPDATE "test62341094_test_chado_b09ffaffa37966aa.db" SET "description"=:db_update_placeholder_0
WHERE "name" = :db_condition_placeholder_0; Array

From the error message it's clear that the testing prefix of test62341094 along with the testing Chado schema named _test_chado_b09ffaffa37966aa are both getting added as a prefix to the table name.

This seems to be caused by the way Drupal handles selects, inserts and updates. For updates it's calling the prefixTables function more than once on the same query string. I'll submit a PR to get around this problem.

@guignonv you might want to check your other more generic module (I forget the name), as I suppose the problem is there too.

Completed in PR #219