? dblog_dbtng-3.patch
Index: modules/dblog/dblog.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/dblog/dblog.admin.inc,v
retrieving revision 1.13
diff -u -p -r1.13 dblog.admin.inc
--- modules/dblog/dblog.admin.inc	26 Feb 2009 07:30:26 -0000	1.13
+++ modules/dblog/dblog.admin.inc	7 Mar 2009 19:45:19 -0000
@@ -72,7 +72,7 @@ function dblog_overview() {
     $result = pager_query($sql . $tablesort, 50);
   }
 
-  while ($dblog = db_fetch_object($result)) {
+  foreach ($result as $dblog) {
     $rows[] = array('data' =>
       array(
         // Cells
@@ -112,7 +112,7 @@ function dblog_top($type) {
   $result = pager_query("SELECT COUNT(wid) AS count, message, variables FROM {watchdog} WHERE type = '%s' GROUP BY message, variables " . tablesort_sql($header), 30, 0, "SELECT COUNT(DISTINCT(message)) FROM {watchdog} WHERE type = '%s'", $type);
 
   $rows = array();
-  while ($dblog = db_fetch_object($result)) {
+  foreach ($result as $dblog) {
     $rows[] = array($dblog->count, truncate_utf8(_dblog_format_message($dblog), 56, TRUE, TRUE));
   }
 
@@ -132,8 +132,8 @@ function dblog_top($type) {
 function dblog_event($id) {
   $severity = watchdog_severity_levels();
   $output = '';
-  $result = db_query('SELECT w.*, u.name, u.uid FROM {watchdog} w INNER JOIN {users} u ON w.uid = u.uid WHERE w.wid = %d', $id);
-  if ($dblog = db_fetch_object($result)) {
+  $result = db_query('SELECT w.*, u.name, u.uid FROM {watchdog} w INNER JOIN {users} u ON w.uid = u.uid WHERE w.wid = :id', array(':id' => $id))->fetchObject();
+  if ($dblog = $result) {
     $rows = array(
       array(
         array('data' => t('Type'), 'header' => TRUE),
Index: modules/dblog/dblog.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/dblog/dblog.module,v
retrieving revision 1.35
diff -u -p -r1.35 dblog.module
--- modules/dblog/dblog.module	25 Jan 2009 12:19:31 -0000	1.35
+++ modules/dblog/dblog.module	7 Mar 2009 19:45:19 -0000
@@ -97,8 +97,10 @@ function dblog_init() {
  */
 function dblog_cron() {
   // Cleanup the watchdog table
-  $max = db_result(db_query('SELECT MAX(wid) FROM {watchdog}'));
-  db_query('DELETE FROM {watchdog} WHERE wid <= %d', $max - variable_get('dblog_row_limit', 1000));
+  $max = db_query('SELECT MAX(wid) FROM {watchdog}')->fetchField();
+  db_delete('watchdog')
+    ->condition('wid', $max - variable_get('dblog_row_limit', 1000), '<=')
+    ->execute();
 }
 
 /**
@@ -107,11 +109,16 @@ function dblog_cron() {
 function dblog_user_cancel($edit, $account, $method) {
   switch ($method) {
     case 'user_cancel_reassign':
-      db_update('watchdog')->fields(array('uid' => 0))->condition('uid', $account->uid)->execute();
+      db_update('watchdog')
+        ->fields(array('uid' => 0))
+        ->condition('uid', $account->uid)
+        ->execute();
       break;
 
     case 'user_cancel_delete':
-      db_delete('watchdog')->condition('uid', $account->uid)->execute();
+      db_delete('watchdog')
+        ->condition('uid', $account->uid)
+        ->execute();
       break;
   }
 }
@@ -120,7 +127,7 @@ function _dblog_get_message_types() {
   $types = array();
 
   $result = db_query('SELECT DISTINCT(type) FROM {watchdog} ORDER BY type');
-  while ($object = db_fetch_object($result)) {
+  foreach ($result as $object) {
     $types[] = $object->type;
   }
 
Index: modules/dblog/dblog.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/dblog/dblog.test,v
retrieving revision 1.14
diff -u -p -r1.14 dblog.test
--- modules/dblog/dblog.test	8 Jan 2009 08:42:12 -0000	1.14
+++ modules/dblog/dblog.test	7 Mar 2009 19:45:19 -0000
@@ -57,7 +57,7 @@ class DBLogTestCase extends DrupalWebTes
     $current_limit = variable_get('dblog_row_limit', 1000);
     $this->assertTrue($current_limit == $row_limit, t('[Cache] Row limit variable of @count equals row limit of @limit', array('@count' => $current_limit, '@limit' => $row_limit)));
     // Verify dblog row limit equals specified row limit.
-    $current_limit = unserialize(db_result(db_query("SELECT value FROM {variable} WHERE name = '%s'", 'dblog_row_limit')));
+    $current_limit = unserialize(db_query("SELECT value FROM {variable} WHERE name = :dblog_limit", array(':dblog_limit' => 'dblog_row_limit'))->fetchField());
     $this->assertTrue($current_limit == $row_limit, t('[Variable table] Row limit variable of @count equals row limit of @limit', array('@count' => $current_limit, '@limit' => $row_limit)));
   }
 
@@ -70,7 +70,7 @@ class DBLogTestCase extends DrupalWebTes
     // Generate additional log entries.
     $this->generateLogEntries($row_limit + 10);
     // Verify dblog row count exceeds row limit.
-    $count = db_result(db_query('SELECT COUNT(wid) FROM {watchdog}'));
+    $count = db_query('SELECT COUNT(wid) FROM {watchdog}')->fetchField();
     $this->assertTrue($count > $row_limit, t('Dblog row count of @count exceeds row limit of @limit', array('@count' => $count, '@limit' => $row_limit)));
 
     // Run cron job.
@@ -78,7 +78,7 @@ class DBLogTestCase extends DrupalWebTes
     $this->assertResponse(200);
     $this->assertText(t('Cron ran successfully'), t('Cron ran successfully'));
     // Verify dblog row count equals row limit plus one because cron adds a record after it runs.
-    $count = db_result(db_query('SELECT COUNT(wid) FROM {watchdog}'));
+    $count = db_query('SELECT COUNT(wid) FROM {watchdog}')->fetchField();
     $this->assertTrue($count == $row_limit + 1, t('Dblog row count of @count equals row limit of @limit plus one', array('@count' => $count, '@limit' => $row_limit)));
   }
 
@@ -196,9 +196,9 @@ class DBLogTestCase extends DrupalWebTes
     // Logout user.
     $this->drupalLogout();
     // Fetch row ids in watchdog that relate to the user.
-    $result = db_query('SELECT wid FROM {watchdog} WHERE uid = %d', $user->uid);
-    while ($row = db_fetch_array($result)) {
-      $ids[] = $row['wid'];
+    $result = db_query('SELECT wid FROM {watchdog} WHERE uid = :uid', array(':uid' => $user->uid));
+    foreach($result as $row) {
+      $ids[] = $row->wid;
     }
     $count_before = (isset($ids)) ? count($ids) : 0;
     $this->assertTrue($count_before > 0, t('DBLog contains @count records for @name', array('@count' => $count_before, '@name' => $user->name)));
@@ -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_result(db_query('SELECT COUNT(wid) FROM {watchdog} WHERE uid = %d', $user->uid));
+    $count = db_query('SELECT COUNT(wid) FROM {watchdog} WHERE uid = %d', $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.
@@ -224,9 +224,9 @@ class DBLogTestCase extends DrupalWebTes
     $this->assertTrue($count_after == $count_before, t('DBLog contains @count records for @name that now have uid = 0', array('@count' => $count_before, '@name' => $user->name)));
     unset($ids);
     // Fetch row ids in watchdog that relate to the user.
-    $result = db_query('SELECT wid FROM {watchdog} WHERE uid = %d', $user->uid);
-    while ($row = db_fetch_array($result)) {
-      $ids[] = $row['wid'];
+    $result = db_query('SELECT wid FROM {watchdog} WHERE uid = :uid', array(':uid' => $user->uid));
+    foreach($result as $row) {
+      $ids[] = $row->wid;
     }
     $this->assertTrue(!isset($ids), t('DBLog contains no records for @name', array('@name' => $user->name)));
 
