Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jfelder committed Jan 16, 2024
1 parent f4cf42d commit 9645730
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 13 deletions.
7 changes: 4 additions & 3 deletions src/Jfelder/OracleDB/Connectors/OracleConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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,
];

/**
Expand Down
29 changes: 22 additions & 7 deletions src/Jfelder/OracleDB/OracleConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

/**
Expand All @@ -76,7 +81,7 @@ protected function getDefaultPostProcessor()
*/
protected function getDoctrineDriver()
{
return new DoctrineDriver;
return new OracleDriver;
}

/**
Expand Down Expand Up @@ -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()));
}
}
4 changes: 2 additions & 2 deletions src/Jfelder/OracleDB/OracleDBServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down
19 changes: 19 additions & 0 deletions src/Jfelder/OracleDB/PDO/OracleDriver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Jfelder\OracleDB\PDO;

use Doctrine\DBAL\Driver\AbstractOracleDriver;
use Illuminate\Database\PDO\Concerns\ConnectsToDatabase;

class OracleDriver extends AbstractOracleDriver
{
use ConnectsToDatabase;

/**
* {@inheritdoc}
*/
public function getName()
{
return 'oci8';
}
}
3 changes: 2 additions & 1 deletion src/Jfelder/OracleDB/Query/OracleBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace Jfelder\OracleDB\Query;

use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\Expression;

class OracleBuilder extends \Illuminate\Database\Query\Builder
class OracleBuilder extends Builder
{
/**
* Add a subquery cross join to the query.
Expand Down

0 comments on commit 9645730

Please sign in to comment.