Index: modules/comment/comment.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.admin.inc,v
retrieving revision 1.23
diff -u -p -r1.23 comment.admin.inc
--- modules/comment/comment.admin.inc	6 Jun 2009 10:27:42 -0000	1.23
+++ modules/comment/comment.admin.inc	14 Jun 2009 19:26:45 -0000
@@ -174,7 +174,7 @@ function comment_multiple_delete_confirm
   foreach (array_filter($edit['comments']) as $cid => $value) {
     $comment = comment_load($cid);
     if (is_object($comment) && is_numeric($comment->cid)) {
-      $subject = db_result(db_query('SELECT subject FROM {comment} WHERE cid = %d', $cid));
+      $subject = db_query('SELECT subject FROM {comment} WHERE cid = :cid', array(':cid' => $cid))->fetchField();
       $form['comments'][$cid] = array('#type' => 'hidden', '#value' => $cid, '#prefix' => '<li>', '#suffix' => check_plain($subject) . '</li>');
       $comment_counter++;
     }
Index: modules/comment/comment.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.install,v
retrieving revision 1.36
diff -u -p -r1.36 comment.install
--- modules/comment/comment.install	4 Jun 2009 03:33:27 -0000	1.36
+++ modules/comment/comment.install	14 Jun 2009 19:26:45 -0000
@@ -42,7 +42,18 @@ function comment_uninstall() {
  */
 function comment_enable() {
   // Insert records into the node_comment_statistics for nodes that are missing.
-  db_query("INSERT INTO {node_comment_statistics} (nid, last_comment_timestamp, last_comment_name, last_comment_uid, comment_count) SELECT n.nid, n.changed, NULL, n.uid, 0 FROM {node} n LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid WHERE c.comment_count IS NULL");
+  $query = db_select('node', 'n');
+  $query->leftJoin('node_comment_statistics', 'ncs', 'ncs.nid = n.nid');
+  $query->addField('n', 'changed', 'last_comment_timestamp');
+  $query->addField('n', 'uid', 'last_comment_uid');
+  $query->addField('n', 'nid');
+  $query->addExpression('0', 'comment_count');
+  $query->addExpression('NULL', 'last_comment_name');
+  $query->isNull('ncs.comment_count');
+
+  db_insert('node_comment_statistics')
+    ->from($query)
+    ->execute();
 }
 
 /**
Index: modules/dblog/dblog.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/dblog/dblog.test,v
retrieving revision 1.21
diff -u -p -r1.21 dblog.test
--- modules/dblog/dblog.test	12 Jun 2009 08:39:36 -0000	1.21
+++ modules/dblog/dblog.test	14 Jun 2009 19:26:49 -0000
@@ -210,7 +210,7 @@ class DBLogTestCase extends DrupalWebTes
     $this->drupalPost('user/' . $user->uid . '/cancel', array('user_cancel_method' => 'user_cancel_reassign'), t('Cancel account'));
 
     // Count rows that have uids for the user.
-    $count = db_query('SELECT COUNT(wid) FROM {watchdog} WHERE uid = %d', $user->uid)->fetchField();
+    $count = db_query('SELECT COUNT(wid) FROM {watchdog} WHERE uid = :uid', array(':uid' => $user->uid))->fetchField();
     $this->assertTrue($count == 0, t('DBLog contains @count records for @name', array('@count' => $count, '@name' => $user->name)));
 
     // Count rows in watchdog that previously related to the deleted user.
Index: modules/field/modules/field_sql_storage/field_sql_storage.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/modules/field_sql_storage/field_sql_storage.test,v
retrieving revision 1.4
diff -u -p -r1.4 field_sql_storage.test
--- modules/field/modules/field_sql_storage/field_sql_storage.test	28 May 2009 10:05:32 -0000	1.4
+++ modules/field/modules/field_sql_storage/field_sql_storage.test	14 Jun 2009 19:26:53 -0000
@@ -43,8 +43,8 @@ class FieldSqlStorageTestCase extends Dr
     $this->assertEqual($t1+1, $t2, 'Entity type ids are sequential');
     $this->assertIdentical(variable_get('field_sql_storage_t1_etid', NULL), $t1, 'First entity type variable is correct');
     $this->assertIdentical(variable_get('field_sql_storage_t2_etid', NULL), $t2, 'Second entity type variable is correct');
-    $this->assertEqual(db_result(db_query("SELECT etid FROM {field_config_entity_type} WHERE type='t1'")), $t1, 'First entity type in database is correct');
-    $this->assertEqual(db_result(db_query("SELECT etid FROM {field_config_entity_type} WHERE type='t2'")), $t2, 'Second entity type in database is correct');
+    $this->assertEqual(db_query("SELECT etid FROM {field_config_entity_type} WHERE type='t1'")->fetchField(), $t1, 'First entity type in database is correct');
+    $this->assertEqual(db_query("SELECT etid FROM {field_config_entity_type} WHERE type='t2'")->fetchField(), $t2, 'Second entity type in database is correct');
     $this->assertEqual($t1, _field_sql_storage_etid('t1'), '_field_sql_storage_etid returns the same value for the first entity type');
     $this->assertEqual($t2, _field_sql_storage_etid('t2'), '_field_sql_storage_etid returns the same value for the second entity type');
   }
@@ -197,31 +197,31 @@ class FieldSqlStorageTestCase extends Dr
 
     // Insert: Field is missing
     field_attach_insert($entity_type, $entity);
-    $count = db_result(db_query("SELECT COUNT(*) FROM {{$this->table}}"));
+    $count = db_query("SELECT COUNT(*) FROM {{$this->table}}")->fetchField();
     $this->assertEqual($count, 0, 'Missing field results in no inserts');
 
     // Insert: Field is NULL
     $entity->{$this->field_name} = NULL;
     field_attach_insert($entity_type, $entity);
-    $count = db_result(db_query("SELECT COUNT(*) FROM {{$this->table}}"));
+    $count = db_query("SELECT COUNT(*) FROM {{$this->table}}")->fetchField();
     $this->assertEqual($count, 0, 'NULL field results in no inserts');
 
     // Add some real data
     $entity->{$this->field_name} = array(0 => array('value' => 1));
     field_attach_insert($entity_type, $entity);
-    $count = db_result(db_query("SELECT COUNT(*) FROM {{$this->table}}"));
+    $count = db_query("SELECT COUNT(*) FROM {{$this->table}}")->fetchField();
     $this->assertEqual($count, 1, 'Field data saved');
 
     // Update: Field is missing. Data should survive.
     unset($entity->{$this->field_name});
     field_attach_update($entity_type, $entity);
-    $count = db_result(db_query("SELECT COUNT(*) FROM {{$this->table}}"));
+    $count = db_query("SELECT COUNT(*) FROM {{$this->table}}")->fetchField();
     $this->assertEqual($count, 1, 'Missing field leaves data in table');
 
     // Update: Field is NULL. Data should be wiped.
     $entity->{$this->field_name} = NULL;
     field_attach_update($entity_type, $entity);
-    $count = db_result(db_query("SELECT COUNT(*) FROM {{$this->table}}"));
+    $count = db_query("SELECT COUNT(*) FROM {{$this->table}}")->fetchField();
     $this->assertEqual($count, 0, 'NULL field leaves no data in table');
   }
 }
Index: modules/forum/forum.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/forum/forum.install,v
retrieving revision 1.29
diff -u -p -r1.29 forum.install
--- modules/forum/forum.install	1 Jun 2009 22:07:09 -0000	1.29
+++ modules/forum/forum.install	14 Jun 2009 19:26:56 -0000
@@ -14,6 +14,14 @@ function forum_install() {
   drupal_install_schema('forum');
   // Set the weight of the forum.module to 1 so it is loaded after the taxonomy.module.
   db_query("UPDATE {system} SET weight = 1 WHERE name = 'forum'");
+
+  // Set node type options.
+  db_insert('variable')
+    ->fields(array(
+      'name' => 'node_options_forum',
+      'value' => serialize(array('status')),
+    ))
+    ->execute();
 }
 
 function forum_enable() {
Index: modules/node/node.api.php
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/node.api.php,v
retrieving revision 1.25
diff -u -p -r1.25 node.api.php
--- modules/node/node.api.php	12 Jun 2009 08:39:38 -0000	1.25
+++ modules/node/node.api.php	14 Jun 2009 19:27:01 -0000
@@ -788,8 +788,12 @@ function hook_form($node, $form_state) {
  * For a detailed usage example, see node_example.module.
  */
 function hook_insert($node) {
-  db_query("INSERT INTO {mytable} (nid, extra)
-    VALUES (%d, '%s')", $node->nid, $node->extra);
+  db_insert('mytable')
+    ->fields(array(
+      'nid' => $node->nid,
+      'extra' => $node->extra,
+    ))
+    ->execute();
 }
 
 /**
@@ -832,8 +836,10 @@ function hook_load($nodes) {
  * For a detailed usage example, see node_example.module.
  */
 function hook_update($node) {
-  db_query("UPDATE {mytable} SET extra = '%s' WHERE nid = %d",
-    $node->extra, $node->nid);
+  db_update('mytable')
+    ->fields(array('extra' => $node->extra))
+    ->condition('nid', $node->nid)
+    ->execute();
 }
 
 /**
Index: modules/node/node.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/node.module,v
retrieving revision 1.1070
diff -u -p -r1.1070 node.module
--- modules/node/node.module	12 Jun 2009 08:39:38 -0000	1.1070
+++ modules/node/node.module	14 Jun 2009 19:27:03 -0000
@@ -2743,7 +2743,7 @@ function _node_access_rebuild_batch_oper
 
   // Process the next 20 nodes.
   $limit = 20;
-  $nids = db_query_range("SELECT nid FROM {node} WHERE nid > %d ORDER BY nid ASC", $context['sandbox']['current_node'], 0, $limit)->fetchCol();
+  $nids = db_query_range("SELECT nid FROM {node} WHERE nid > :nid ORDER BY nid ASC", array(':nid' => $context['sandbox']['current_node']), 0, $limit)->fetchCol();
   $nodes = node_load_multiple($nids, array(), TRUE);
   foreach ($nodes as $node) {
     // To preserve database integrity, only acquire grants if the node
@@ -3216,7 +3216,7 @@ function node_requirements($phase) {
   // Only show rebuild button if there are either 0, or 2 or more, rows
   // in the {node_access} table, or if there are modules that
   // implement hook_node_grants().
-  $grant_count = db_result(db_query('SELECT COUNT(*) FROM {node_access}'));
+  $grant_count = db_query('SELECT COUNT(*) FROM {node_access}')->fetchField();
   if ($grant_count != 1 || count(module_implements('node_grants')) > 0) {
     $value = format_plural($grant_count, 'One permission in use', '@count permissions in use', array('@count' => $grant_count));
   } else {
Index: modules/node/node.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/node.test,v
retrieving revision 1.32
diff -u -p -r1.32 node.test
--- modules/node/node.test	12 Jun 2009 08:39:38 -0000	1.32
+++ modules/node/node.test	14 Jun 2009 19:27:04 -0000
@@ -571,7 +571,7 @@ class NodeAccessRecordsAlterUnitTest ext
     $this->assertTrue(node_load($node1->nid), t('Article node created.'));
 
     // Check to see if grants added by node_test_node_access_records made it in.
-    $records = db_query('SELECT realm, gid FROM {node_access} WHERE nid = %d', $node1->nid)->fetchAll();
+    $records = db_query('SELECT realm, gid FROM {node_access} WHERE nid = :nid', array(':nid' => $node1->nid))->fetchAll();
     $this->assertEqual(count($records), 1, t('Returned the correct number of rows.'));
     $this->assertEqual($records[0]->realm, 'test_article_realm', t('Grant with article_realm acquired for node without alteration.'));
     $this->assertEqual($records[0]->gid, 1, t('Grant with gid = 1 acquired for node without alteration.'));
@@ -581,7 +581,7 @@ class NodeAccessRecordsAlterUnitTest ext
     $this->assertTrue(node_load($node1->nid), t('Unpromoted page node created.'));
 
     // Check to see if grants added by node_test_node_access_records made it in.
-    $records = db_query('SELECT realm, gid FROM {node_access} WHERE nid = %d', $node2->nid)->fetchAll();
+    $records = db_query('SELECT realm, gid FROM {node_access} WHERE nid = :nid', array(':nid' => $node2->nid))->fetchAll();
     $this->assertEqual(count($records), 1, t('Returned the correct number of rows.'));
     $this->assertEqual($records[0]->realm, 'test_page_realm', t('Grant with page_realm acquired for node without alteration.'));
     $this->assertEqual($records[0]->gid, 1, t('Grant with gid = 1 acquired for node without alteration.'));
@@ -592,7 +592,7 @@ class NodeAccessRecordsAlterUnitTest ext
 
     // Check to see if grant added by node_test_node_access_records was altered
     // by node_test_node_access_records_alter.
-    $records = db_query('SELECT realm, gid FROM {node_access} WHERE nid = %d', $node3->nid)->fetchAll();
+    $records = db_query('SELECT realm, gid FROM {node_access} WHERE nid =:nid', array(':nid' => $node3->nid))->fetchAll();
     $this->assertEqual(count($records), 1, t('Returned the correct number of rows.'));
     $this->assertEqual($records[0]->realm, 'test_alter_realm', t('Altered grant with alter_realm acquired for node.'));
     $this->assertEqual($records[0]->gid, 2, t('Altered grant with gid = 2 acquired for node.'));
@@ -639,7 +639,7 @@ class NodeSaveTestCase extends DrupalWeb
    */
   function testImport() {
     // Node ID must be a number that is not in the database.
-    $max_nid = db_result(db_query('SELECT MAX(nid) FROM {node}'));
+    $max_nid = db_query('SELECT MAX(nid) FROM {node}')->fetchField();
     $test_nid = $max_nid + mt_rand(1000, 1000000);
     $title = $this->randomName(8);
     $node = array(
Index: modules/profile/profile.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/profile/profile.module,v
retrieving revision 1.261
diff -u -p -r1.261 profile.module
--- modules/profile/profile.module	3 Jun 2009 07:28:28 -0000	1.261
+++ modules/profile/profile.module	14 Jun 2009 19:27:07 -0000
@@ -341,7 +341,7 @@ function profile_view_profile(&$user) {
 
   // Show private fields to administrators and people viewing their own account.
   if (user_access('administer users') || $GLOBALS['user']->uid == $user->uid) {
-    $result = db_query('SELECT * FROM {profile_field} WHERE visibility <> %d ORDER BY category, weight', PROFILE_HIDDEN);
+    $result = db_query('SELECT * FROM {profile_field} WHERE visibility <> :hidden ORDER BY category, weight', array(':hidden' => PROFILE_HIDDEN));
   }
   else {
     $result = db_query('SELECT * FROM {profile_field} WHERE visibility <> :private AND visibility <> :hidden ORDER BY category, weight', array(':private' => PROFILE_PRIVATE, ':hidden' => PROFILE_HIDDEN));
Index: modules/profile/profile.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/profile/profile.test,v
retrieving revision 1.14
diff -u -p -r1.14 profile.test
--- modules/profile/profile.test	24 May 2009 17:39:33 -0000	1.14
+++ modules/profile/profile.test	14 Jun 2009 19:27:08 -0000
@@ -37,7 +37,7 @@ class ProfileTestCase extends DrupalWebT
     $edit['explanation'] = $this->randomName(50);
 
     $this->drupalPost('admin/user/profile/add/' . $type, $edit, t('Save field'));
-    $fid = db_result(db_query("SELECT fid FROM {profile_field} WHERE title = '%s'", $title));
+    $fid = db_query("SELECT fid FROM {profile_field} WHERE title = :title", array(':title' => $title))->fetchField();
     $this->assertTrue($fid, t('New Profile field has been entered in the database'));
 
     // Check that the new field is appearing on the user edit form.
Index: modules/simpletest/tests/database_test.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/database_test.test,v
retrieving revision 1.57
diff -u -p -r1.57 database_test.test
--- modules/simpletest/tests/database_test.test	5 Jun 2009 16:55:45 -0000	1.57
+++ modules/simpletest/tests/database_test.test	14 Jun 2009 19:27:16 -0000
@@ -518,10 +518,14 @@ class DatabaseInsertTestCase extends Dat
    * Test that the INSERT INTO ... SELECT ... syntax works.
    */
   function testInsertSelect() {
-    $query = db_select('test_people', 'tp')->fields('tp', array('name', 'age', 'job'));
+    $query = db_select('test_people', 'tp');
+    // Use an expression to test the correct order of the insert query fields.
+    $query->addExpression('tp.age', 'age');
+    $query
+      ->fields('tp', array('name','job'))
+      ->condition('tp.name', 'Meredith');
 
     db_insert('test')
-      ->fields(array('name', 'age', 'job'))
       ->from($query)
       ->execute();
 
Index: modules/statistics/statistics.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/statistics/statistics.module,v
retrieving revision 1.304
diff -u -p -r1.304 statistics.module
--- modules/statistics/statistics.module	27 May 2009 18:34:01 -0000	1.304
+++ modules/statistics/statistics.module	14 Jun 2009 19:27:21 -0000
@@ -393,5 +393,5 @@ function statistics_ranking() {
  * Implement hook_update_index().
  */
 function statistics_update_index() {
-  variable_set('node_cron_views_scale', 1.0 / max(1, db_result(db_query('SELECT MAX(totalcount) FROM {node_counter}'))));
+  variable_set('node_cron_views_scale', 1.0 / max(1, db_query('SELECT MAX(totalcount) FROM {node_counter}'))->fetchField());
 }
Index: modules/system/system.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.install,v
retrieving revision 1.344
diff -u -p -r1.344 system.install
--- modules/system/system.install	13 Jun 2009 20:40:08 -0000	1.344
+++ modules/system/system.install	14 Jun 2009 19:27:27 -0000
@@ -359,67 +359,163 @@ function system_install() {
   // uid 2 which is not what we want. So we insert the first user here, the
   // anonymous user. uid is 1 here for now, but very soon it will be changed
   // to 0.
-  db_query("INSERT INTO {users} (name, mail) VALUES('%s', '%s')", '', '');
+  db_insert('users')
+    ->fields(array(
+      'name' => '',
+      'mail' => '',
+    ))
+    ->execute();
   // We need some placeholders here as name and mail are uniques and data is
   // presumed to be a serialized array. Install will change uid 1 immediately
   // anyways. So we insert the superuser here, the uid is 2 here for now, but
   // very soon it will be changed to 1.
-  db_query("INSERT INTO {users} (name, mail, created, status, data) VALUES('%s', '%s', %d, %d, '%s')", 'placeholder-for-uid-1', 'placeholder-for-uid-1', REQUEST_TIME, 1, serialize(array()));
+  db_insert('users')
+    ->fields(array(
+      'name' => 'placeholder-for-uid-1',
+      'mail' => 'placeholder-for-uid-1',
+      'created' => REQUEST_TIME,
+      'status' => 1,
+      'data' => serialize(array())
+    ))
+    ->execute();
   // This sets the above two users uid 0 (anonymous). We avoid an explicit 0
   // otherwise MySQL might insert the next auto_increment value.
-  db_query("UPDATE {users} SET uid = uid - uid WHERE name = '%s'", '');
+  db_update('users')
+    ->expression('uid', 'uid - uid')
+    ->condition('name', '')
+    ->execute();
   // This sets uid 1 (superuser). We skip uid 2 but that's not a big problem.
-  db_query("UPDATE {users} SET uid = 1 WHERE name = '%s'", 'placeholder-for-uid-1');
+  db_update('users')
+    ->fields(array('uid' => 1))
+    ->condition('name', 'placeholder-for-uid-1')
+    ->execute();
 
   // Built-in roles.
-  db_query("INSERT INTO {role} (name) VALUES ('%s')", 'anonymous user');
-  db_query("INSERT INTO {role} (name) VALUES ('%s')", 'authenticated user');
+  db_insert('role')
+    ->fields(array('name'))
+    ->values(array('name' => 'anonymous user'))
+    ->values(array('name' => 'authenticated user'))
+    ->execute();
 
+  $query = db_insert('role_permission')->fields(array('rid', 'permission'));
   // Anonymous role permissions.
-  db_query("INSERT INTO {role_permission} (rid, permission) VALUES (%d, '%s')", 1, 'access content');
+  $query->values(array(
+    'rid' => 1,
+    'permission' => 'access content'
+  ));
 
   // Authenticated role permissions.
-  db_query("INSERT INTO {role_permission} (rid, permission) VALUES (%d, '%s')", 2, 'access comments');
-  db_query("INSERT INTO {role_permission} (rid, permission) VALUES (%d, '%s')", 2, 'access content');
-  db_query("INSERT INTO {role_permission} (rid, permission) VALUES (%d, '%s')", 2, 'post comments');
-  db_query("INSERT INTO {role_permission} (rid, permission) VALUES (%d, '%s')", 2, 'post comments without approval');
+  foreach (array('access comments', 'access content', 'post comments', 'post comments without approval') as $permission) {
+    $query->values(array(
+      'rid' => 2,
+      'permission' => $permission,
+    ));
+  }
+  $query->execute();
 
-  db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", 'theme_default', 's:7:"garland";');
-  db_query("UPDATE {system} SET status = %d WHERE type = '%s' AND name = '%s'", 1, 'theme', 'garland');
+  db_insert('variable')
+    ->fields(array('name', 'value'))
+    ->values(array(
+      'name' => 'theme_default',
+      'value' => serialize('garland'),
+    ))
+    ->values(array(
+      'name' => 'filter_html_1',
+      'value' => serialize(1),
+    ))
+    ->values(array(
+      'name' => 'cron_key',
+      'value' => serialize(md5(mt_rand())),
+    ))
+    ->execute();
+
+  db_update('system')
+    ->fields(array('status' => 1))
+    ->condition('type', 'theme')
+    ->condition('name', 'garland')
+    ->execute();
 
-  db_query("INSERT INTO {node_access} (nid, gid, realm, grant_view, grant_update, grant_delete) VALUES (%d, %d, '%s', %d, %d, %d)", 0, 0, 'all', 1, 0, 0);
+  db_insert('node_access')
+    ->fields(array(
+      'nid' => 0,
+      'gid' => 0,
+      'realm' => 'all',
+      'grant_view' => 1,
+      'grant_update' => 0,
+      'grant_delete' => 0,
+    ))
+    ->execute();
 
   // Add text formats.
-  db_query("INSERT INTO {filter_format} (name, roles, cache) VALUES ('%s', '%s', %d)", 'Filtered HTML', ',1,2,', 1);
-  db_query("INSERT INTO {filter_format} (name, roles, cache) VALUES ('%s', '%s', %d)", 'Full HTML', '', 1);
+  db_insert('filter_format')
+    ->fields(array('name', 'roles', 'cache'))
+    ->values(array(
+      'name' => 'Filtered HTML',
+      'roles' => ',1,2,',
+      'cache' => 1
+    ))
+    ->values(array(
+      'name' => 'Full HTML',
+      'roles' => '',
+      'cache' => 1
+    ))
+    ->execute();
 
   // Enable filters for each text format.
+  $query = db_insert('filter')->fields(array('format', 'module', 'delta', 'weight'));
 
   // Filtered HTML:
   // URL filter.
-  db_query("INSERT INTO {filter} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", 1, 'filter', 2, 0);
+  $query->values(array(
+    'format' => 1,
+    'module' => 'filter',
+    'delta' => 2,
+    'weight' => 0,
+  ));
   // HTML filter.
-  db_query("INSERT INTO {filter} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", 1, 'filter', 0, 1);
+  $query->values(array(
+    'format' => 1,
+    'module' => 'filter',
+    'delta' => 0,
+    'weight' => 1,
+  ));
   // Line break filter.
-  db_query("INSERT INTO {filter} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", 1, 'filter', 1, 2);
+  $query->values(array(
+    'format' => 1,
+    'module' => 'filter',
+    'delta' => 1,
+    'weight' => 2,
+  ));
   // HTML corrector filter.
-  db_query("INSERT INTO {filter} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", 1, 'filter', 3, 10);
+  $query->values(array(
+    'format' => 1,
+    'module' => 'filter',
+    'delta' => 3,
+    'weight' => 10,
+  ));
 
   // Full HTML:
   // URL filter.
-  db_query("INSERT INTO {filter} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", 2, 'filter', 2, 0);
+  $query->values(array(
+    'format' => 2,
+    'module' => 'filter',
+    'delta' => 2,
+    'weight' => 0,
+  ));
   // Line break filter.
-  db_query("INSERT INTO {filter} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", 2, 'filter', 1, 1);
+  $query->values(array(
+    'format' => 2,
+    'module' => 'filter',
+    'delta' => 1,
+    'weight' => 1,
+  ));
   // HTML corrector filter.
-  db_query("INSERT INTO {filter} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", 2, 'filter', 3, 10);
-
-  db_query("INSERT INTO {variable} (name, value) VALUES ('%s','%s')", 'filter_html_1', 'i:1;');
-
-  db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", 'node_options_forum', 'a:1:{i:0;s:6:"status";}');
-
-  $cron_key = serialize(md5(mt_rand()));
-
-  db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", 'cron_key', $cron_key);
+  $query->values(array(
+    'format' => 2,
+    'module' => 'filter',
+    'delta' => 3,
+    'weight' => 10,
+  ));
 }
 
 /**
@@ -2891,7 +2987,7 @@ function system_update_7003() {
     ':status' => 0,
     ':type' => $type,
   ));
-  while ($blocked = db_fetch_object($result)) {
+  foreach ($result as $blocked) {
     if (filter_var($blocked->mask, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE) !== FALSE) {
       $ret[] = update_sql("INSERT INTO {blocked_ips} (ip) VALUES ('$blocked->mask')");
     }
Index: modules/trigger/trigger.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/trigger/trigger.test,v
retrieving revision 1.12
diff -u -p -r1.12 trigger.test
--- modules/trigger/trigger.test	12 Jun 2009 08:39:40 -0000	1.12
+++ modules/trigger/trigger.test	14 Jun 2009 19:27:32 -0000
@@ -60,7 +60,7 @@ class TriggerContentTestCase extends Dru
       // Test 3: The action should be able to be unassigned from a trigger.
       $this->drupalPost('admin/build/trigger/unassign/node/presave/' . $hash, array(), t('Unassign'));
       $this->assertRaw(t('Action %action has been unassigned.', array('%action' => ucfirst($info['name']))), t('Check to make sure the @action action can be unassigned from the trigger.', array('@action' => $info['name'])));
-      $assigned = db_result(db_query("SELECT COUNT(*) FROM {trigger_assignments} WHERE aid IN ('" . implode("','", $content_actions) . "')"));
+      $assigned = db_query("SELECT COUNT(*) FROM {trigger_assignments} WHERE aid IN (:keys)", array(':keys' => $content_actions))->fetchField();
       $this->assertFalse($assigned, t('Check to make sure unassign worked properly at the database level.'));
     }
   }
Index: modules/upload/upload.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/upload/upload.test,v
retrieving revision 1.19
diff -u -p -r1.19 upload.test
--- modules/upload/upload.test	21 May 2009 12:00:06 -0000	1.19
+++ modules/upload/upload.test	14 Jun 2009 19:27:35 -0000
@@ -68,7 +68,7 @@ class UploadTestCase extends DrupalWebTe
     $this->assertTrue(strpos($teaser, format_plural(2, '1 attachment', '@count attachments')), 'Attachments link found on node teaser.');
 
     // Fetch db record and use fid to rename and delete file.
-    $upload = db_fetch_object(db_query('SELECT fid, description FROM {upload} WHERE nid = %d', array($node->nid)));
+    $upload = db_query('SELECT fid, description FROM {upload} WHERE nid = :nid', array(':nid' => $node->nid))->fetchObject();
     if ($upload) {
       // Rename file.
       $edit = array();
Index: modules/user/user.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.test,v
retrieving revision 1.43
diff -u -p -r1.43 user.test
--- modules/user/user.test	13 Jun 2009 20:40:09 -0000	1.43
+++ modules/user/user.test	14 Jun 2009 19:27:39 -0000
@@ -1043,7 +1043,7 @@ class UserSaveTestCase extends DrupalWeb
    */
   function testUserImport() {
     // User ID must be a number that is not in the database.
-    $max_uid = db_result(db_query('SELECT MAX(uid) FROM {users}'));
+    $max_uid = db_query('SELECT MAX(uid) FROM {users}')->fetchField();
     $test_uid = $max_uid + mt_rand(1000, 1000000);
     $test_name = $this->randomName();
 
