Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.1291
diff -u -p -r1.1291 common.inc
--- includes/common.inc	19 Feb 2011 13:19:26 -0000	1.1291
+++ includes/common.inc	12 Apr 2011 17:10:28 -0000
@@ -6596,9 +6596,10 @@ function drupal_common_theme() {
 function drupal_install_schema($module) {
   $schema = drupal_get_schema_unprocessed($module);
   _drupal_schema_initialize($schema, $module, FALSE);
+  $connection = Database::getConnection('default', $schema['database key']);
 
   foreach ($schema as $name => $table) {
-    db_create_table($name, $table);
+    $connection->schema()->createTable($name, $table);
   }
 }
 
@@ -6619,10 +6620,11 @@ function drupal_install_schema($module) 
 function drupal_uninstall_schema($module) {
   $schema = drupal_get_schema_unprocessed($module);
   _drupal_schema_initialize($schema, $module, FALSE);
-
+  $connection = Database::getConnection('default', $schema['database key']);
+  
   foreach ($schema as $table) {
-    if (db_table_exists($table['name'])) {
-      db_drop_table($table['name']);
+    if ($connection->schema()->tableExists($table['name'])) {
+      $connection->schema()->dropTable($table['name']);
     }
   }
 }
@@ -6687,6 +6689,9 @@ function _drupal_schema_initialize(&$sch
     if (!isset($table['name'])) {
       $table['name'] = $name;
     }
+    if (!isset($table['database key'])) {
+      $table['database key'] = 'default';
+    }
     if ($remove_descriptions) {
       unset($table['description']);
       foreach ($table['fields'] as &$field) {
@@ -6829,11 +6834,15 @@ function drupal_write_record($table, &$r
         unset($fields[$serial]);
       }
     }
-    $query = db_insert($table, $options)->fields($fields);
+    $query = Database::getConnection('default', $schema['database key'])
+      ->insert($table, $options)
+      ->fields($fields);
     $return = SAVED_NEW;
   }
   else {
-    $query = db_update($table)->fields($fields);
+    $query = Database::getConnection('default', $schema['database key'])
+      ->update($table)
+      ->fields($fields);
     foreach ($primary_keys as $key) {
       $query->condition($key, $object->$key);
     }
Index: includes/database/schema.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/database/schema.inc,v
retrieving revision 1.44
diff -u -p -r1.44 schema.inc
--- includes/database/schema.inc	3 Jan 2011 18:03:54 -0000	1.44
+++ includes/database/schema.inc	12 Apr 2011 17:10:28 -0000
@@ -32,6 +32,9 @@ require_once dirname(__FILE__) . '/query
  *     curly-brackets. For example, the node_revisions table
  *     description field might contain "Stores per-revision title and
  *     body data for each {node}."
+ *   - 'database key': A string containing the key of the database where this
+ *     table is stored. This key is specified in the $databases array in
+ *     settings.php. The default value equals 'default'.
  *   - 'fields': An associative array ('fieldname' => specification)
  *     that describes the table's database columns. The specification
  *     is also an array. The following specification parameters are defined:
