Index: modules/filter/filter.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.admin.inc,v
retrieving revision 1.25
diff -u -p -r1.25 filter.admin.inc
--- modules/filter/filter.admin.inc	8 Mar 2009 21:25:18 -0000	1.25
+++ modules/filter/filter.admin.inc	9 Mar 2009 18:37:59 -0000
@@ -50,7 +50,10 @@ function filter_admin_overview_submit($f
   foreach ($form_state['values'] as $id => $data) {
     if (is_array($data) && isset($data['weight'])) {
       // Only update if this is a form element with weight.
-      db_query("UPDATE {filter_format} SET weight = %d WHERE format = %d", $data['weight'], $id);
+      db_update('filter_format')
+        ->fields(array('weight' => $data['weight']))
+        ->condition('format', $id)
+        ->execute();
     }
   }
   drupal_set_message(t('The text format ordering has been saved.'));
@@ -239,7 +242,14 @@ function filter_admin_format_form_submit
     $roles = ',' . implode(',', $roles) . ',';
   }
 
-  db_query("UPDATE {filter_format} SET cache = %d, name='%s', roles = '%s' WHERE format = %d", $cache, $name, $roles, $format);
+  db_update('filter_format')
+    ->fields(array(
+      'cache' => $cache,
+      'name'  => $name,
+      'roles' => $roles,
+    ))
+    ->condition('format', $format)
+    ->execute();
 
   cache_clear_all($format . ':', 'cache_filter', TRUE);
 
