Index: modules/filter/filter.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.admin.inc,v
retrieving revision 1.24
diff -u -p -r1.24 filter.admin.inc
--- modules/filter/filter.admin.inc	5 Feb 2009 19:52:02 -0000	1.24
+++ modules/filter/filter.admin.inc	7 Mar 2009 20:57:48 -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.'));
@@ -181,8 +184,8 @@ function filter_admin_format_form(&$form
 function filter_admin_format_form_validate($form, &$form_state) {
   if (!isset($form_state['values']['format'])) {
     $name = trim($form_state['values']['name']);
-    $result = db_fetch_object(db_query("SELECT format FROM {filter_format} WHERE name='%s'", $name));
-    if ($result) {
+    $result = db_query("SELECT format FROM {filter_format} WHERE name = :name", array(':name' => $name))->fetchField();
+    if (!empty($result)) {
       form_set_error('name', t('Filter format names need to be unique. A format named %name already exists.', array('%name' => $name)));
     }
   }
@@ -200,21 +203,34 @@ function filter_admin_format_form_submit
   // Add a new filter format.
   if (!$format) {
     $new = TRUE;
-    db_query("INSERT INTO {filter_format} (name) VALUES ('%s')", $name);
-    $format = db_result(db_query("SELECT MAX(format) AS format FROM {filter_format}"));
+    db_insert('filter_format')
+      ->fields(array(
+        'name' => $name,
+      ))
+      ->execute();
+    $format = db_query("SELECT MAX(format) AS format FROM {filter_format}")->fetchField();
     drupal_set_message(t('Added text format %format.', array('%format' => $name)));
   }
   else {
     drupal_set_message(t('The text format settings have been updated.'));
   }
 
-  db_query("DELETE FROM {filter} WHERE format = %d", $format);
+  db_delete('filter')
+    ->condition('format', $format)
+    ->execute();
   foreach ($form_state['values']['filters'] as $id => $checked) {
     if ($checked) {
       list($module, $delta) = explode('/', $id);
       // Add new filters to the bottom.
       $weight = isset($current[$id]->weight) ? $current[$id]->weight : 10;
-      db_query("INSERT INTO {filter} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", $format, $module, $delta, $weight);
+      db_insert('filter')
+        ->fields(array(
+          'format' => $format,
+          'module' => $module,
+          'delta'  => $delta,
+          'weight' => $weight,
+        ))
+        ->execute();
 
       // Check if there are any 'no cache' filters.
       $cache &= !module_invoke($module, 'filter', 'no cache', $delta);
@@ -239,7 +255,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 +283,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))->fetch();
 
   if ($format) {
     if ($format->format != variable_get('filter_default_format', 1)) {
@@ -283,14 +306,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 +444,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	7 Mar 2009 20:57:48 -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.240
diff -u -p -r1.240 filter.module
--- modules/filter/filter.module	21 Jan 2009 16:58:42 -0000	1.240
+++ modules/filter/filter.module	7 Mar 2009 20:57:49 -0000
@@ -361,7 +361,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];
 }
@@ -374,8 +374,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];
@@ -560,7 +560,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))->fetch());
   }
 
   $tips = array();
Index: modules/filter/filter.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.test,v
retrieving revision 1.14
diff -u -p -r1.14 filter.test
--- modules/filter/filter.test	26 Jan 2009 14:08:43 -0000	1.14
+++ modules/filter/filter.test	7 Mar 2009 20:57:49 -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}')->fetch();
     $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))->fetch();
   }
 }
 
@@ -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']))->fetch();
   }
 
   function deleteFormat($format) {
