Index: includes/database/schema.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/database/schema.inc,v
retrieving revision 1.5
diff -u -p -r1.5 schema.inc
--- includes/database/schema.inc	3 Dec 2008 16:32:21 -0000	1.5
+++ includes/database/schema.inc	7 Dec 2008 20:37:31 -0000
@@ -415,14 +415,51 @@ abstract class DatabaseSchema {
    *   Array, both the keys and the values are the matching tables.
    */
   public function findTables($table_expression) {
-    global $db_prefix;
-    $info = Database::getConnectionInfo();
     $result = db_query("SELECT table_name FROM information_schema.tables WHERE table_schema = :database AND table_name LIKE :table_name", array(
-      ':database' => $info['default']['database'],
+      ':database' => $this->getSchema($table_expression),
       ':table_name' => $table_expression,
     ));
     return $result->fetchAllKeyed(0, 0);
   }
+
+  /**
+   * breaks the db_prefix up into better peices
+   *
+   * @param (optional) table name to get specific infomation about
+   *
+   * @return 
+   *    array of table/schema/database information
+   */
+  protected function getPrefixInfo($table = null) {
+    global $db_prefix;
+    
+    $prefixes = is_array($db_prefix) ? $db_prefix : array('default' => $db_prefix);
+    if (isset($table)) {
+      $prefixes = isset($prefixes[$table]) ? array($table => $prefixes[$table]) : array('default' => $prefixes['default']);  
+    }
+
+    foreach ($prefixes as $name => $prefix) {
+      if (strpos($prefix, '.')) {
+        list($schema,$pfx) = explode('.', $prefix); 
+        $prefixes[$name] = (object) array(
+            "schema" => $schema,
+            "prefix" => $pfx,
+        );
+      } 
+      else {
+        $info = isset($info) ? $info : Database::getConnectionInfo();
+        $prefixes[$name] = (object) array(
+            "schema" => $info['default']['database'],
+            "prefix" => $prefix,
+        );
+      }
+    }
+    if (isset($table)) 
+    {
+        return isset($prefixes[$table]) ? $prefixes[$table] : $prefixes['default'];
+    }
+    return $prefixes;
+  }
 }
 
 /**
Index: includes/database/mysql/schema.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/database/mysql/schema.inc,v
retrieving revision 1.7
diff -u -p -r1.7 schema.inc
--- includes/database/mysql/schema.inc	2 Dec 2008 19:45:01 -0000	1.7
+++ includes/database/mysql/schema.inc	7 Dec 2008 20:37:31 -0000
@@ -15,14 +15,22 @@
 class DatabaseSchema_mysql extends DatabaseSchema {
 
   public function tableExists($table) {
-    return (bool) $this->connection->query("SHOW TABLES LIKE '{" . $table . "}'", array(), array())->fetchField();
-  }
-
+    $info = $this->getPrefixInfo($table);
+    return (bool) db_result(db_query("SELECT COUNT(table_name) FROM information_schema.tables WHERE table_schema = :database AND table_name = :table", array(
+      ':database'   => $info->schema,
+      ':table'    => $info->prefix . $table,
+    )));
+  }   
+      
   public function columnExists($table, $column) {
-    return (bool) $this->connection->query("SHOW COLUMNS FROM {" . $this->connection->escapeTable($table) . "} LIKE '" . $this->connection->escapeTable($column) . "'", array(), array())->fetchField();
+    $info = $this->getPrefixInfo($table); 
+    return (bool) db_result(db_query("SELECT COUNT(column_name) FROM information_schema.columns WHERE table_schema = :schema AND table_name = :table AND column_name = :column", array(
+      ':schema'   => $info->schema,
+      ':table'    => $info->prefix . $table,
+      ':column'   => $column,
+    )));
   }
 
-
   /**
    * Generate SQL to create a new table from a Drupal schema definition.
    *
Index: includes/database/pgsql/schema.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/database/pgsql/schema.inc,v
retrieving revision 1.3
diff -u -p -r1.3 schema.inc
--- includes/database/pgsql/schema.inc	26 Nov 2008 13:42:25 -0000	1.3
+++ includes/database/pgsql/schema.inc	7 Dec 2008 20:37:31 -0000
@@ -14,11 +14,24 @@
 class DatabaseSchema_pgsql extends DatabaseSchema {
 
   public function tableExists($table) {
-    return (bool) db_result(db_query("SELECT COUNT(*) FROM pg_class WHERE relname = '{" . db_escape_table($table) . "}'"));
+    $db_info = Database::getConnectionInfo();
+    $info = $this->getPrefixInfo($table);
+    return (bool) db_result(db_query("SELECT COUNT(table_name) FROM information_schema.tables WHERE table_schema = :schema AND table_catalog = :database AND table_name = :table", array(
+      ':schema'   => $info->schema,// will return 'public' in most cases
+      ':database' => $db_info['default']['database'],
+      ':table'    => $info->prefix . $table,
+    )));
   }
 
   public function columnExists($table, $column) {
-    return (bool) db_result(db_query("SELECT COUNT(pg_attribute.attname) FROM pg_class, pg_attribute WHERE pg_attribute.attrelid = pg_class.oid AND pg_class.relname = '{" . db_escape_table($table) . "}' AND attname = '" . db_escape_table($column) . "'"));
+    $db_info = Database::getConnectionInfo();
+    $info = $this->getPrefixInfo($table); 
+    return (bool) db_result(db_query("SELECT COUNT(column_name) FROM information_schema.columns WHERE table_schema = :schema AND table_catalog = :database AND table_name = :table AND column_name = :column", array(
+      ':schema'   => $info->schema,
+      ':database' => $db_info['default']['database'],
+      ':table'    => $info->prefix . $table,
+      ':column'   => $column,
+    )));
   }
 
   /**
@@ -506,4 +519,62 @@ class DatabaseSchema_pgsql extends Datab
       }
     }
   }
+
+  /**
+   * Find 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.
+   */
+  public function findTables($table_expression) {
+    $info = Database::getConnectionInfo();
+    $result = db_query("SELECT table_name FROM information_schema.tables WHERE table_schema = :schema AND table_catalog = :database AND table_name LIKE :table_name", array(
+      ':schema'   => $this->getSchema($table_expression),
+      ':database' => $info['default']['database'],
+      ':table_name' => $table_expression,
+    ));
+    return $result->fetchAllKeyed(0, 0);
+  }
+
+  /**
+   * breaks the db_prefix up into better peices
+   *
+   * @param (optional) table name to get specific infomation about
+   *
+   * @return 
+   *    array of table/schema/database information
+   */
+  protected function getPrefixInfo($table = null) {
+    global $db_prefix;
+    
+    $prefixes = is_array($db_prefix) ? $db_prefix : array('default' => $db_prefix);
+    if (isset($table)) {
+      $prefixes = isset($prefixes[$table]) ? array($table => $prefixes[$table]) : array('default' => $prefixes['default']); 
+    }
+
+    foreach ($prefixes as $name => $prefix) {
+      if (strpos($prefix, '.')) {
+        list($schema,$pfx) = explode('.', $prefix);
+        $prefixes[$name] = (object) array(
+            "schema" => $schema,
+            "prefix" => $pfx,
+        );
+      } 
+      else {
+        $prefixes[$name] = (object) array(
+            "schema" => 'public',
+            "prefix" => $prefix,
+        );
+      }
+    }
+    if (isset($table))  
+    { 
+        return isset($prefixes[$table]) ? $prefixes[$table] : $prefixes['default'];
+    } 
+    return $prefixes;
+  }
+
 }
