[2.0] DDC-290 - Enhance OCI8 Error handling and convert errors to exceptions where necessary.
This commit is contained in:
parent
8d607b1b78
commit
3ea1f8064a
lib/Doctrine/DBAL/Driver/OCI8
@ -32,7 +32,10 @@ class OCI8Connection implements \Doctrine\DBAL\Driver\Connection
|
|||||||
|
|
||||||
public function __construct($username, $password, $db)
|
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)
|
public function prepare($prepareString)
|
||||||
@ -74,12 +77,18 @@ class OCI8Connection implements \Doctrine\DBAL\Driver\Connection
|
|||||||
|
|
||||||
public function commit()
|
public function commit()
|
||||||
{
|
{
|
||||||
return oci_commit($this->_dbh);
|
if (!oci_commit($this->_dbh)) {
|
||||||
|
throw OCI8Exception::fromErrorInfo($this->errorInfo());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function rollBack()
|
public function rollBack()
|
||||||
{
|
{
|
||||||
return oci_rollback($this->_dbh);
|
if (!oci_rollback($this->_dbh)) {
|
||||||
|
throw OCI8Exception::fromErrorInfo($this->errorInfo());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function errorCode()
|
public function errorCode()
|
||||||
|
30
lib/Doctrine/DBAL/Driver/OCI8/OCI8Exception.php
Normal file
30
lib/Doctrine/DBAL/Driver/OCI8/OCI8Exception.php
Normal 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']);
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user