From 4ca2b0306c2a0ae2dd83e492f1cd0c1b9c9e915c Mon Sep 17 00:00:00 2001 From: Marius Orcsik Date: Sat, 2 May 2009 00:08:17 +0200 Subject: [PATCH] * added the transaction stuff in the sql driver abstract and mysqli implementation --- .../models/sqldrivers/foosqldrivera.class.php | 6 +++++ _res/_libs/models/sqldrivers/mysqlim.class.php | 28 +++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/_res/_libs/models/sqldrivers/foosqldrivera.class.php b/_res/_libs/models/sqldrivers/foosqldrivera.class.php index 857e80a..c3d5bd0 100644 --- a/_res/_libs/models/sqldrivers/foosqldrivera.class.php +++ b/_res/_libs/models/sqldrivers/foosqldrivera.class.php @@ -43,6 +43,12 @@ abstract class fooSqlDriverA { public function close () {} + abstract public function startTransaction ($bAutoCommit = false); + + abstract public function rollBackTransaction (); + + abstract public function commitTransaction (); + abstract public function _SELECT($incObj); abstract public function _CREATE($sName); diff --git a/_res/_libs/models/sqldrivers/mysqlim.class.php b/_res/_libs/models/sqldrivers/mysqlim.class.php index 236279b..aa5dc55 100644 --- a/_res/_libs/models/sqldrivers/mysqlim.class.php +++ b/_res/_libs/models/sqldrivers/mysqlim.class.php @@ -74,6 +74,31 @@ class mySqlIm extends fooSqlDriverA { // $this->close(); } + public function startTransaction ($bAutoCommit = false) { + if ($this->getEngine() != 'InnoDB') + throw new tsExceptionUnimplemented ('Unable to use transactions for the current MySQL engine.'); + + $sQuery = 'SET autocommit=' . ($bAutoCommit ? 1 : 0) . ';'; + $this->query($sQuery); + $sQuery = 'START TRANSACTION;'; + return $this->query($sQuery); + } + + public function rollBackTransaction () { + if ($this->getEngine() != 'InnoDB') + throw new tsExceptionUnimplemented ('Unable to use transactions for the current MySQL engine.'); + + $sQuery = 'ROLLBACK;'; + return $this->query($sQuery); + } + + public function commitTransaction () { + if ($this->getEngine() != 'InnoDB') + throw new tsExceptionUnimplemented ('Unable to use transactions for the current MySQL engine.'); + + $sQuery = 'COMMIT;'; + return $this->query($sQuery); + } /** * wrapper for mysql_connect @@ -156,7 +181,6 @@ class mySqlIm extends fooSqlDriverA { return false; if ($this->link->errno) { -// d ($query, $this->link->errno, $this->link->error); throw new fooConnectionException ($this->link->error. nl() . $query . nl ()); return false; } @@ -166,6 +190,8 @@ class mySqlIm extends fooSqlDriverA { return $this->conn; elseif (preg_match('/insert|update|replace|delete/i', $query)) return $this->link->affected_rows; + + return true; } /** -- 2.11.4.GIT