cvs: pear /MDB2 MDB2.php
| From: | Lukas Smith | Date: | Wed, 21 Jun 2006 10:02:25 +0000 |
| Subject: | cvs: pear /MDB2 MDB2.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-40848@lists.php.net to get a copy of this message | ||
lsmith Wed Jun 21 10:02:25 2006 UTC
Modified files:
/pear/MDB2 MDB2.php
Log:
- added ability to end a nested transaction immediatly and not at the very end
http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2.php?r1=1.222&r2=1.223&diff_format=u
Index: pear/MDB2/MDB2.php
diff -u pear/MDB2/MDB2.php:1.222 pear/MDB2/MDB2.php:1.223
--- pear/MDB2/MDB2.php:1.222 Tue Jun 20 09:04:28 2006
+++ pear/MDB2/MDB2.php Wed Jun 21 10:02:25 2006
@@ -43,7 +43,7 @@
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
-// $Id: MDB2.php,v 1.222 2006/06/20 09:04:28 lsmith Exp $
+// $Id: MDB2.php,v 1.223 2006/06/21 10:02:25 lsmith Exp $
//
/**
@@ -1158,12 +1158,18 @@
var $debug_output = '';
/**
- * determine if there is an open transaction and what the smart transaction
- * nesting depth is
- * @var int|bool
+ * determine if there is an open transaction
+ * @var bool
* @access protected
*/
- var $in_transaction = 0;
+ var $in_transaction = false;
+
+ /**
+ * the smart transaction nesting depth
+ * @var int
+ * @access protected
+ */
+ var $nested_transaction_counter = null;
/**
* the first error that occured inside a nested transaction
@@ -1380,7 +1386,7 @@
}
$err =& PEAR::raiseError(null, $code, $mode, $options, $userinfo,
'MDB2_Error', true);
- if (isset($this->in_transaction) && $this->in_transaction &&
!$this->has_transaction_error) {
+ if (isset($this->nested_transaction_counter) &&
!$this->has_transaction_error) {
$this->has_transaction_error =& $err;
}
return $err;
@@ -1896,6 +1902,9 @@
*/
function inTransaction()
{
+ if (isset($this->nested_transaction_counter)) {
+ return $this->nested_transaction_counter;
+ }
return $this->in_transaction;
}
// }}}
@@ -1934,12 +1943,12 @@
function beginNestedTransaction()
{
if ($this->in_transaction) {
- $this->in_transaction+= 1;
+ $this->nested_transaction_counter+= 1;
return MDB2_OK;
}
$this->has_transaction_error = false;
$result = $this->beginTransaction();
- $this->in_transaction = 1;
+ $this->nested_transaction_counter = 1;
return $result;
}
// }}}
@@ -1956,13 +1965,17 @@
*/
function completeNestedTransaction()
{
- if ($this->in_transaction > 1) {
- $this->in_transaction-= 1;
+ if ($this->nested_transaction_counter > 1) {
+ $this->nested_transaction_counter-= 1;
return MDB2_OK;
- } elseif ($this->in_transaction <= 0) {
- return $this->raiseError(MDB2_ERROR, null, null,
- 'completeNestedTransaction: no transaction is opene to complete');
}
+ $this->nested_transaction_counter = null;
+
+ // transaction has already been rolled back
+ if (!$this->in_transaction) {
+ return MDB2_OK;
+ }
+
if ($this->has_transaction_error) {
return $this->rollback();
}
@@ -1980,7 +1993,7 @@
*
* @access public
*/
- function failNestedTransaction($error = null)
+ function failNestedTransaction($error = null, $immediatly = false)
{
if (is_null($error)) {
$error = $this->has_transaction_error ? $this->has_transaction_error : true;
@@ -1988,7 +2001,11 @@
$error = true;
}
$this->has_transaction_error = $error;
- return MDB2_OK;
+ $result = MDB2_OK;
+ if ($immediatly) {
+ $result = $this->rollback();
+ }
+ return $result;
}
// }}}
@@ -2058,7 +2075,8 @@
$this->connected_database_name = '';
$this->opened_persistent = null;
$this->connected_server_info = '';
- $this->in_transaction = false;
+ $this->in_transaction = null;
+ $this->nested_transaction_counter = 0;
return MDB2_OK;
}
// }}}