cvs: pear /MDB2 MDB2.php
| From: | Lukas Smith | Date: | Sun, 18 Jun 2006 13:51:59 +0000 |
| Subject: | cvs: pear /MDB2 MDB2.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-40798@lists.php.net to get a copy of this message | ||
lsmith Sun Jun 18 13:51:59 2006 UTC
Modified files:
/pear/MDB2 MDB2.php
Log:
- turned in_transaction into an integer
- added nested transaction support (inspired by ADODB's smart transactions)
http://cvs.php.net/viewcvs.cgi/pear/MDB2/MDB2.php?r1=1.218&r2=1.219&diff_format=u
Index: pear/MDB2/MDB2.php
diff -u pear/MDB2/MDB2.php:1.218 pear/MDB2/MDB2.php:1.219
--- pear/MDB2/MDB2.php:1.218 Sat Jun 17 22:30:04 2006
+++ pear/MDB2/MDB2.php Sun Jun 18 13:51:59 2006
@@ -43,7 +43,7 @@
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
-// $Id: MDB2.php,v 1.218 2006/06/17 22:30:04 lsmith Exp $
+// $Id: MDB2.php,v 1.219 2006/06/18 13:51:59 lsmith Exp $
//
/**
@@ -1158,11 +1158,19 @@
var $debug_output = '';
/**
- * determine if there is an open transaction
- * @var bool
+ * determine if there is an open transaction and what the smart transaction
+ * nesting depth is
+ * @var integer
* @access protected
*/
- var $in_transaction = false;
+ var $in_transaction = 0;
+
+ /**
+ * the first error that occured inside a nested transaction
+ * @var MDB2_Error|bool
+ * @access protected
+ */
+ var $has_transaction_error = false;
/**
* result offset used in the next query
@@ -1373,6 +1381,9 @@
}
$err =& PEAR::raiseError(null, $code, $mode, $options, $userinfo,
'MDB2_Error', true);
+ if (isset($this->in_transaction) && $this->in_transaction &&
!$this->has_transaction_error) {
+ $this->has_transaction_error =& $err;
+ }
return $err;
}
// }}}
@@ -1877,7 +1888,7 @@
/**
* If a transaction is currently open.
*
- * @return bool true if a transaction is currently open, else false
+ * @return int 1+ depending on the smart transaction nesting depth, else 0
*
* @access public
*/
@@ -1887,6 +1898,83 @@
}
// }}}
+ // {{{ function beginNestedTransaction()
+
+ /**
+ * Start a nested transaction.
+ *
+ * @return mixed MDB2_OK on success, a MDB2 error on failure
+ *
+ * @access public
+ */
+ function beginNestedTransaction()
+ {
+ if ($this->in_transaction) {
+ ++$this->in_transaction;
+ return MDB2_OK;
+ }
+ $this->has_transaction_error = false;
+ return $this->beginTransaction();
+ }
+ // }}}
+
+ // {{{ function completeNestedTransaction()
+
+ /**
+ * Finish a nested transaction by rolling back if an error occured or
+ * commiting otherwise.
+ *
+ * @return mixed MDB2_OK on success, a MDB2 error on failure
+ *
+ * @access public
+ */
+ function completeNestedTransaction()
+ {
+ if ($this->in_transaction > 1) {
+ --$this->in_transaction;
+ return MDB2_OK;
+ }
+ if ($this->has_transaction_error) {
+ return $this->rollback();
+ }
+ return $this->commit();
+ }
+ // }}}
+
+ // {{{ function failNestedTransactionError()
+
+ /**
+ * Force setting nested transaction to failed.
+ *
+ * @return bool MDB2_OK
+ *
+ * @access public
+ */
+ function failNestedTransactionError($error = null)
+ {
+ if (is_null($error)) {
+ $error = $this->has_transaction_error ? $this->has_transaction_error : true;
+ }
+ $this->has_transaction_error = $error;
+ return MDB2_OK;
+ }
+ // }}}
+
+ // {{{ function getNestedTransactionError()
+
+ /**
+ * The first error that occured since the transaction start.
+ *
+ * @return MDB2_Error|bool MDB2 error object if an error occured or false.
+ *
+ * @access public
+ */
+ function getNestedTransactionError()
+ {
+ return $this->has_transaction_error;
+ }
+ // }}}
+
// {{{ connect()
/**
@@ -1938,7 +2026,7 @@
$this->connected_database_name = '';
$this->opened_persistent = null;
$this->connected_server_info = '';
- $this->in_transaction = false;
+ $this->in_transaction = 0;
return MDB2_OK;
}
// }}}