diff --git a/lib/Doctrine/Connection/Firebird.php b/lib/Doctrine/Connection/Firebird.php index 244ec3bdf..e50d18b5f 100644 --- a/lib/Doctrine/Connection/Firebird.php +++ b/lib/Doctrine/Connection/Firebird.php @@ -73,63 +73,6 @@ class Doctrine_Connection_Firebird extends Doctrine_Connection { $this->options['server_version'] = ''; parent::__construct($manager, $adapter); } - /** - * Set the transacton isolation level. - * - * @param string standard isolation level (SQL-92) - * READ UNCOMMITTED (allows dirty reads) - * READ COMMITTED (prevents dirty reads) - * REPEATABLE READ (prevents nonrepeatable reads) - * SERIALIZABLE (prevents phantom reads) - * - * @param array some transaction options: - * 'wait' => 'WAIT' | 'NO WAIT' - * 'rw' => 'READ WRITE' | 'READ ONLY' - * @return void - */ - public function setTransactionIsolation($isolation, $options = array()) { - switch ($isolation) { - case 'READ UNCOMMITTED': - $ibase_isolation = 'READ COMMITTED RECORD_VERSION'; - break; - case 'READ COMMITTED': - $ibase_isolation = 'READ COMMITTED NO RECORD_VERSION'; - break; - case 'REPEATABLE READ': - $ibase_isolation = 'SNAPSHOT'; - break; - case 'SERIALIZABLE': - $ibase_isolation = 'SNAPSHOT TABLE STABILITY'; - break; - default: - throw new Doctrine_Connection_Firebird_Exception('isolation level is not supported: ' . $isolation); - } - - if( ! empty($options['wait'])) { - switch ($options['wait']) { - case 'WAIT': - case 'NO WAIT': - $wait = $options['wait']; - break; - default: - throw new Doctrine_Connection_Firebird_Exception('wait option is not supported: ' . $options['wait']); - } - } - - if( ! empty($options['rw'])) { - switch ($options['rw']) { - case 'READ ONLY': - case 'READ WRITE': - $rw = $options['wait']; - break; - default: - throw new Doctrine_Connection_Firebird_Exception('wait option is not supported: ' . $options['rw']); - } - } - - $query = 'SET TRANSACTION ' . $rw . ' ' . $wait .' ISOLATION LEVEL ' . $ibase_isolation; - $this->dbh->query($query); - } /** * Set the charset on the current connection * diff --git a/lib/Doctrine/Connection/Mysql.php b/lib/Doctrine/Connection/Mysql.php index 41010b59b..9c219c618 100644 --- a/lib/Doctrine/Connection/Mysql.php +++ b/lib/Doctrine/Connection/Mysql.php @@ -22,15 +22,15 @@ Doctrine::autoload('Doctrine_Connection_Common'); /** * Doctrine_Connection_Mysql * - * @package Doctrine - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @author Konsta Vesterinen + * @package Doctrine + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @author Konsta Vesterinen * @author Lukas Smith (PEAR MDB2 library) - * @version $Revision$ - * @category Object Relational Mapping - * @link www.phpdoctrine.com - * @since 1.0 - */ + * @version $Revision$ + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + */ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common { /** * @var string $driverName the name of this connection driver @@ -69,47 +69,5 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common { parent::__construct($manager, $adapter); } - /** - * getTransactionIsolation - * - * @return string returns the current session transaction isolation level - */ - public function getTransactionIsolation() { - $ret = $this->dbh->query('SELECT @@tx_isolation')->fetch(PDO::FETCH_NUM); - return $ret[0]; - } - /** - * Set the transacton isolation level. - * - * example : - * - * - * $conn->setTransactionIsolation('READ UNCOMMITTED'); - * - * - * @param string standard isolation level - * READ UNCOMMITTED (allows dirty reads) - * READ COMMITTED (prevents dirty reads) - * REPEATABLE READ (prevents nonrepeatable reads) - * SERIALIZABLE (prevents phantom reads) - * - * @throws Doctrine_Connection_Mysql_Exception if using unknown isolation level - * @throws PDOException if something fails at the PDO level - * @return void - */ - public function setTransactionIsolation($isolation) { - switch ($isolation) { - case 'READ UNCOMMITTED': - case 'READ COMMITTED': - case 'REPEATABLE READ': - case 'SERIALIZABLE': - - break; - default: - throw new Doctrine_Connection_Mysql_Exception('Isolation level ' . $isolation . ' is not supported.'); - } - $query = "SET SESSION TRANSACTION ISOLATION LEVEL $isolation"; - return $this->dbh->query($query); - } } diff --git a/lib/Doctrine/Connection/Oracle.php b/lib/Doctrine/Connection/Oracle.php index 0a27f09dd..c40ce8f43 100644 --- a/lib/Doctrine/Connection/Oracle.php +++ b/lib/Doctrine/Connection/Oracle.php @@ -22,14 +22,14 @@ Doctrine::autoload('Doctrine_Connection'); /** * Doctrine_Connection_Oracle * - * @package Doctrine - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @category Object Relational Mapping - * @link www.phpdoctrine.com - * @since 1.0 - * @version $Revision$ - * @author Konsta Vesterinen - */ + * @package Doctrine + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision$ + * @author Konsta Vesterinen + */ class Doctrine_Connection_Oracle extends Doctrine_Connection { /** * @var string $driverName the name of this connection driver @@ -101,40 +101,6 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection { } return $query; } - /** - * Set the transacton isolation level. - * - * example: - * - * - * $conn->setTransactionIsolation('READ UNCOMMITTED'); - * - * - * @param string standard isolation level - * READ UNCOMMITTED (allows dirty reads) - * READ COMMITTED (prevents dirty reads) - * REPEATABLE READ (prevents nonrepeatable reads) - * SERIALIZABLE (prevents phantom reads) - * @throws PDOException if something fails at the PDO level - * @return void - */ - public function setTransactionIsolation($isolation) { - switch($isolation) { - case 'READ UNCOMMITTED': - $isolation = 'READ COMMITTED'; - break; - case 'READ COMMITTED': - case 'REPEATABLE READ': - case 'SERIALIZABLE': - $isolation = 'SERIALIZABLE'; - break; - default: - throw new Doctrine_Connection_Oracle_Exception('Isolation level ' . $isolation . ' is not supported.'); - } - - $query = 'ALTER SESSION ISOLATION LEVEL ' . $isolation; - return $this->dbh->query($query); - } /** * returns the next value in the given sequence * diff --git a/lib/Doctrine/Connection/Pgsql.php b/lib/Doctrine/Connection/Pgsql.php index 29188b785..9cba1a8dc 100644 --- a/lib/Doctrine/Connection/Pgsql.php +++ b/lib/Doctrine/Connection/Pgsql.php @@ -22,15 +22,15 @@ Doctrine::autoload("Doctrine_Connection_Common"); /** * Doctrine_Connection_Pgsql * - * @package Doctrine - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @author Konsta Vesterinen + * @package Doctrine + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @author Konsta Vesterinen * @author Lukas Smith (PEAR MDB2 library) - * @version $Revision$ - * @category Object Relational Mapping - * @link www.phpdoctrine.com - * @since 1.0 - */ + * @version $Revision$ + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + */ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common { /** * @var string $driverName the name of this connection driver @@ -109,10 +109,9 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common { * @param integer $limit limit the number of rows * @param integer $offset start reading from given offset * @param boolean $isManip if the query is a DML query - * @return string modified query */ - public function modifyLimitQuery($query, $limit=false, $offset=false, $isManip = false) { + public function modifyLimitQuery($query, $limit = false, $offset = false, $isManip = false) { if ($limit > 0) { $query = rtrim($query); @@ -128,39 +127,14 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common { . $from . ' ' . $where . ' LIMIT ' . $limit . ')'; } else { - if($limit !== false) { - $query .= ' LIMIT ' . $limit; - } - if($offset !== false) { - $query .= ' OFFSET ' . $offset; - } + if($limit !== false) { + $query .= ' LIMIT ' . $limit; + } + if($offset !== false) { + $query .= ' OFFSET ' . $offset; + } } } return $query; } - /** - * Set the transacton isolation level. - * - * @param string standard isolation level - * READ UNCOMMITTED (allows dirty reads) - * READ COMMITTED (prevents dirty reads) - * REPEATABLE READ (prevents nonrepeatable reads) - * SERIALIZABLE (prevents phantom reads) - * @return void - */ - public function setTransactionIsolation($isolation) { - switch ($isolation) { - case 'READ UNCOMMITTED': - case 'READ COMMITTED': - case 'REPEATABLE READ': - case 'SERIALIZABLE': - break; - throw new Doctrine_Connection_Pgsql_Exception('Isolation level '.$isolation.' is not supported.'); - } - - $query = 'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL ' . $isolation; - return $this->dbh->query($query); - } - } - diff --git a/lib/Doctrine/Connection/Sqlite.php b/lib/Doctrine/Connection/Sqlite.php index 4696238ad..a5ae4252f 100644 --- a/lib/Doctrine/Connection/Sqlite.php +++ b/lib/Doctrine/Connection/Sqlite.php @@ -22,15 +22,15 @@ Doctrine::autoload("Doctrine_Connection_Common"); /** * Doctrine_Connection_Sqlite * - * @package Doctrine - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @author Konsta Vesterinen + * @package Doctrine + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @author Konsta Vesterinen * @author Lukas Smith (PEAR MDB2 library) - * @version $Revision$ - * @category Object Relational Mapping - * @link www.phpdoctrine.com - * @since 1.0 - */ + * @version $Revision$ + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + */ class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common { /** * @var string $driverName the name of this connection driver @@ -82,33 +82,6 @@ class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common { $this->dbh->sqliteCreateFunction('concat', array('Doctrine_Expression_Sqlite', 'concatImpl')); $this->dbh->sqliteCreateFunction('now', 'time', 0); } - /** - * Set the transacton isolation level. - * - * @param string standard isolation level - * READ UNCOMMITTED (allows dirty reads) - * READ COMMITTED (prevents dirty reads) - * REPEATABLE READ (prevents nonrepeatable reads) - * SERIALIZABLE (prevents phantom reads) - * @return void - */ - public function setTransactionIsolation($isolation) { - switch ($isolation) { - case 'READ UNCOMMITTED': - $isolation = 0; - break; - case 'READ COMMITTED': - case 'REPEATABLE READ': - case 'SERIALIZABLE': - $isolation = 1; - break; - default: - throw new Doctrine_Connection_Sqlite_Exception('Isolation level ' . $isolation . 'is not supported.'); - } - - $query = "PRAGMA read_uncommitted=$isolation"; - return $this->_doQuery($query, true); - } /** * Returns the current id of a sequence * diff --git a/lib/Doctrine/Transaction/Firebird.php b/lib/Doctrine/Transaction/Firebird.php index aefaf19d9..c92c6f91b 100644 --- a/lib/Doctrine/Transaction/Firebird.php +++ b/lib/Doctrine/Transaction/Firebird.php @@ -67,4 +67,65 @@ class Doctrine_Transaction_Firebird extends Doctrine_Transaction { return $this->conn->getDbh()->query($query); } + /** + * Set the transacton isolation level. + * + * @param string standard isolation level (SQL-92) + * READ UNCOMMITTED (allows dirty reads) + * READ COMMITTED (prevents dirty reads) + * REPEATABLE READ (prevents nonrepeatable reads) + * SERIALIZABLE (prevents phantom reads) + * + * @param array some transaction options: + * 'wait' => 'WAIT' | 'NO WAIT' + * 'rw' => 'READ WRITE' | 'READ ONLY' + * + * @throws PDOException if something fails at the PDO level + * @throws Doctrine_Transaction_Exception if using unknown isolation level or unknown wait option + * @return void + */ + public function setTransactionIsolation($isolation, $options = array()) { + switch ($isolation) { + case 'READ UNCOMMITTED': + $nativeIsolation = 'READ COMMITTED RECORD_VERSION'; + break; + case 'READ COMMITTED': + $nativeIsolation = 'READ COMMITTED NO RECORD_VERSION'; + break; + case 'REPEATABLE READ': + $nativeIsolation = 'SNAPSHOT'; + break; + case 'SERIALIZABLE': + $nativeIsolation = 'SNAPSHOT TABLE STABILITY'; + break; + default: + throw new Doctrine_Transaction_Exception('isolation level is not supported: ' . $isolation); + } + + if( ! empty($options['wait'])) { + switch ($options['wait']) { + case 'WAIT': + case 'NO WAIT': + $wait = $options['wait']; + break; + default: + throw new Doctrine_Transaction_Exception('wait option is not supported: ' . $options['wait']); + } + } + + if( ! empty($options['rw'])) { + switch ($options['rw']) { + case 'READ ONLY': + case 'READ WRITE': + $rw = $options['wait']; + break; + default: + throw new Doctrine_Transaction_Exception('wait option is not supported: ' . $options['rw']); + } + } + + $query = 'SET TRANSACTION ' . $rw . ' ' . $wait .' ISOLATION LEVEL ' . $nativeIsolation; + + $this->conn->getDbh()->query($query); + } } diff --git a/lib/Doctrine/Transaction/Mysql.php b/lib/Doctrine/Transaction/Mysql.php index 0150f9742..daf1e7f36 100644 --- a/lib/Doctrine/Transaction/Mysql.php +++ b/lib/Doctrine/Transaction/Mysql.php @@ -67,4 +67,42 @@ class Doctrine_Transaction_Mysql extends Doctrine_Transaction { return $this->conn->getDbh()->query($query); } + /** + * Set the transacton isolation level. + * + * @param string standard isolation level + * READ UNCOMMITTED (allows dirty reads) + * READ COMMITTED (prevents dirty reads) + * REPEATABLE READ (prevents nonrepeatable reads) + * SERIALIZABLE (prevents phantom reads) + * + * @throws Doctrine_Transaction_Exception if using unknown isolation level + * @throws PDOException if something fails at the PDO level + * @return void + */ + public function setTransactionIsolation($isolation) { + switch ($isolation) { + case 'READ UNCOMMITTED': + case 'READ COMMITTED': + case 'REPEATABLE READ': + case 'SERIALIZABLE': + + break; + default: + throw new Doctrine_Transaction_Exception('Isolation level ' . $isolation . ' is not supported.'); + } + + $query = "SET SESSION TRANSACTION ISOLATION LEVEL $isolation"; + + return $this->conn->getDbh()->query($query); + } + /** + * getTransactionIsolation + * + * @return string returns the current session transaction isolation level + */ + public function getTransactionIsolation() { + $ret = $this->conn->getDbh()->query('SELECT @@tx_isolation')->fetch(PDO::FETCH_NUM); + return $ret[0]; + } } diff --git a/lib/Doctrine/Transaction/Oracle.php b/lib/Doctrine/Transaction/Oracle.php index c65c72c63..24a0d039e 100644 --- a/lib/Doctrine/Transaction/Oracle.php +++ b/lib/Doctrine/Transaction/Oracle.php @@ -66,4 +66,33 @@ class Doctrine_Transaction_Oracle extends Doctrine_Transaction { return $this->conn->getDbh()->query($query); } + /** + * Set the transacton isolation level. + * + * @param string standard isolation level + * READ UNCOMMITTED (allows dirty reads) + * READ COMMITTED (prevents dirty reads) + * REPEATABLE READ (prevents nonrepeatable reads) + * SERIALIZABLE (prevents phantom reads) + * @throws PDOException if something fails at the PDO level + * @throws Doctrine_Transaction_Exception if using unknown isolation level + * @return void + */ + public function setTransactionIsolation($isolation) { + switch($isolation) { + case 'READ UNCOMMITTED': + $isolation = 'READ COMMITTED'; + break; + case 'READ COMMITTED': + case 'REPEATABLE READ': + case 'SERIALIZABLE': + $isolation = 'SERIALIZABLE'; + break; + default: + throw new Doctrine_Transaction_Exception('Isolation level ' . $isolation . ' is not supported.'); + } + + $query = 'ALTER SESSION ISOLATION LEVEL ' . $isolation; + return $this->dbh->query($query); + } } diff --git a/lib/Doctrine/Transaction/Pgsql.php b/lib/Doctrine/Transaction/Pgsql.php index 0e904ea4f..670374423 100644 --- a/lib/Doctrine/Transaction/Pgsql.php +++ b/lib/Doctrine/Transaction/Pgsql.php @@ -67,5 +67,30 @@ class Doctrine_Transaction_Pgsql extends Doctrine_Transaction { $query = 'ROLLBACK TO SAVEPOINT '.$savepoint; return $this->conn->getDbh()->query($query); - } + } + /** + * Set the transacton isolation level. + * + * @param string standard isolation level + * READ UNCOMMITTED (allows dirty reads) + * READ COMMITTED (prevents dirty reads) + * REPEATABLE READ (prevents nonrepeatable reads) + * SERIALIZABLE (prevents phantom reads) + * @throws PDOException if something fails at the PDO level + * @throws Doctrine_Transaction_Exception if using unknown isolation level or unknown wait option + * @return void + */ + public function setTransactionIsolation($isolation) { + switch ($isolation) { + case 'READ UNCOMMITTED': + case 'READ COMMITTED': + case 'REPEATABLE READ': + case 'SERIALIZABLE': + break; + throw new Doctrine_Connection_Pgsql_Exception('Isolation level '.$isolation.' is not supported.'); + } + + $query = 'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL ' . $isolation; + return $this->dbh->query($query); + } } diff --git a/lib/Doctrine/Transaction/Sqlite.php b/lib/Doctrine/Transaction/Sqlite.php index 23dcfb77e..f4eb09682 100644 --- a/lib/Doctrine/Transaction/Sqlite.php +++ b/lib/Doctrine/Transaction/Sqlite.php @@ -30,4 +30,35 @@ Doctrine::autoload('Doctrine_Transaction'); * @since 1.0 * @version $Revision$ */ -class Doctrine_Transaction_Sqlite extends Doctrine_Transaction { } +class Doctrine_Transaction_Sqlite extends Doctrine_Transaction { + /** + * Set the transacton isolation level. + * + * @param string standard isolation level + * READ UNCOMMITTED (allows dirty reads) + * READ COMMITTED (prevents dirty reads) + * REPEATABLE READ (prevents nonrepeatable reads) + * SERIALIZABLE (prevents phantom reads) + * @throws PDOException if something fails at the PDO level + * @throws Doctrine_Transaction_Exception if using unknown isolation level + * @return void + */ + public function setTransactionIsolation($isolation) { + switch ($isolation) { + case 'READ UNCOMMITTED': + $isolation = 0; + break; + case 'READ COMMITTED': + case 'REPEATABLE READ': + case 'SERIALIZABLE': + $isolation = 1; + break; + default: + throw new Doctrine_Transaction_Exception('Isolation level ' . $isolation . 'is not supported.'); + } + + $query = 'PRAGMA read_uncommitted = '.$isolation; + + return $this->conn->getDbh()->query($query); + } +}