DB::fbsql differet from the other drivers

From: Date: Fri, 06 Jun 2003 10:48:02 +0000
Subject: DB::fbsql differet from the other drivers
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-17112@lists.php.net to get a copy of this message
If you look at the autoCommit(), commit(), rollback(), and simpleQuery() methods of DB::fbsql and any other driver that implements transactions, you'll see fbsql is very different from the rest of the pack: * commit() and rollback() methods are void in fbsql, while they return (DB_OK / error object) in all the others. * autoCommit() doesn't just set a flag for the next simpleQuery() call, it actually starts a transaction * simpleQuery() doesn't contain contain the usual transaction handling the fact that autoCommit() in one driver begins a transaction right away (that's what I think it's doing anyway, there's no online documentation for FrontBase) is completely incompatible, and very dangerous. I'd love it if Frank could review this patch, test it, and eventually commit it if it brings DB::fbsql in line with the rest of PEAR::DB drivers: I don't have access to FrontBase, and could only make sure it passes lint. It's therefore quite possible that the commit() and rollback() methods need SET COMMIT TRUE as well: I couldn't discern it from the fbsql_autocommit() description in the PHP manual. Oh, one more question: wouldn't fbsql_autocommit(false) be faster than fbsql_query('SET COMMIT FALSE')? -- 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/fbsql.php =================================================================== RCS file: /repository/pear/DB/DB/fbsql.php,v retrieving revision 1.6 diff -u -r1.6 fbsql.php --- DB/DB/fbsql.php 7 May 2003 16:58:28 -0000 1.6 +++ DB/DB/fbsql.php 6 Jun 2003 10:39:34 -0000 @@ -41,6 +41,8 @@ var $prepare_types = array(); var $num_rows = array(); var $fetchmode = DB_FETCHMODE_ORDERED; /* Default fetch mode */ + var $transaction_opcount = 0; + var $autocommit = true; // }}} // {{{ constructor @@ -168,23 +170,36 @@ */ function simpleQuery($query) { + $ismanip = DB::isManip($query); $this->last_query = $query; + if (!@fbsql_select_db($this->_db, $this->connection)) { + return $this->fbsqlRaiseError(DB_ERROR_NODBSELECTED); + } $query = $this->modifyQuery($query); + if (!$this->autocommit && $ismanip) { + if ($this->transaction_opcount == 0) { + $result = @fbsql_query('SET COMMIT FALSE', $this->connection); + if (!$result) { + return $this->fbsqlRaiseError(); + } + } + $this->transaction_opcount++; + } $result = @fbsql_query("$query;", $this->connection); if (!$result) { return $this->fbsqlRaiseError(); } + if (is_resource($result)) { + $numrows = $this->numRows($result); + if (is_object($numrows)) { + return $numrows; + } + $this->num_rows[$result] = $numrows; + return $result; + } // Determine which queries that should return data, and which // should return an error code only. - if (DB::isManip($query)) { - return DB_OK; - } - $numrows = $this->numrows($result); - if (is_object($numrows)) { - return $numrows; - } - $this->num_rows[$result] = $numrows; - return $result; + return $ismanip ? DB_OK : $result; } // }}} @@ -296,11 +311,10 @@ function autoCommit($onoff=false) { - if ($onoff) { - $this->query("SET COMMIT TRUE"); - } else { - $this->query("SET COMMIT FALSE"); - } + // XXX if $this->transaction_opcount > 0, we should probably + // issue a warning here. + $this->autocommit = $onoff ? true : false; + return DB_OK; } // }}} @@ -308,7 +322,17 @@ function commit() { - fbsql_commit(); + if ($this->transaction_opcount > 0) { + if (!@fbsql_select_db($this->_db, $this->connection)) { + return $this->fbsqlRaiseError(DB_ERROR_NODBSELECTED); + } + $result = fbsql_commit($this->connection); + $this->transaction_opcount = 0; + if (!$result) { + return $this->fbsqlRaiseError(); + } + } + return DB_OK; } // }}} @@ -316,7 +340,17 @@ function rollback() { - fbsql_rollback(); + if ($this->transaction_opcount > 0) { + if (!@fbsql_select_db($this->_db, $this->connection)) { + return $this->fbsqlRaiseError(DB_ERROR_NODBSELECTED); + } + $result = fbsql_rollback($this->connection); + $this->transaction_opcount = 0; + if (!$result) { + return $this->fbsqlRaiseError(); + } + } + return DB_OK; } // }}}
« previous php.pear.dev (#17112) next »