From af4cfa71c0603706aff045027794bb507314023f Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sun, 18 Jun 2006 12:30:57 +0000 Subject: [PATCH] Changed transaction semantics: made begin() and commit() work all the time and not be broken and counterintuitive. Also fixed a minor bug in ResultWrapper. --- includes/Database.php | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/includes/Database.php b/includes/Database.php index 33aaee1720..9bb92e0984 100644 --- a/includes/Database.php +++ b/includes/Database.php @@ -577,7 +577,9 @@ class Database { } # If DBO_TRX is set, start a transaction - if ( ( $this->mFlags & DBO_TRX ) && !$this->trxLevel() && $sql != 'BEGIN' ) { + if ( ( $this->mFlags & DBO_TRX ) && !$this->trxLevel() && + $sql != 'BEGIN' && $sql != 'COMMIT' && $sql != 'ROLLBACK' + ) { $this->begin(); } @@ -1699,26 +1701,19 @@ class Database { } /** - * Begin a transaction, or if a transaction has already started, continue it + * Begin a transaction, committing any previously open transaction */ function begin( $fname = 'Database::begin' ) { - if ( !$this->mTrxLevel ) { - $this->immediateBegin( $fname ); - } else { - $this->mTrxLevel++; - } + $this->query( 'BEGIN', $fname ); + $this->mTrxLevel = 1; } /** - * End a transaction, or decrement the nest level if transactions are nested + * End a transaction */ function commit( $fname = 'Database::commit' ) { - if ( $this->mTrxLevel ) { - $this->mTrxLevel--; - } - if ( !$this->mTrxLevel ) { - $this->immediateCommit( $fname ); - } + $this->query( 'COMMIT', $fname ); + $this->mTrxLevel = 0; } /** @@ -1731,18 +1726,18 @@ class Database { /** * Begin a transaction, committing any previously open transaction + * @deprecated use begin() */ function immediateBegin( $fname = 'Database::immediateBegin' ) { - $this->query( 'BEGIN', $fname ); - $this->mTrxLevel = 1; + $this->begin(); } /** * Commit transaction, if one is open + * @deprecated use commit() */ function immediateCommit( $fname = 'Database::immediateCommit' ) { - $this->query( 'COMMIT', $fname ); - $this->mTrxLevel = 0; + $this->commit(); } /** @@ -1994,7 +1989,7 @@ class ResultWrapper { /** * @todo document */ - function &fetchRow() { + function fetchRow() { return $this->db->fetchRow( $this->result ); } -- 2.20.1