From ed9c29fe4993a14c564981cd3a034c0e159d81fe Mon Sep 17 00:00:00 2001 From: Sergey Tsalkov Date: Tue, 18 Sep 2012 21:08:28 -0700 Subject: [PATCH] add DB::transactionDepth() for checking how many transactions are active when not using nested transactions, will return 1 or 0 --- db.class.php | 3 +++ simpletest/TransactionTest_55.php | 1 + 2 files changed, 4 insertions(+) diff --git a/db.class.php b/db.class.php index 929dd5b..18cecea 100644 --- a/db.class.php +++ b/db.class.php @@ -98,6 +98,8 @@ class DB { public static function nonSQLError() { $args = func_get_args(); return call_user_func_array(array(DB::getMDB(), 'nonSQLError'), $args); } public static function serverVersion() { $args = func_get_args(); return call_user_func_array(array(DB::getMDB(), 'serverVersion'), $args); } + public static function transactionDepth() { $args = func_get_args(); return call_user_func_array(array(DB::getMDB(), 'transactionDepth'), $args); } + public static function debugMode($handler = true) { DB::$success_handler = $handler; @@ -194,6 +196,7 @@ class MeekroDB { } public function serverVersion() { return $this->server_info; } + public function transactionDepth() { return $this->nested_transactions_count; } public function insertId() { return $this->insert_id; } public function affectedRows() { return $this->affected_rows; } public function count() { $args = func_get_args(); return call_user_func_array(array($this, 'numRows'), $args); } diff --git a/simpletest/TransactionTest_55.php b/simpletest/TransactionTest_55.php index d868399..beebb47 100644 --- a/simpletest/TransactionTest_55.php +++ b/simpletest/TransactionTest_55.php @@ -13,6 +13,7 @@ class TransactionTest_55 extends SimpleTest { $depth = DB::startTransaction(); $this->assert($depth === 3); + $this->assert(DB::transactionDepth() === 3); DB::query("UPDATE accounts SET age=%i WHERE username=%s", 500, 'Abe'); $depth = DB::commit();