From 9ad0a7ea9b9fefecef1d33ee26d654201f9627d1 Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Mon, 2 Aug 2010 18:55:17 +0000 Subject: #851168 by Stevel, Damien Tournoud: Fixed db_find_tables() expects tables to be prefixed, inconsistent implementation and documentation. --- includes/database/mysql/schema.inc | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'includes/database/mysql') diff --git a/includes/database/mysql/schema.inc b/includes/database/mysql/schema.inc index ca7a14be4..1712ca2a4 100644 --- a/includes/database/mysql/schema.inc +++ b/includes/database/mysql/schema.inc @@ -30,16 +30,19 @@ class DatabaseSchema_mysql extends DatabaseSchema { * @return * A keyed array with information about the database, table name and prefix. */ - protected function getPrefixInfo($table = 'default') { + protected function getPrefixInfo($table = 'default', $add_prefix = TRUE) { $info = array('prefix' => $this->connection->tablePrefix($table)); - if (($pos = strpos($info['prefix'], '.')) !== FALSE) { - $info['database'] = substr($info['prefix'], 0, $pos); - $info['table'] = substr($info['prefix'], ++$pos) . $table; + if ($add_prefix) { + $table = $info['prefix'] . $table; + } + if (($pos = strpos($table, '.')) !== FALSE) { + $info['database'] = substr($table, 0, $pos); + $info['table'] = substr($table, ++$pos); } else { $db_info = Database::getConnectionInfo(); $info['database'] = $db_info['default']['database']; - $info['table'] = $info['prefix'] . $table; + $info['table'] = $table; } return $info; } @@ -52,10 +55,10 @@ class DatabaseSchema_mysql extends DatabaseSchema { * database as the schema unless specified otherwise, and exclude table_catalog * from the condition criteria. */ - protected function buildTableNameCondition($table_name, $operator = '=') { + protected function buildTableNameCondition($table_name, $operator = '=', $add_prefix = TRUE) { $info = $this->connection->getConnectionOptions(); - $table_info = $this->getPrefixInfo($table_name); + $table_info = $this->getPrefixInfo($table_name, $add_prefix); $condition = new DatabaseCondition('AND'); $condition->condition('table_schema', $table_info['database']); -- cgit v1.2.3