Index: database.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/database.inc,v
retrieving revision 1.69
diff -u -p -r1.69 database.inc
--- database.inc	25 May 2007 12:46:43 -0000	1.69
+++ database.inc	25 May 2007 22:34:07 -0000
@@ -43,6 +43,49 @@
  * common pattern of iterating over the result set using db_fetch_object().
  */
 
+class db_transaction {
+  function __construct()
+  {
+    global $db_transaction_layers, $db_transaction_allow_commit;
+    if (!isset($db_transaction_layers)) {
+      $db_transaction_layers = 0;
+    }
+    if (!isset($db_transaction_allow_commit)) {
+      $db_transaction_allow_commit = TRUE;
+    }
+    if ($db_transaction_layers == 0)
+      db_query('BEGIN');
+    $db_transaction_layers++;
+  }
+
+  function __destruct()
+  {
+    global $db_transaction_layers, $db_transaction_allow_commit;
+    $db_transaction_layers--;     
+    if ($db_transaction_layers == 0) {
+      if ($db_transaction_allow_commit) {
+        db_query('COMMIT');
+      } else {
+        db_query('ROLLBACK');
+      }
+      // Reset the ROLLBACK propagator
+      $db_transaction_allow_commit = TRUE;
+    }
+  }
+  
+  function rollback()
+  {
+    global $db_transaction_allow_commit;
+    $db_transaction_allow_commit = FALSE;
+  }
+  
+  function will_rollback()
+  {
+    global $db_transaction_allow_commit;
+    return $db_transaction_allow_commit;
+  }
+}
+
 /**
  * Perform an SQL query and return success or failure.
  *
