Index: includes/database/database.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/database/database.inc,v
retrieving revision 1.81
diff -u -p -r1.81 database.inc
--- includes/database/database.inc	18 Oct 2009 06:56:24 -0000	1.81
+++ includes/database/database.inc	17 Nov 2009 07:39:08 -0000
@@ -1073,16 +1073,20 @@ abstract class DatabaseConnection extend
     // for those simple cases.
     // If another transaction wants to write the same row, it will wait until
     // this transaction commits.
-    $stmt = $this->query('UPDATE {sequences} SET value = GREATEST(value, :existing_id) + 1', array(
+    $affected = $this->query('UPDATE {sequences} SET value = GREATEST(value, :existing_id) + 1', array(
       ':existing_id' => $existing_id,
-    ));
-    if (!$stmt->rowCount()) {
-      $this->query('INSERT INTO {sequences} (value) VALUES (:existing_id + 1)', array(
-        ':existing_id' => $existing_id,
-      ));
+    ), array('return' => Database::RETURN_AFFECTED));
+    
+    if(!$affected) {
+	    $new_value = $this->query('INSERT INTO {sequences} (value) VALUES (:existing_id + 1)', array(
+	      ':existing_id' => $existing_id,
+	    ), array('return' => Database::RETURN_INSERT_ID));
     }
-    // The transaction gets committed when the transaction object gets
-    // destructed because it gets out of scope.
+    else {
+    	$stmt = $this->query('SELECT value FROM {sequences}', array(), array('return' => Database::RETURN_STATEMENT));
+    	$new_value = $stmt->fetchField();
+    }
+
     return $new_value;
   }
 }
