diff --git a/lib/Doctrine/DBAL/Driver/OCI8/Driver.php b/lib/Doctrine/DBAL/Driver/OCI8/Driver.php index 4ff6d72d12d..ddba3bf94af 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/Driver.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/Driver.php @@ -36,7 +36,9 @@ public function connect(array $params, $username = null, $password = null, array return new OCI8Connection( $username, $password, - $this->_constructDsn($params) + $this->_constructDsn($params), + isset($params['charset']) ? $params['charset'] : null, + isset($params['session_mode']) ? $params['session_mode'] : OCI_DEFAULT ); } @@ -67,10 +69,6 @@ private function _constructDsn(array $params) $dsn .= $params['dbname']; } - if (isset($params['charset'])) { - $dsn .= ';charset=' . $params['charset']; - } - return $dsn; } diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php index 987bf6c0c76..cfbb5962769 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php @@ -30,17 +30,19 @@ class OCI8Connection implements \Doctrine\DBAL\Driver\Connection { private $_dbh; - public function __construct($username, $password, $db) + private $_executionMode = OCI_COMMIT_ON_SUCCESS; + + public function __construct($username, $password, $db, $charset = null, $session_mode = OCI_DEFAULT) { - $this->_dbh = @oci_connect($username, $password, $db); + $this->_dbh = @oci_connect($username, $password, $db, $charset, $session_mode); if (!$this->_dbh) { - throw new OCI8Exception($this->errorInfo()); + throw OCI8Exception::fromErrorInfo($this->errorInfo()); } } public function prepare($prepareString) { - return new OCI8Statement($this->_dbh, $prepareString); + return new OCI8Statement($this, $prepareString); } public function query() @@ -72,11 +74,13 @@ public function lastInsertId($name = null) public function beginTransaction() { + $this->_executionMode = OCI_NO_AUTO_COMMIT; return true; } public function commit() { + $this->_executionMode = OCI_COMMIT_ON_SUCCESS; if (!oci_commit($this->_dbh)) { throw OCI8Exception::fromErrorInfo($this->errorInfo()); } @@ -85,6 +89,7 @@ public function commit() public function rollBack() { + $this->_executionMode = OCI_COMMIT_ON_SUCCESS; if (!oci_rollback($this->_dbh)) { throw OCI8Exception::fromErrorInfo($this->errorInfo()); } @@ -93,7 +98,12 @@ public function rollBack() public function errorCode() { - $error = oci_error($this->_dbh); + if (!is_resource($this->_dbh)) { + $error = oci_error(); + } else { + $error = oci_error($this->_dbh); + } + if ($error !== false) { $error = $error['code']; } @@ -102,7 +112,20 @@ public function errorCode() public function errorInfo() { + if (!is_resource($this->_dbh)) { + return oci_error(); + } return oci_error($this->_dbh); } + public function getDbh() + { + return $this->_dbh; + } + + public function getExecutionMode() + { + return $this->_executionMode; + } + } \ No newline at end of file diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php index d1168d12468..fdee78316f7 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php @@ -41,6 +41,7 @@ class OCI8Statement implements \Doctrine\DBAL\Driver\Statement PDO::FETCH_NUM => OCI_NUM ); private $_paramMap = array(); + private $_connection; /** * Creates a new OCI8Statement that uses the given connection handle and SQL statement. @@ -48,9 +49,10 @@ class OCI8Statement implements \Doctrine\DBAL\Driver\Statement * @param resource $dbh The connection handle. * @param string $statement The SQL statement. */ - public function __construct($dbh, $statement) + public function __construct($connection, $statement) { - $this->_sth = oci_parse($dbh, $this->_convertPositionalToNamedPlaceholders($statement)); + $this->_connection = $connection; + $this->_sth = oci_parse($connection->getDbh(), $this->_convertPositionalToNamedPlaceholders($statement)); } /** @@ -146,7 +148,7 @@ public function execute($params = null) } } - $ret = @oci_execute($this->_sth, OCI_DEFAULT); + $ret = @oci_execute($this->_sth, $this->_connection->getExecutionMode()); if ( ! $ret) { throw OCI8Exception::fromErrorInfo($this->errorInfo()); }