Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oci8 improvements #5

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions lib/Doctrine/DBAL/Driver/OCI8/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

Expand Down Expand Up @@ -67,10 +69,6 @@ private function _constructDsn(array $params)
$dsn .= $params['dbname'];
}

if (isset($params['charset'])) {
$dsn .= ';charset=' . $params['charset'];
}

return $dsn;
}

Expand Down
33 changes: 28 additions & 5 deletions lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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());
}
Expand All @@ -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());
}
Expand All @@ -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'];
}
Expand All @@ -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;
}

}
8 changes: 5 additions & 3 deletions lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,18 @@ 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.
*
* @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));
}

/**
Expand Down Expand Up @@ -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());
}
Expand Down