cox Mon Jun 30 05:44:05 2003 EDT
Modified files:
/pear/DB package.xml
/pear/DB/DB ifx.php
Log:
Added transaction capability to the ifx driver
(thanks to James Kaufman <jmk@no-spam>)
Index: pear/DB/package.xml
diff -u pear/DB/package.xml:1.21 pear/DB/package.xml:1.22
--- pear/DB/package.xml:1.21 Sun Jun 22 21:04:56 2003
+++ pear/DB/package.xml Mon Jun 30 05:44:05 2003
@@no-spam -41,14 +41,15 @@no-spam
</maintainer>
</maintainers>
<release>
- <version>1.5.0RC1</version>
+ <version>1.5.0RC2</version>
<state>stable</state>
- <date>2003-06-23</date>
+ <date>xxxx-xx-xx</date>
<notes>
New Features:
- Added $dbh->freePrepared(), for explicitily free a prepared result
- Test suite enhanced
- Added new *experimental* driver for SQLite
+- Added transaction capability to the ifx driver
Bugs fixed:
- Fixed memory leaks with methods that did automatic prepare/execute
Index: pear/DB/DB/ifx.php
diff -u pear/DB/DB/ifx.php:1.10 pear/DB/DB/ifx.php:1.11
--- pear/DB/DB/ifx.php:1.10 Tue Jun 10 16:16:39 2003
+++ pear/DB/DB/ifx.php Mon Jun 30 05:44:05 2003
@@no-spam -16,7 +16,7 @@no-spam
// | Author: Tomas V.V.Cox <cox@no-spam> |
// +----------------------------------------------------------------------+
//
-// $Id: ifx.php,v 1.10 2003/06/10 20:16:39 cox Exp $
+// $Id: ifx.php,v 1.11 2003/06/30 09:44:05 cox Exp $
//
// Database independent query interface definition for PHP's Informix
// extension.
@@no-spam -39,6 +39,8 @@no-spam
var $connection;
var $affected = 0;
var $dsn = array();
+ var $transaction_opcount = 0;
+ var $autocommit = true;
var $fetchmode = DB_FETCHMODE_ORDERED; /* Default fetch mode */
// }}}
@@no-spam -127,12 +129,22 @@no-spam
*/
function simpleQuery($query)
{
+ $ismanip = DB::isManip($query);
$this->last_query = $query;
if (preg_match('/(SELECT)/i', $query)) { //TESTME: Use !DB::isManip()?
// the scroll is needed for fetching absolute row numbers
// in a select query result
$result = @no-spam $this->connection, IFX_SCROLL);
} else {
+ if (!$this->autocommit && $ismanip) {
+ if ($this->transaction_opcount == 0) {
+ $result = @no-spam WORK', $this->connection);
+ if (!$result) {
+ return $this->ifxraiseError();
+ }
+ }
+ $this->transaction_opcount++;
+ }
$result = @no-spam $this->connection);
}
if (!$result) {
@@no-spam -144,7 +156,7 @@no-spam
if (preg_match('/(SELECT)/i', $query)) {
return $result;
}
- // Result has to be freeed even with a insert or update
+ // Result has to be freed even with a insert or update
ifx_free_result($result);
return DB_OK;
@@no-spam -261,6 +273,56 @@no-spam
unset($this->prepare_tokens[(int)$result]);
unset($this->prepare_types[(int)$result]);
return true;
+ }
+
+ // }}}
+ // {{{ autoCommit()
+
+ /**
+ * Enable/disable automatic commits
+ */
+ function autoCommit($onoff = true)
+ {
+ // 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) {
+ $result = @no-spam WORK', $this->connection);
+ $this->transaction_opcount = 0;
+ if (!$result) {
+ return $this->ifxRaiseError();
+ }
+ }
+ return DB_OK;
+ }
+
+ // }}}
+ // {{{ rollback()
+
+ /**
+ * Roll back (undo) the current transaction.
+ */
+ function rollback()
+ {
+ if ($this->transaction_opcount > 0) {
+ $result = @no-spam WORK', $this->connection);
+ $this->transaction_opcount = 0;
+ if (!$result) {
+ return $this->ifxRaiseError();
+ }
+ }
+ return DB_OK;
}
// }}}