Skip to content
Draft
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
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
use flake github:loophp/nix-auto-changelog
use flake github:loophp/nix-shell#env-php81-nts --impure
use flake github:loophp/nix-shell#env-php81 --impure
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2019-2022, European Union.
Copyright (c) 2019-2023, European Union.
Original work Copyright (c) 2018 Jason Hofer
All rights reserved.

Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
],
"homepage": "https://github.com/ecphp/doctrine-oci8",
"require": {
"php": ">= 7.4",
"php": ">= 8.0",
"ext-oci8": "*",
"ext-pdo": "*",
"doctrine/dbal": "^2.6"
"doctrine/dbal": "^3"
},
"require-dev": {
"ecphp/php-conventions": "^1",
"phpunit/phpunit": "^9",
"symfony/dotenv": "^5"
"phpunit/phpunit": "^10",
"symfony/dotenv": "^6"
},
"autoload": {
"psr-4": {
Expand Down
50 changes: 50 additions & 0 deletions migration-doctrine-2.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
@startuml

skin rose
hide empty members

title ecphp/doctrine-oci8 migration to dbal3


namespace doctrine.dbal {
abstract class AbstractDriverException
abstract class AbstractOracleDriver

class OCI8Exception extends AbstractDriverException

class Driver extends AbstractOracleDriver

class OCI8Connection implements Connection, ServerInfoAwareConnection {
# dbh : resource
# executeMode : int
}

class OCI8Statement implements IteratorAggregate, Statement {
# _dbh : resource
# _sth : resource
# _conn : OCI8Connection
# _PARAM : string
# fetchModeMap : int[]
# _defaultFetchMode : int
# _paramMap : string[]
# boundValues : mixed[]
# result : bool
}
}

namespace ecphp.doctrine-oci8 {
class OCI8

class Driver extends doctrine.dbal.Driver

class OCI8Connection extends doctrine.dbal.OCI8Connection {
+ newCursor($sth = null): OCI8Cursor
+ prepare($prepareString): OCI8Statement
}

class OCI8Cursor extends doctrine.dbal.OCI8Statement

class OCI8Statement extends doctrine.dbal.OCI8Statement
}

@enduml
61 changes: 61 additions & 0 deletions migration-doctrine-3.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
@startuml

skin rose
hide empty members

title ecphp/doctrine-oci8 migration to dbal3

namespace doctrine.dbal {
together {
interface ServerInfoAwareConnection
interface Statement
interface IteratorAggregate
abstract class AbstractOracleDriver
class "Connection" as OCI8ConnectionDbal
class "OCI8Statement" as OCI8StatementDbal
class "Driver" as DriverDbal
}

together {
OCI8ConnectionDbal -[dashed]-|> ServerInfoAwareConnection
class OCI8ConnectionDbal {
# dbh : resource
# executeMode : int
}

OCI8StatementDbal -[dashed]-|> IteratorAggregate
OCI8StatementDbal -[dashed]-|> Statement
class OCI8StatementDbal {
# _dbh : resource
# _sth : resource
# _conn : OCI8Connection
# _PARAM : string
# fetchModeMap : int[]
# _defaultFetchMode : int
# _paramMap : string[]
# boundValues : mixed[]
# result : bool
}

DriverDbal --|> AbstractOracleDriver
}
}

namespace ecphp.doctrineoci8 {
together {
OCI8Cursor -[dashed]-|> doctrine.dbal.Statement
OCI8Cursor *-- doctrine.dbal.Statement
OCI8Cursor *-- OCI8Connection

OCI8Connection -[dashed]-|> doctrine.dbal.ServerInfoAwareConnection
OCI8Connection *-- doctrine.dbal.OCI8ConnectionDbal

Driver --|> doctrine.dbal.AbstractOracleDriver
Driver *-- doctrine.dbal.DriverDbal

OCI8Statement -[dashed]-|> doctrine.dbal.Statement
OCI8Statement *-- doctrine.dbal.OCI8ConnectionDbal
}
}

@enduml
23 changes: 17 additions & 6 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="tests/bootstrap.php"
backupGlobals="false"
colors="true"
processIsolation="false"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
>
<coverage/>
<testsuites>
<testsuite name="OCI8">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
118 changes: 118 additions & 0 deletions src/Doctrine/DBAL/Driver/OCI8/Connection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php

/**
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* @see https://github.com/ecphp
*/

declare(strict_types=1);

namespace EcPhp\DoctrineOci8\Doctrine\DBAL\Driver\OCI8;

use Doctrine\DBAL\Driver\OCI8\Connection as DBALOCI8Connection;
use Doctrine\DBAL\Driver\OCI8\ConvertPositionalToNamedPlaceholders;
use Doctrine\DBAL\Driver\OCI8\ExecutionMode;
use Doctrine\DBAL\Driver\OCI8\Statement as DBALOCI8Statement;
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\SQL\Parser;

use function assert;
use function is_resource;

final class Connection implements ServerInfoAwareConnection
{
private DBALOCI8Connection $connection;

private ExecutionMode $executionMode;

private Parser $parser;

public function __construct(DBALOCI8Connection $connection)
{
$this->connection = $connection;
$this->parser = new Parser(false);
$this->executionMode = new ExecutionMode();
}

public function beginTransaction()
{
return $this->connection->beginTransaction();
}

public function commit()
{
return $this->connection->commit();
}

public function exec(string $sql): int
{
return $this->connection->exec($sql);
}

public function getNativeConnection()
{
return $this->connection->getNativeConnection();
}

public function getServerVersion()
{
return $this->connection->getServerVersion();
}

public function lastInsertId($name = null)
{
return $this->connection->lastInsertId($name);
}

public function newCursor($sth = null): Cursor
{
return new Cursor(
$this,
$sth,
);
}

public function prepare(string $sql): Statement
{
$visitor = new ConvertPositionalToNamedPlaceholders();

$this->parser->parse($sql, $visitor);

$statement = oci_parse($this->connection->getNativeConnection(), $visitor->getSQL());
assert(is_resource($statement));

$parameterMap = $visitor->getParameterMap();

return new Statement(
$this,
$statement,
$parameterMap,
$this->executionMode,
new DBALOCI8Statement(
$this->connection,
$statement,
$parameterMap,
$this->executionMode
)
);
}

public function query(string $sql): Result
{
return $this->connection->query($sql);
}

public function quote($value, $type = ParameterType::STRING)
{
return $this->connection->quote($value, $type);
}

public function rollBack()
{
return $this->connection->rollBack();
}
}
66 changes: 66 additions & 0 deletions src/Doctrine/DBAL/Driver/OCI8/Cursor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

/**
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* @see https://github.com/ecphp
*/

declare(strict_types=1);

namespace EcPhp\DoctrineOci8\Doctrine\DBAL\Driver\OCI8;

use Doctrine\DBAL\Driver\OCI8\ExecutionMode;
use Doctrine\DBAL\Driver\OCI8\Statement as DriverOCI8Statement;
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\ParameterType;

use function assert;
use function is_resource;
use function oci_new_cursor;

final class Cursor implements Statement
{
private Statement $decoratedStatement;

// TODO: What to do with this?
private $sth;

public function __construct(
private readonly Connection $connection,
$sth = null,
) {
$this->sth = $sth ?: oci_new_cursor($connection->getNativeConnection());

assert(is_resource($this->sth));

$this->decoratedStatement = new DriverOCI8Statement(
$this->connection,
$this->sth,
[],
new ExecutionMode()
);
}

public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null): bool
{
return $this->decoratedStatement->bindParam($param, $variable, $type, $length);
}

public function bindValue($param, $value, $type = ParameterType::STRING): bool
{
return $this->decoratedStatement->bindValue($param, $value, $type);
}

public function execute($params = null): Result
{
return $this->decoratedStatement->execute($params);
}

public function getStatementHandle()
{
return $this->sth;
}
}
Loading