1
0
mirror of synced 2025-01-29 19:41:45 +03:00

[2.0] DDC-290 - Enhance OCI8 Error handling and convert errors to exceptions where necessary.

This commit is contained in:
beberlei 2010-01-31 18:17:05 +00:00
parent 8d607b1b78
commit 3ea1f8064a
3 changed files with 47 additions and 4 deletions

View File

@ -32,7 +32,10 @@ class OCI8Connection implements \Doctrine\DBAL\Driver\Connection
public function __construct($username, $password, $db)
{
$this->_dbh = oci_connect($username, $password, $db);
$this->_dbh = @oci_connect($username, $password, $db);
if (!$this->_dbh) {
throw new OCI8Exception($this->errorInfo());
}
}
public function prepare($prepareString)
@ -74,12 +77,18 @@ class OCI8Connection implements \Doctrine\DBAL\Driver\Connection
public function commit()
{
return oci_commit($this->_dbh);
if (!oci_commit($this->_dbh)) {
throw OCI8Exception::fromErrorInfo($this->errorInfo());
}
return true;
}
public function rollBack()
{
return oci_rollback($this->_dbh);
if (!oci_rollback($this->_dbh)) {
throw OCI8Exception::fromErrorInfo($this->errorInfo());
}
return true;
}
public function errorCode()

View File

@ -0,0 +1,30 @@
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Driver\OCI8;
class OCI8Exception extends \Exception
{
static public function fromErrorInfo($error)
{
return new self($error['message'], $error['code']);
}
}

View File

@ -137,7 +137,11 @@ class OCI8Statement implements \Doctrine\DBAL\Driver\Statement
}
}
return oci_execute($this->_sth, OCI_DEFAULT);
$ret = @oci_execute($this->_sth, OCI_DEFAULT);
if (!$ret) {
throw OCI8Exception::fromErrorInfo($this->errorInfo());
}
return $ret;
}
/**