updated-packages

This commit is contained in:
RafficMohammed
2023-01-08 00:13:22 +05:30
parent 3ff7df7487
commit da241bacb6
12659 changed files with 563377 additions and 510538 deletions

View File

@@ -0,0 +1,7 @@
<?php
namespace Doctrine\DBAL\Driver\OCI8;
final class Connection extends OCI8Connection
{
}

View File

@@ -2,9 +2,11 @@
namespace Doctrine\DBAL\Driver\OCI8;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\AbstractOracleDriver;
use const OCI_DEFAULT;
use Doctrine\DBAL\Exception;
use Doctrine\Deprecations\Deprecation;
use const OCI_NO_AUTO_COMMIT;
/**
* A Doctrine DBAL driver for the Oracle OCI8 PHP extensions.
@@ -17,16 +19,16 @@ class Driver extends AbstractOracleDriver
public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
{
try {
return new OCI8Connection(
$username,
$password,
return new Connection(
(string) $username,
(string) $password,
$this->_constructDsn($params),
$params['charset'] ?? null,
$params['sessionMode'] ?? OCI_DEFAULT,
$params['charset'] ?? '',
$params['sessionMode'] ?? OCI_NO_AUTO_COMMIT,
$params['persistent'] ?? false
);
} catch (OCI8Exception $e) {
throw DBALException::driverException($this, $e);
throw Exception::driverException($this, $e);
}
}
@@ -44,9 +46,17 @@ class Driver extends AbstractOracleDriver
/**
* {@inheritdoc}
*
* @deprecated
*/
public function getName()
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/3580',
'Driver::getName() is deprecated'
);
return 'oci8';
}
}

View File

@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\Driver\OCI8\Exception;
use Doctrine\DBAL\Driver\OCI8\OCI8Exception;
use function sprintf;
/**
* @internal
*
* @psalm-immutable
*/
final class NonTerminatedStringLiteral extends OCI8Exception
{
public static function new(int $offset): self
{
return new self(
sprintf(
'The statement contains non-terminated string literal starting at offset %d.',
$offset
)
);
}
}

View File

@@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\Driver\OCI8\Exception;
use Doctrine\DBAL\Driver\OCI8\OCI8Exception;
/**
* @internal
*
* @psalm-immutable
*/
final class SequenceDoesNotExist extends OCI8Exception
{
public static function new(): self
{
return new self('lastInsertId failed: Query was executed but no result was returned.');
}
}

View File

@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\Driver\OCI8\Exception;
use Doctrine\DBAL\Driver\OCI8\OCI8Exception;
use function sprintf;
/**
* @internal
*
* @psalm-immutable
*/
final class UnknownParameterIndex extends OCI8Exception
{
public static function new(int $index): self
{
return new self(
sprintf('Could not find variable mapping with index %d, in the SQL statement', $index)
);
}
}

View File