@@ -260,7 +270,7 @@ function filter_admin_format_form_submit
  */
 function filter_admin_delete() {
   $format = arg(4);
-  $format = db_fetch_object(db_query('SELECT * FROM {filter_format} WHERE format = %d', $format));
+  $format = db_query('SELECT * FROM {filter_format} WHERE format = :format', array(':format' => $format))->fetchObject();
 
   if ($format) {
     if ($format->format != variable_get('filter_default_format', 1)) {
@@ -283,14 +293,31 @@ function filter_admin_delete() {
  * Process filter delete form submission.
  */
 function filter_admin_delete_submit($form, &$form_state) {
-  db_query("DELETE FROM {filter_format} WHERE format = %d", $form_state['values']['format']);
-  db_query("DELETE FROM {filter} WHERE format = %d", $form_state['values']['format']);
+  db_delete('filter_format')
+    ->condition('format', $form_state['values']['format'])
+    ->execute();
+  db_delete('filter')
+    ->condition('format', $form_state['values']['format'])
+    ->execute();
 
   $default = variable_get('filter_default_format', 1);
   // Replace existing instances of the deleted format with the default format.
-  db_query("UPDATE {node_revision} SET format = %d WHERE format = %d", $default, $form_state['values']['format']);
-  db_query("UPDATE {comment} SET format = %d WHERE format = %d", $default, $form_state['values']['format']);
-  db_query("UPDATE {box} SET format = %d WHERE format = %d", $default, $form_state['values']['format']);
+  db_update('node_revision')
+    ->fields(array('format' => $default))
+    ->condition('format', $form_state['values']['format'])
+    ->execute();
+  if (db_table_exists('comment')) {
+    db_update('comment')
+      ->fields(array('format' => $default))
+      ->condition('format', $form_state['values']['format'])
+      ->execute();
+  }
+  if (db_table_exists('box')) {
+    db_update('box')
+      ->fields(array('format' => $default))
+      ->condition('format', $form_state['values']['format'])
+      ->execute();
+  }
 
   cache_clear_all($form_state['values']['format'] . ':', 'cache_filter', TRUE);
   drupal_set_message(t('Deleted text format %format.', array('%format' => $form_state['values']['name'])));
@@ -404,7 +431,12 @@ function theme_filter_admin_order($form)
 function filter_admin_order_submit($form, &$form_state) {
   foreach ($form_state['values']['weights'] as $id => $weight) {
     list($module, $delta) = explode('/', $id);
-    db_query("UPDATE {filter} SET weight = %d WHERE format = %d AND module = '%s' AND delta = %d", $weight, $form_state['values']['format'], $module, $delta);
+    db_update('filter')
+      ->fields(array('weight' => $weight))
+      ->condition('format', $form_state['values']['format'])
+      ->condition('module', $module)
+      ->condition('delta', $delta)
+      ->execute();
   }
   drupal_set_message(t('The filter ordering has been saved.'));
 
Index: modules/filter/filter.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.install,v
retrieving revision 1.12
diff -u -p -r1.12 filter.install
--- modules/filter/filter.install	21 Jan 2009 16:58:42 -0000	1.12
+++ modules/filter/filter.install	9 Mar 2009 18:37:59 -0000
@@ -113,7 +113,7 @@ function filter_update_7000() {
 function filter_update_7001() {
   $ret = array();
   $result = db_query("SELECT format FROM {filter_formats}");
-  while ($format = db_fetch_object($result)) {
+  foreach ($result as $format) {
     // Deprecated constants FILTER_HTML_STRIP = 1 and FILTER_HTML_ESCAPE = 2.
     if (variable_get('filter_html_' . $format->format, 1) == 2) {
       $ret[] = update_sql("INSERT INTO {filters} (format, module, delta, weight) VALUES (" . $format->format . ", 'filter', 4, 0)");
Index: modules/filter/filter.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.module,v
retrieving revision 1.243
diff -u -p -r1.243 filter.module
--- modules/filter/filter.module	8 Mar 2009 21:25:18 -0000	1.243
+++ modules/filter/filter.module	9 Mar 2009 18:37:59 -0000
@@ -364,7 +364,7 @@ function filter_format_allowcache($forma
   static $cache = array();
   $format = filter_resolve_format($format);
   if (!isset($cache[$format])) {
-    $cache[$format] = db_result(db_query('SELECT cache FROM {filter_format} WHERE format = %d', $format));
+    $cache[$format] = db_query('SELECT cache FROM {filter_format} WHERE format = :format', array(':format' => $format))->fetchField();
   }
   return $cache[$format];
 }
@@ -377,8 +377,8 @@ function filter_list_format($format) {
 
   if (!isset($filters[$format])) {
     $filters[$format] = array();
-    $result = db_query("SELECT * FROM {filter} WHERE format = %d ORDER BY weight, module, delta", $format);
-    while ($filter = db_fetch_object($result)) {
+    $result = db_query("SELECT * FROM {filter} WHERE format = :format ORDER BY weight, module, delta", array(':format' => $format));
+    foreach ($result as $filter) {
       $list = module_invoke($filter->module, 'filter', 'list');
       if (isset($list) && is_array($list) && isset($list[$filter->delta])) {
         $filter->name = $list[$filter->delta];
@@ -548,7 +548,7 @@ function _filter_tips($format, $long = F
     $formats = filter_formats();
   }
   else {
-    $formats = array(db_fetch_object(db_query("SELECT * FROM {filter_format} WHERE format = %d", $format)));
+    $formats = array(db_query("SELECT * FROM {filter_format} WHERE format = :format", array(':format' => $format))->fetchObject());
   }
 
   $tips = array();
Index: modules/filter/filter.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.test,v
retrieving revision 1.15
diff -u -p -r1.15 filter.test
--- modules/filter/filter.test	8 Mar 2009 01:43:57 -0000	1.15
+++ modules/filter/filter.test	9 Mar 2009 18:37:59 -0000
@@ -41,7 +41,7 @@ class FilterAdminTestCase extends Drupal
 
     $this->assertRaw(htmlentities($edit['allowed_html_1']), t('Tag displayed.'));
 
-    $result = db_fetch_object(db_query('SELECT * FROM {cache_filter}'));
+    $result = db_query('SELECT * FROM {cache_filter}')->fetchObject();
     $this->assertFalse($result, t('Cache cleared.'));
 
     // Reorder filters.
@@ -51,9 +51,9 @@ class FilterAdminTestCase extends Drupal
     $this->drupalPost('admin/settings/filter/' . $filtered . '/order', $edit, t('Save configuration'));
     $this->assertText(t('The filter ordering has been saved.'), t('Order saved successfully.'));
 
-    $result = db_query('SELECT * FROM {filter} WHERE format = %d ORDER BY weight ASC', $filtered);
+    $result = db_query('SELECT * FROM {filter} WHERE format = :format ORDER BY weight ASC', array(':format' => $filtered));
     $filters = array();
-    while ($filter = db_fetch_object($result)) {
+    foreach ($result as $filter) {
       if ($filter->delta == $second_filter || $filter->delta == $first_filter) {
         $filters[] = $filter;
       }
@@ -155,7 +155,7 @@ class FilterAdminTestCase extends Drupal
 
     $filtered = -1;
     $full = -1;
-    while ($format = db_fetch_object($result)) {
+    foreach ($result as $format) {
       if ($format->name == 'Filtered HTML') {
         $filtered = $format->format;
       }
@@ -174,7 +174,7 @@ class FilterAdminTestCase extends Drupal
    * @return object Filter object.
    */
   function getFilter($name) {
-    return db_fetch_object(db_query("SELECT * FROM {filter_format} WHERE name = '%s'", $name));
+    return db_query("SELECT * FROM {filter_format} WHERE name = :name", array(':name' => $name))->fetchObject();
   }
 }
 
@@ -224,7 +224,7 @@ class FilterTestCase extends DrupalWebTe
       'filters[filter/' . $filter . ']' => TRUE,
     );
     $this->drupalPost('admin/settings/filter/add', $edit, t('Save configuration'));
-    return db_fetch_object(db_query("SELECT * FROM {filter_format} WHERE name = '%s'", $edit['name']));
+    return db_query("SELECT * FROM {filter_format} WHERE name = :name", array(':name' => $edit['name']))->fetchObject();
   }
 
   function deleteFormat($format) {
