diff --git a/src/Jfelder/OracleDB/Connectors/OracleConnector.php b/src/Jfelder/OracleDB/Connectors/OracleConnector.php index 1f3673d..2b1eaf7 100644 --- a/src/Jfelder/OracleDB/Connectors/OracleConnector.php +++ b/src/Jfelder/OracleDB/Connectors/OracleConnector.php @@ -6,6 +6,7 @@ use Illuminate\Database\Connectors\ConnectorInterface as ConnectorInterface; use InvalidArgumentException; use Jfelder\OracleDB\OCI_PDO\OCI as OCI; +use PDO; class OracleConnector extends Connector implements ConnectorInterface { @@ -15,9 +16,9 @@ class OracleConnector extends Connector implements ConnectorInterface * @var array */ protected $options = [ - \PDO::ATTR_CASE => \PDO::CASE_LOWER, - \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, - \PDO::ATTR_ORACLE_NULLS => \PDO::NULL_NATURAL, + PDO::ATTR_CASE => PDO::CASE_LOWER, + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, ]; /** diff --git a/src/Jfelder/OracleDB/OracleConnection.php b/src/Jfelder/OracleDB/OracleConnection.php index 37f91fd..0aaa686 100644 --- a/src/Jfelder/OracleDB/OracleConnection.php +++ b/src/Jfelder/OracleDB/OracleConnection.php @@ -2,12 +2,13 @@ namespace Jfelder\OracleDB; -use Doctrine\DBAL\Driver\OCI8\Driver as DoctrineDriver; +use Exception; use Illuminate\Database\Connection; -use Jfelder\OracleDB\Query\Grammars\OracleGrammar as QueryGrammer; +use Jfelder\OracleDB\PDO\OracleDriver; +use Jfelder\OracleDB\Query\Grammars\OracleGrammar as QueryGrammar; use Jfelder\OracleDB\Query\OracleBuilder as OracleQueryBuilder; use Jfelder\OracleDB\Query\Processors\OracleProcessor; -use Jfelder\OracleDB\Schema\Grammars\OracleGrammar as SchemaGrammer; +use Jfelder\OracleDB\Schema\Grammars\OracleGrammar as SchemaGrammar; use Jfelder\OracleDB\Schema\OracleBuilder as OracleSchemaBuilder; use PDO; @@ -46,17 +47,21 @@ public function query() */ protected function getDefaultQueryGrammar() { - return $this->withTablePrefix(new QueryGrammer); + ($grammar = new QueryGrammar)->setConnection($this); + + return $this->withTablePrefix($grammar); } /** * Get the default schema grammar instance. * - * @return \Jfelder\OracleDB\Schema\Grammars\OracleGrammar + * @return \Jfelder\OracleDB\Schema\Grammars\OracleGrammar|null */ protected function getDefaultSchemaGrammar() { - return $this->withTablePrefix(new SchemaGrammer); + ($grammar = new SchemaGrammar)->setConnection($this); + + return $this->withTablePrefix($grammar); } /** @@ -76,7 +81,7 @@ protected function getDefaultPostProcessor() */ protected function getDoctrineDriver() { - return new DoctrineDriver; + return new OracleDriver; } /** @@ -129,4 +134,14 @@ public function oracleInsertGetId($query, $bindings = []) return (int) $last_insert_id; }); } + + /** + * Determine if the given database exception was caused by a unique constraint violation. + * + * @return bool + */ + protected function isUniqueConstraintError(Exception $exception) + { + return boolval(preg_match('#ORA-00001: unique constraint#i', $exception->getMessage())); + } } diff --git a/src/Jfelder/OracleDB/OracleDBServiceProvider.php b/src/Jfelder/OracleDB/OracleDBServiceProvider.php index 2a7a7ab..401ba19 100644 --- a/src/Jfelder/OracleDB/OracleDBServiceProvider.php +++ b/src/Jfelder/OracleDB/OracleDBServiceProvider.php @@ -46,9 +46,9 @@ public function register() // setup connection resolver Connection::resolverFor('oracle', function ($connection, $database, $prefix, $config) { $oConnector = new OracleConnector(); - + $oConnection = $oConnector->connect($config); - + return new OracleConnection($oConnection, $config['database'], $config['prefix'], $config); }); } diff --git a/src/Jfelder/OracleDB/PDO/OracleDriver.php b/src/Jfelder/OracleDB/PDO/OracleDriver.php new file mode 100644 index 0000000..ab8e1b2 --- /dev/null +++ b/src/Jfelder/OracleDB/PDO/OracleDriver.php @@ -0,0 +1,19 @@ +