@@ -2,16 +2,14 @@
namespace Doctrine\DBAL\Driver\OCI8;
use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Driver\Connection as ConnectionInterface;
use Doctrine\DBAL\Driver\OCI8\Exception\SequenceDoesNotExist;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\ParameterType;
use Doctrine\Deprecations\Deprecation;
use UnexpectedValueException;
use const OCI_COMMIT_ON_SUCCESS;
use const OCI_DEFAULT;
use const OCI_NO_AUTO_COMMIT;
use function addcslashes;
use function define;
use function defined;
use function func_get_args;
use function is_float;
use function is_int;
@@ -25,10 +23,15 @@ use function preg_match;
use function sprintf;
use function str_replace;
use const OCI_COMMIT_ON_SUCCESS;
use const OCI_NO_AUTO_COMMIT;
/**
* OCI8 implementation of the Connection interface.
*
* @deprecated Use {@link Connection} instead
*/
class OCI8Connection implements Connection, ServerInfoAwareConnection
class OCI8Connection implements ConnectionInterface, ServerInfoAwareConnection
{
/** @var resource */
protected $dbh;
@@ -39,28 +42,34 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
/**
* Creates a Connection to an Oracle Database using oci8 extension.
*
* @param string $username
* @param string $password
* @param string $db
* @param string|null $charset
* @param int $sessionMode
* @param bool $persistent
* @internal The connection can be only instantiated by its driver.
*
* @param string $username
* @param string $password
* @param string $db
* @param string $charset
* @param int $sessionMode
* @param bool $persistent
*
* @throws OCI8Exception
*/
public function __construct($username, $password, $db, $charset = null, $sessionMode = OCI_DEFAULT, $persistent = false)
{
if (! defined('OCI_NO_AUTO_COMMIT')) {
define('OCI_NO_AUTO_COMMIT', 0);
}
$this->dbh = $persistent
public function __construct(
$username,
$password,
$db,
$charset = '',
$sessionMode = OCI_NO_AUTO_COMMIT,
$persistent = false
) {
$dbh = $persistent
? @oci_pconnect($username, $password, $db, $charset, $sessionMode)
: @oci_connect($username, $password, $db, $charset, $sessionMode);
if (! $this->dbh) {
if ($dbh === false) {
throw OCI8Exception::fromErrorInfo(oci_error());
}
$this->dbh = $dbh;
}
/**
@@ -71,17 +80,23 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
*/
public function getServerVersion()
{
if (! preg_match('/\s+(\d+\.\d+\.\d+\.\d+\.\d+)\s+/', oci_server_version($this->dbh), $version)) {
$version = oci_server_version($this->dbh);
if ($version === false) {
throw OCI8Exception::fromErrorInfo(oci_error($this->dbh));
}
if (! preg_match('/\s+(\d+\.\d+\.\d+\.\d+\.\d+)\s+/', $version, $matches)) {
throw new UnexpectedValueException(
sprintf(
'Unexpected database version string "%s". Cannot parse an appropriate version number from it. ' .
'Please report this database version string to the Doctrine team.',
oci_server_version($this->dbh)
$version
)
);
}
return $version[1];
return $matches[1];
}
/**
@@ -89,15 +104,21 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
*/
public function requiresQueryForServerVersion()
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4114',
'ServerInfoAwareConnection::requiresQueryForServerVersion() is deprecated and removed in DBAL 3.'
);
return false;
}
/**
* {@inheritdoc}
*/
public function prepare($prepareString)
public function prepare($sql)
{
return new OCI8Statement($this->dbh, $prepareString, $this);
return new Statement($this->dbh, $sql, $this);
}
/**
@@ -122,6 +143,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
if (is_int($value) || is_float($value)) {
return $value;
}
$value = str_replace("'", "''", $value);
return "'" . addcslashes($value, "\000\n\r\\\032") . "'";
@@ -130,9 +152,9 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
/**
* {@inheritdoc}
*/
public function exec($statement)
public function exec($sql)
{
$stmt = $this->prepare($statement);
$stmt = $this->prepare($sql);
$stmt->execute();
return $stmt->rowCount();
@@ -140,6 +162,10 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
/**
* {@inheritdoc}
*
* @param string|null $name
*
* @return int|false
*/
public function lastInsertId($name = null)
{
@@ -152,7 +178,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
$result = $stmt->fetchColumn();
if ($result === false) {
throw new OCI8Exception('lastInsertId failed: Query was executed but no result was returned.');
throw SequenceDoesNotExist::new();
}
return (int) $result;
@@ -161,6 +187,8 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
/**
* Returns the current execution mode.
*
* @internal
*
* @return int
*/
public function getExecuteMode()
@@ -186,6 +214,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
if (! oci_commit($this->dbh)) {
throw OCI8Exception::fromErrorInfo($this->errorInfo());
}
$this->executeMode = OCI_COMMIT_ON_SUCCESS;
return true;
@@ -199,6 +228,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
if (! oci_rollback($this->dbh)) {
throw OCI8Exception::fromErrorInfo($this->errorInfo());
}
$this->executeMode = OCI_COMMIT_ON_SUCCESS;
return true;
@@ -206,22 +236,33 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
/**
* {@inheritdoc}
*
* @deprecated The error information is available via exceptions.
*/
public function errorCode()
{
$error = oci_error($this->dbh);
if ($error !== false) {
$error = $error['code'];
return $error['code'];
}
return $error;
return null;
}
/**
* {@inheritdoc}
*
* @deprecated The error information is available via exceptions.
*/
public function errorInfo()
{
return oci_error($this->dbh);
$error = oci_error($this->dbh);
if ($error === false) {
return [];
}
return $error;
}
}

View File

@@ -4,15 +4,24 @@ namespace Doctrine\DBAL\Driver\OCI8;
use Doctrine\DBAL\Driver\AbstractDriverException;
/**
* @deprecated Use {@link \Doctrine\DBAL\Driver\Exception} instead
*
* @psalm-immutable
*/
class OCI8Exception extends AbstractDriverException
{
/**
* @param mixed[] $error
* @param mixed[]|false $error
*
* @return \Doctrine\DBAL\Driver\OCI8\OCI8Exception
* @return OCI8Exception
*/
public static function fromErrorInfo($error)
{
if ($error === false) {
return new self('Database error occurred but no error information was retrieved from the driver.');
}
return new self($error['message'], null, $error['code']);
}
}

View File

@@ -2,30 +2,25 @@
namespace Doctrine\DBAL\Driver\OCI8;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Driver\FetchUtils;
use Doctrine\DBAL\Driver\OCI8\Exception\NonTerminatedStringLiteral;
use Doctrine\DBAL\Driver\OCI8\Exception\UnknownParameterIndex;
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Driver\Statement as StatementInterface;
use Doctrine\DBAL\Driver\StatementIterator;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType;
use InvalidArgumentException;
use IteratorAggregate;
use PDO;
use const OCI_ASSOC;
use const OCI_B_BIN;
use const OCI_B_BLOB;
use const OCI_BOTH;
use const OCI_D_LOB;
use const OCI_FETCHSTATEMENT_BY_COLUMN;
use const OCI_FETCHSTATEMENT_BY_ROW;
use const OCI_NUM;
use const OCI_RETURN_LOBS;
use const OCI_RETURN_NULLS;
use const OCI_TEMP_BLOB;
use const PREG_OFFSET_CAPTURE;
use const SQLT_CHR;
use ReturnTypeWillChange;
use function array_key_exists;
use function assert;
use function count;
use function implode;
use function is_numeric;
use function is_int;
use function is_resource;
use function oci_bind_by_name;
use function oci_cancel;
use function oci_error;
@@ -39,13 +34,28 @@ use function oci_num_rows;
use function oci_parse;
use function preg_match;
use function preg_quote;
use function sprintf;
use function substr;
use const OCI_ASSOC;
use const OCI_B_BIN;
use const OCI_B_BLOB;
use const OCI_BOTH;
use const OCI_D_LOB;
use const OCI_FETCHSTATEMENT_BY_COLUMN;
use const OCI_FETCHSTATEMENT_BY_ROW;
use const OCI_NUM;
use const OCI_RETURN_LOBS;
use const OCI_RETURN_NULLS;
use const OCI_TEMP_BLOB;
use const PREG_OFFSET_CAPTURE;
use const SQLT_CHR;
/**
* The OCI8 implementation of the Statement interface.
*
* @deprecated Use {@link Statement} instead
*/
class OCI8Statement implements IteratorAggregate, Statement
class OCI8Statement implements IteratorAggregate, StatementInterface, Result
{
/** @var resource */
protected $_dbh;
@@ -56,7 +66,11 @@ class OCI8Statement implements IteratorAggregate, Statement
/** @var OCI8Connection */
protected $_conn;
/** @var string */
/**
* @deprecated
*
* @var string
*/
protected static $_PARAM = ':param';
/** @var int[] */
@@ -92,16 +106,22 @@ class OCI8Statement implements IteratorAggregate, Statement
/**
* Creates a new OCI8Statement that uses the given connection handle and SQL statement.
*
* @param resource $dbh The connection handle.
* @param string $statement The SQL statement.
* @internal The statement can be only instantiated by its driver connection.
*
* @param resource $dbh The connection handle.
* @param string $query The SQL query.
*/
public function __construct($dbh, $statement, OCI8Connection $conn)
public function __construct($dbh, $query, OCI8Connection $conn)
{
[$statement, $paramMap] = self::convertPositionalToNamedPlaceholders($statement);
$this->_sth = oci_parse($dbh, $statement);
$this->_dbh = $dbh;
$this->_paramMap = $paramMap;
$this->_conn = $conn;
[$query, $paramMap] = self::convertPositionalToNamedPlaceholders($query);
$stmt = oci_parse($dbh, $query);
assert(is_resource($stmt));
$this->_sth = $stmt;
$this->_dbh = $dbh;
$this->_paramMap = $paramMap;
$this->_conn = $conn;
}
/**
@@ -116,6 +136,8 @@ class OCI8Statement implements IteratorAggregate, Statement
* Question marks inside literal strings are therefore handled correctly by this method.
* This comes at a cost, the whole sql statement has to be looped over.
*
* @internal
*
* @param string $statement The SQL statement to convert.
*
* @return mixed[] [0] => the statement value (string), [1] => the paramMap value (array).
@@ -146,11 +168,8 @@ class OCI8Statement implements IteratorAggregate, Statement
}
} while ($result);
if ($currentLiteralDelimiter) {
throw new OCI8Exception(sprintf(
'The statement contains non-terminated string literal starting at offset %d',
$tokenOffset - 1
));
if ($currentLiteralDelimiter !== null) {
throw NonTerminatedStringLiteral::new($tokenOffset - 1);
}
$fragments[] = substr($statement, $fragmentOffset);
@@ -163,12 +182,14 @@ class OCI8Statement implements IteratorAggregate, Statement
* Finds next placeholder or opening quote.
*
* @param string $statement The SQL statement to parse
* @param string $tokenOffset The offset to start searching from
* @param int $tokenOffset The offset to start searching from
* @param int $fragmentOffset The offset to build the next fragment from
* @param string[] $fragments Fragments of the original statement not containing placeholders
* @param string[] $fragments Fragments of the original statement
* not containing placeholders
* @param string|null $currentLiteralDelimiter The delimiter of the current string literal
* or NULL if not currently in a literal
* @param array<int, string> $paramMap Mapping of the original parameter positions to their named replacements
* @param array<int, string> $paramMap Mapping of the original parameter positions
* to their named replacements
*
* @return bool Whether the token was found
*/
@@ -207,12 +228,13 @@ class OCI8Statement implements IteratorAggregate, Statement
/**
* Finds closing quote
*
* @param string $statement The SQL statement to parse
* @param string $tokenOffset The offset to start searching from
* @param string|null $currentLiteralDelimiter The delimiter of the current string literal
* or NULL if not currently in a literal
* @param string $statement The SQL statement to parse
* @param int $tokenOffset The offset to start searching from
* @param string $currentLiteralDelimiter The delimiter of the current string literal
*
* @return bool Whether the token was found
*
* @param-out string|null $currentLiteralDelimiter
*/
private static function findClosingQuote(
$statement,
@@ -229,7 +251,7 @@ class OCI8Statement implements IteratorAggregate, Statement
return false;
}
$currentLiteralDelimiter = false;
$currentLiteralDelimiter = null;
++$tokenOffset;
return true;
@@ -240,7 +262,7 @@ class OCI8Statement implements IteratorAggregate, Statement
* where the token was found.
*
* @param string $statement The SQL statement to parse
* @param string $offset The offset to start searching from
* @param int $offset The offset to start searching from
* @param string $regex The regex containing token pattern
*
* @return string|null Token or NULL if not found
@@ -249,6 +271,7 @@ class OCI8Statement implements IteratorAggregate, Statement
{
if (preg_match($regex, $statement, $matches, PREG_OFFSET_CAPTURE, $offset)) {
$offset = $matches[0][1];
return $matches[0][0];
}
@@ -266,9 +289,15 @@ class OCI8Statement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null)
public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null)
{
$column = $this->_paramMap[$column] ?? $column;
if (is_int($param)) {
if (! isset($this->_paramMap[$param])) {
throw UnknownParameterIndex::new($param);
}
$param = $this->_paramMap[$param];
}
if ($type === ParameterType::LARGE_OBJECT) {
$lob = oci_new_descriptor($this->_dbh, OCI_D_LOB);
@@ -277,11 +306,11 @@ class OCI8Statement implements IteratorAggregate, Statement
$variable =& $lob;
}
$this->boundValues[$column] =& $variable;
$this->boundValues[$param] =& $variable;
return oci_bind_by_name(
$this->_sth,
$column,
$param,
$variable,
$length ?? -1,
$this->convertParameterType($type)
@@ -291,7 +320,7 @@ class OCI8Statement implements IteratorAggregate, Statement
/**
* Converts DBAL parameter type to oci8 parameter type
*/
private function convertParameterType(int $type) : int
private function convertParameterType(int $type): int
{
switch ($type) {
case ParameterType::BINARY:
@@ -307,17 +336,12 @@ class OCI8Statement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*
* @deprecated Use free() instead.
*/
public function closeCursor()
{
// not having the result means there's nothing to close
if (! $this->result) {
return true;
}
oci_cancel($this->_sth);
$this->result = false;
$this->free();
return true;
}
@@ -327,11 +351,13 @@ class OCI8Statement implements IteratorAggregate, Statement
*/
public function columnCount()
{
return oci_num_fields($this->_sth);
return oci_num_fields($this->_sth) ?: 0;
}
/**
* {@inheritdoc}
*
* @deprecated The error information is available via exceptions.
*/
public function errorCode()
{
@@ -345,10 +371,18 @@ class OCI8Statement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*
* @deprecated The error information is available via exceptions.
*/
public function errorInfo()
{
return oci_error($this->_sth);
$error = oci_error($this->_sth);
if ($error === false) {
return [];
}
return $error;
}
/**
@@ -358,8 +392,9 @@ class OCI8Statement implements IteratorAggregate, Statement
{
if ($params) {
$hasZeroIndex = array_key_exists(0, $params);
foreach ($params as $key => $val) {
if ($hasZeroIndex && is_numeric($key)) {
if ($hasZeroIndex && is_int($key)) {
$this->bindValue($key + 1, $val);
} else {
$this->bindValue($key, $val);
@@ -379,6 +414,8 @@ class OCI8Statement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*
* @deprecated Use one of the fetch- or iterate-related methods.
*/
public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
{
@@ -389,7 +426,10 @@ class OCI8Statement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*
* @deprecated Use iterateNumeric(), iterateAssociative() or iterateColumn() instead.
*/
#[ReturnTypeWillChange]
public function getIterator()
{
return new StatementIterator($this);
@@ -397,6 +437,8 @@ class OCI8Statement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*
* @deprecated Use fetchNumeric(), fetchAssociative() or fetchOne() instead.
*/
public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
{
@@ -428,6 +470,8 @@ class OCI8Statement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*
* @deprecated Use fetchAllNumeric(), fetchAllAssociative() or fetchFirstColumn() instead.
*/
public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null)
{
@@ -482,6 +526,8 @@ class OCI8Statement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*
* @deprecated Use fetchOne() instead.
*/
public function fetchColumn($columnIndex = 0)
{
@@ -505,6 +551,105 @@ class OCI8Statement implements IteratorAggregate, Statement
*/
public function rowCount()
{
return oci_num_rows($this->_sth);
return oci_num_rows($this->_sth) ?: 0;
}
/**
* {@inheritdoc}
*/
public function fetchNumeric()
{
return $this->doFetch(OCI_NUM);
}
/**
* {@inheritdoc}
*/
public function fetchAssociative()
{
return $this->doFetch(OCI_ASSOC);
}
/**
* {@inheritdoc}
*/
public function fetchOne()
{
return FetchUtils::fetchOne($this);
}
/**
* {@inheritdoc}
*/
public function fetchAllNumeric(): array
{
return $this->doFetchAll(OCI_NUM, OCI_FETCHSTATEMENT_BY_ROW);
}
/**
* {@inheritdoc}
*/
public function fetchAllAssociative(): array
{
return $this->doFetchAll(OCI_ASSOC, OCI_FETCHSTATEMENT_BY_ROW);
}
/**
* {@inheritdoc}
*/
public function fetchFirstColumn(): array
{
return $this->doFetchAll(OCI_NUM, OCI_FETCHSTATEMENT_BY_COLUMN)[0];
}
public function free(): void
{
// not having the result means there's nothing to close
if (! $this->result) {
return;
}
oci_cancel($this->_sth);
$this->result = false;
}
/**
* @return mixed|false
*/
private function doFetch(int $mode)
{
// do not try fetching from the statement if it's not expected to contain the result
// in order to prevent exceptional situation
if (! $this->result) {
return false;
}
return oci_fetch_array(
$this->_sth,
$mode | OCI_RETURN_NULLS | OCI_RETURN_LOBS
);
}
/**
* @return array<mixed>
*/
private function doFetchAll(int $mode, int $fetchStructure): array
{
// do not try fetching from the statement if it's not expected to contain the result
// in order to prevent exceptional situation
if (! $this->result) {
return [];
}
oci_fetch_all(
$this->_sth,
$result,
0,
-1,
$mode | OCI_RETURN_NULLS | $fetchStructure | OCI_RETURN_LOBS
);
return $result;
}
}

View File

@@ -0,0 +1,7 @@
<?php
namespace Doctrine\DBAL\Driver\OCI8;
final class Statement extends OCI8Statement
{
}