Re: [PATCH] transaction support for DB::sybase

From: Date: Fri, 06 Jun 2003 09:33:07 +0000
Subject: Re: [PATCH] transaction support for DB::sybase
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-17111@lists.php.net to get a copy of this message
# neuhauser@bellavista.cz / 2003-06-06 11:31:15 +0200: > Attached is a patch that adds transaction support to the Sybase DB > driver. this time, it's actually attached. sorry for the noise! -- If you cc me or remove the list(s) completely I'll most likely ignore your message. see http://www.eyrie.org./~eagle/faqs/questions.html

Index: DB/DB/sybase.php =================================================================== RCS file: /repository/pear/DB/DB/sybase.php,v retrieving revision 1.7 diff -u -r1.7 sybase.php --- DB/DB/sybase.php 7 May 2003 16:58:28 -0000 1.7 +++ DB/DB/sybase.php 6 Jun 2003 09:17:06 -0000 @@ -33,6 +33,8 @@ var $phptype, $dbsyntax; var $prepare_tokens = array(); var $prepare_types = array(); + var $transaction_opcount = 0; + var $autocommit = true; // }}} // {{{ constructor @@ -202,8 +204,21 @@ */ function simpleQuery($query) { + $ismanip = DB::isManip($query); $this->last_query = $query; + if (!@sybase_select_db($this->_db, $this->connection)) { + return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED); + } $query = $this->modifyQuery($query); + if (!$this->autocommit && $ismanip) { + if ($this->transaction_opcount == 0) { + $result = @sybase_query('BEGIN TRANSACTION', $this->connection); + if (!$result) { + return $this->sybaseRaiseError(); + } + } + $this->transaction_opcount++; + } $result = @sybase_query($query, $this->connection); if (!$result) { return $this->sybaseRaiseError(); @@ -218,7 +233,7 @@ } // Determine which queries that should return data, and which // should return an error code only. - return DB::isManip($query) ? DB_OK : $result; + return $ismanip ? DB_OK : $result; } // }}} @@ -402,6 +417,62 @@ return null; } return $sql; + } + + // }}} + // {{{ autoCommit() + + /** + * Enable/disable automatic commits + */ + function autoCommit($onoff = false) + { + // XXX if $this->transaction_opcount > 0, we should probably + // issue a warning here. + $this->autocommit = $onoff ? true : false; + return DB_OK; + } + + // }}} + // {{{ commit() + + /** + * Commit the current transaction. + */ + function commit() + { + if ($this->transaction_opcount > 0) { + if (!@sybase_select_db($this->_db, $this->connection)) { + return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED); + } + $result = @sybase_query('COMMIT', $this->connection); + $this->transaction_opcount = 0; + if (!$result) { + return $this->sybaseRaiseError(); + } + } + return DB_OK; + } + + // }}} + // {{{ rollback() + + /** + * Roll back (undo) the current transaction. + */ + function rollback() + { + if ($this->transaction_opcount > 0) { + if (!@sybase_select_db($this->_db, $this->connection)) { + return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED); + } + $result = @sybase_query('ROLLBACK', $this->connection); + $this->transaction_opcount = 0; + if (!$result) { + return $this->sybaseRaiseError(); + } + } + return DB_OK; } // }}}
« previous php.pear.dev (#17111) next »