add DB::transactionDepth() for checking how many transactions are active

when not using nested transactions, will return 1 or 0
This commit is contained in:
Sergey Tsalkov
2012-09-18 21:08:28 -07:00
parent 9a41bf34a1
commit ed9c29fe49
2 changed files with 4 additions and 0 deletions

View File

@@ -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 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 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) { public static function debugMode($handler = true) {
DB::$success_handler = $handler; DB::$success_handler = $handler;
@@ -194,6 +196,7 @@ class MeekroDB {
} }
public function serverVersion() { return $this->server_info; } public function serverVersion() { return $this->server_info; }
public function transactionDepth() { return $this->nested_transactions_count; }
public function insertId() { return $this->insert_id; } public function insertId() { return $this->insert_id; }
public function affectedRows() { return $this->affected_rows; } public function affectedRows() { return $this->affected_rows; }
public function count() { $args = func_get_args(); return call_user_func_array(array($this, 'numRows'), $args); } public function count() { $args = func_get_args(); return call_user_func_array(array($this, 'numRows'), $args); }

View File

@@ -13,6 +13,7 @@ class TransactionTest_55 extends SimpleTest {
$depth = DB::startTransaction(); $depth = DB::startTransaction();
$this->assert($depth === 3); $this->assert($depth === 3);
$this->assert(DB::transactionDepth() === 3);
DB::query("UPDATE accounts SET age=%i WHERE username=%s", 500, 'Abe'); DB::query("UPDATE accounts SET age=%i WHERE username=%s", 500, 'Abe');
$depth = DB::commit(); $depth = DB::commit();