updated-packages
This commit is contained in:
@@ -2,21 +2,25 @@
|
||||
|
||||
namespace Doctrine\DBAL\Driver\SQLAnywhere;
|
||||
|
||||
use Doctrine\DBAL\DBALException;
|
||||
use Doctrine\DBAL\Driver\AbstractSQLAnywhereDriver;
|
||||
use Doctrine\DBAL\Exception;
|
||||
use Doctrine\Deprecations\Deprecation;
|
||||
|
||||
use function array_keys;
|
||||
use function array_map;
|
||||
use function implode;
|
||||
|
||||
/**
|
||||
* A Doctrine DBAL driver for the SAP Sybase SQL Anywhere PHP extension.
|
||||
*
|
||||
* @deprecated Support for SQLAnywhere will be removed in 3.0.
|
||||
*/
|
||||
class Driver extends AbstractSQLAnywhereDriver
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @throws DBALException If there was a problem establishing the connection.
|
||||
* @throws Exception If there was a problem establishing the connection.
|
||||
*/
|
||||
public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
|
||||
{
|
||||
@@ -34,35 +38,50 @@ class Driver extends AbstractSQLAnywhereDriver
|
||||
$params['persistent'] ?? false
|
||||
);
|
||||
} catch (SQLAnywhereException $e) {
|
||||
throw DBALException::driverException($this, $e);
|
||||
throw Exception::driverException($this, $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
Deprecation::trigger(
|
||||
'doctrine/dbal',
|
||||
'https://github.com/doctrine/dbal/issues/3580',
|
||||
'Driver::getName() is deprecated'
|
||||
);
|
||||
|
||||
return 'sqlanywhere';
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the connection string for given connection parameters and driver options.
|
||||
*
|
||||
* @param string $host Host address to connect to.
|
||||
* @param int $port Port to use for the connection (default to SQL Anywhere standard port 2638).
|
||||
* @param string $server Database server name on the host to connect to.
|
||||
* SQL Anywhere allows multiple database server instances on the same host,
|
||||
* therefore specifying the server instance name to use is mandatory.
|
||||
* @param string $dbname Name of the database on the server instance to connect to.
|
||||
* @param string $username User name to use for connection authentication.
|
||||
* @param string $password Password to use for connection authentication.
|
||||
* @param mixed[] $driverOptions Additional parameters to use for the connection.
|
||||
* @param string|null $host Host address to connect to.
|
||||
* @param int|null $port Port to use for the connection (default to SQL Anywhere standard port 2638).
|
||||
* @param string|null $server Database server name on the host to connect to.
|
||||
* SQL Anywhere allows multiple database server instances on the same host,
|
||||
* therefore specifying the server instance name to use is mandatory.
|
||||
* @param string|null $dbname Name of the database on the server instance to connect to.
|
||||
* @param string $username User name to use for connection authentication.
|
||||
* @param string $password Password to use for connection authentication.
|
||||
* @param mixed[] $driverOptions Additional parameters to use for the connection.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function buildDsn($host, $port, $server, $dbname, $username = null, $password = null, array $driverOptions = [])
|
||||
{
|
||||
private function buildDsn(
|
||||
$host,
|
||||
$port,
|
||||
$server,
|
||||
$dbname,
|
||||
$username = null,
|
||||
$password = null,
|
||||
array $driverOptions = []
|
||||
) {
|
||||
$host = $host ?: 'localhost';
|
||||
$port = $port ?: 2638;
|
||||
|
||||
|
@@ -3,8 +3,11 @@
|
||||
namespace Doctrine\DBAL\Driver\SQLAnywhere;
|
||||
|
||||
use Doctrine\DBAL\Driver\Connection;
|
||||
use Doctrine\DBAL\Driver\Result;
|
||||
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
use Doctrine\Deprecations\Deprecation;
|
||||
|
||||
use function assert;
|
||||
use function func_get_args;
|
||||
use function is_float;
|
||||
@@ -25,6 +28,8 @@ use function sasql_set_option;
|
||||
|
||||
/**
|
||||
* SAP Sybase SQL Anywhere implementation of the Connection interface.
|
||||
*
|
||||
* @deprecated Support for SQLAnywhere will be removed in 3.0.
|
||||
*/
|
||||
class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection
|
||||
{
|
||||
@@ -34,6 +39,8 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection
|
||||
/**
|
||||
* Connects to database with given connection string.
|
||||
*
|
||||
* @internal The connection can be only instantiated by its driver.
|
||||
*
|
||||
* @param string $dsn The connection string.
|
||||
* @param bool $persistent Whether or not to establish a persistent connection.
|
||||
*
|
||||
@@ -41,6 +48,12 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection
|
||||
*/
|
||||
public function __construct($dsn, $persistent = false)
|
||||
{
|
||||
Deprecation::trigger(
|
||||
'doctrine/dbal',
|
||||
'https://github.com/doctrine/dbal/pull/4077',
|
||||
'The SQLAnywhere driver is deprecated'
|
||||
);
|
||||
|
||||
$this->connection = $persistent ? @sasql_pconnect($dsn) : @sasql_connect($dsn);
|
||||
|
||||
if (! is_resource($this->connection)) {
|
||||
@@ -90,6 +103,8 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @deprecated The error information is available via exceptions.
|
||||
*/
|
||||
public function errorCode()
|
||||
{
|
||||
@@ -98,6 +113,8 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @deprecated The error information is available via exceptions.
|
||||
*/
|
||||
public function errorInfo()
|
||||
{
|
||||
@@ -107,9 +124,9 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function exec($statement)
|
||||
public function exec($sql)
|
||||
{
|
||||
if (sasql_real_query($this->connection, $statement) === false) {
|
||||
if (sasql_real_query($this->connection, $sql) === false) {
|
||||
throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
|
||||
}
|
||||
|
||||
@@ -121,7 +138,13 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection
|
||||
*/
|
||||
public function getServerVersion()
|
||||
{
|
||||
$version = $this->query("SELECT PROPERTY('ProductVersion')")->fetchColumn();
|
||||
$stmt = $this->query("SELECT PROPERTY('ProductVersion')");
|
||||
|
||||
if ($stmt instanceof Result) {
|
||||
$version = $stmt->fetchOne();
|
||||
} else {
|
||||
$version = $stmt->fetchColumn();
|
||||
}
|
||||
|
||||
assert(is_string($version));
|
||||
|
||||
@@ -137,15 +160,21 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection
|
||||
return sasql_insert_id($this->connection);
|
||||
}
|
||||
|
||||
return $this->query('SELECT ' . $name . '.CURRVAL')->fetchColumn();
|
||||
$stmt = $this->query('SELECT ' . $name . '.CURRVAL');
|
||||
|
||||
if ($stmt instanceof Result) {
|
||||
return $stmt->fetchOne();
|
||||
}
|
||||
|
||||
return $stmt->fetchColumn();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function prepare($prepareString)
|
||||
public function prepare($sql)
|
||||
{
|
||||
return new SQLAnywhereStatement($this->connection, $prepareString);
|
||||
return new SQLAnywhereStatement($this->connection, $sql);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,13 +193,13 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function quote($input, $type = ParameterType::STRING)
|
||||
public function quote($value, $type = ParameterType::STRING)
|
||||
{
|
||||
if (is_int($input) || is_float($input)) {
|
||||
return $input;
|
||||
if (is_int($value) || is_float($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
return "'" . sasql_escape_string($this->connection, $input) . "'";
|
||||
return "'" . sasql_escape_string($this->connection, $value) . "'";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -178,6 +207,12 @@ class SQLAnywhereConnection 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 true;
|
||||
}
|
||||
|
||||
|
@@ -4,7 +4,7 @@ namespace Doctrine\DBAL\Driver\SQLAnywhere;
|
||||
|
||||
use Doctrine\DBAL\Driver\AbstractDriverException;
|
||||
use InvalidArgumentException;
|
||||
use function is_resource;
|
||||
|
||||
use function sasql_error;
|
||||
use function sasql_errorcode;
|
||||
use function sasql_sqlstate;
|
||||
@@ -13,6 +13,10 @@ use function sasql_stmt_error;
|
||||
|
||||
/**
|
||||
* SAP Sybase SQL Anywhere driver exception.
|
||||
*
|
||||
* @deprecated Support for SQLAnywhere will be removed in 3.0.
|
||||
*
|
||||
* @psalm-immutable
|
||||
*/
|
||||
class SQLAnywhereException extends AbstractDriverException
|
||||
{
|
||||
@@ -28,14 +32,6 @@ class SQLAnywhereException extends AbstractDriverException
|
||||
*/
|
||||
public static function fromSQLAnywhereError($conn = null, $stmt = null)
|
||||
{
|
||||
if ($conn !== null && ! is_resource($conn)) {
|
||||
throw new InvalidArgumentException('Invalid SQL Anywhere connection resource given: ' . $conn);
|
||||
}
|
||||
|
||||
if ($stmt !== null && ! is_resource($stmt)) {
|
||||
throw new InvalidArgumentException('Invalid SQL Anywhere statement resource given: ' . $stmt);
|
||||
}
|
||||
|
||||
$state = $conn ? sasql_sqlstate($conn) : sasql_sqlstate();
|
||||
$code = null;
|
||||
$message = null;
|
||||
|
@@ -2,6 +2,9 @@
|
||||
|
||||
namespace Doctrine\DBAL\Driver\SQLAnywhere;
|
||||
|
||||
use Doctrine\DBAL\Driver\Exception;
|
||||
use Doctrine\DBAL\Driver\FetchUtils;
|
||||
use Doctrine\DBAL\Driver\Result;
|
||||
use Doctrine\DBAL\Driver\Statement;
|
||||
use Doctrine\DBAL\Driver\StatementIterator;
|
||||
use Doctrine\DBAL\FetchMode;
|
||||
@@ -10,14 +13,16 @@ use IteratorAggregate;
|
||||
use PDO;
|
||||
use ReflectionClass;
|
||||
use ReflectionObject;
|
||||
use ReturnTypeWillChange;
|
||||
use stdClass;
|
||||
use const SASQL_BOTH;
|
||||
|
||||
use function array_key_exists;
|
||||
use function assert;
|
||||
use function func_get_args;
|
||||
use function func_num_args;
|
||||
use function gettype;
|
||||
use function is_array;
|
||||
use function is_numeric;
|
||||
use function is_int;
|
||||
use function is_object;
|
||||
use function is_resource;
|
||||
use function is_string;
|
||||
@@ -36,10 +41,14 @@ use function sasql_stmt_reset;
|
||||
use function sasql_stmt_result_metadata;
|
||||
use function sprintf;
|
||||
|
||||
use const SASQL_BOTH;
|
||||
|
||||
/**
|
||||
* SAP SQL Anywhere implementation of the Statement interface.
|
||||
*
|
||||
* @deprecated Support for SQLAnywhere will be removed in 3.0.
|
||||
*/
|
||||
class SQLAnywhereStatement implements IteratorAggregate, Statement
|
||||
class SQLAnywhereStatement implements IteratorAggregate, Statement, Result
|
||||
{
|
||||
/** @var resource The connection resource. */
|
||||
private $conn;
|
||||
@@ -53,15 +62,20 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
|
||||
/** @var int Default fetch mode to use. */
|
||||
private $defaultFetchMode = FetchMode::MIXED;
|
||||
|
||||
/** @var resource The result set resource to fetch. */
|
||||
/** @var resource|null The result set resource to fetch. */
|
||||
private $result;
|
||||
|
||||
/** @var resource The prepared SQL statement to execute. */
|
||||
private $stmt;
|
||||
|
||||
/** @var mixed[] The references to bound parameter values. */
|
||||
private $boundValues = [];
|
||||
|
||||
/**
|
||||
* Prepares given statement for given connection.
|
||||
*
|
||||
* @internal The statement can be only instantiated by its driver connection.
|
||||
*
|
||||
* @param resource $conn The connection resource to use.
|
||||
* @param string $sql The SQL statement to prepare.
|
||||
*
|
||||
@@ -86,8 +100,10 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
|
||||
*
|
||||
* @throws SQLAnywhereException
|
||||
*/
|
||||
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null)
|
||||
public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null)
|
||||
{
|
||||
assert(is_int($param));
|
||||
|
||||
switch ($type) {
|
||||
case ParameterType::INTEGER:
|
||||
case ParameterType::BOOLEAN:
|
||||
@@ -108,7 +124,9 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
|
||||
throw new SQLAnywhereException('Unknown type: ' . $type);
|
||||
}
|
||||
|
||||
if (! sasql_stmt_bind_param_ex($this->stmt, $column - 1, $variable, $type, $variable === null)) {
|
||||
$this->boundValues[$param] =& $variable;
|
||||
|
||||
if (! sasql_stmt_bind_param_ex($this->stmt, $param - 1, $variable, $type, $variable === null)) {
|
||||
throw SQLAnywhereException::fromSQLAnywhereError($this->conn, $this->stmt);
|
||||
}
|
||||
|
||||
@@ -120,12 +138,16 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
|
||||
*/
|
||||
public function bindValue($param, $value, $type = ParameterType::STRING)
|
||||
{
|
||||
assert(is_int($param));
|
||||
|
||||
return $this->bindParam($param, $value, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @deprecated Use free() instead.
|
||||
*
|
||||
* @throws SQLAnywhereException
|
||||
*/
|
||||
public function closeCursor()
|
||||
@@ -147,6 +169,8 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @deprecated The error information is available via exceptions.
|
||||
*/
|
||||
public function errorCode()
|
||||
{
|
||||
@@ -155,6 +179,8 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @deprecated The error information is available via exceptions.
|
||||
*/
|
||||
public function errorInfo()
|
||||
{
|
||||
@@ -172,9 +198,11 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
|
||||
$hasZeroIndex = array_key_exists(0, $params);
|
||||
|
||||
foreach ($params as $key => $val) {
|
||||
$key = $hasZeroIndex && is_numeric($key) ? $key + 1 : $key;
|
||||
|
||||
$this->bindValue($key, $val);
|
||||
if ($hasZeroIndex && is_int($key)) {
|
||||
$this->bindValue($key + 1, $val);
|
||||
} else {
|
||||
$this->bindValue($key, $val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,6 +218,8 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @deprecated Use fetchNumeric(), fetchAssociative() or fetchOne() instead.
|
||||
*
|
||||
* @throws SQLAnywhereException
|
||||
*/
|
||||
public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
|
||||
@@ -241,6 +271,8 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @deprecated Use fetchAllNumeric(), fetchAllAssociative() or fetchFirstColumn() instead.
|
||||
*/
|
||||
public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null)
|
||||
{
|
||||
@@ -248,19 +280,21 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
|
||||
|
||||
switch ($fetchMode) {
|
||||
case FetchMode::CUSTOM_OBJECT:
|
||||
while ($row = $this->fetch(...func_get_args())) {
|
||||
while (($row = $this->fetch(...func_get_args())) !== false) {
|
||||
$rows[] = $row;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case FetchMode::COLUMN:
|
||||
while ($row = $this->fetchColumn()) {
|
||||
while (($row = $this->fetchColumn()) !== false) {
|
||||
$rows[] = $row;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
while ($row = $this->fetch($fetchMode)) {
|
||||
while (($row = $this->fetch($fetchMode)) !== false) {
|
||||
$rows[] = $row;
|
||||
}
|
||||
}
|
||||
@@ -270,6 +304,8 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @deprecated Use fetchOne() instead.
|
||||
*/
|
||||
public function fetchColumn($columnIndex = 0)
|
||||
{
|
||||
@@ -284,12 +320,79 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @deprecated Use iterateNumeric(), iterateAssociative() or iterateColumn() instead.
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function getIterator()
|
||||
{
|
||||
return new StatementIterator($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function fetchNumeric()
|
||||
{
|
||||
if (! is_resource($this->result)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return sasql_fetch_row($this->result);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fetchAssociative()
|
||||
{
|
||||
if (! is_resource($this->result)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return sasql_fetch_assoc($this->result);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function fetchOne()
|
||||
{
|
||||
return FetchUtils::fetchOne($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int,array<int,mixed>>
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function fetchAllNumeric(): array
|
||||
{
|
||||
return FetchUtils::fetchAllNumeric($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int,array<string,mixed>>
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function fetchAllAssociative(): array
|
||||
{
|
||||
return FetchUtils::fetchAllAssociative($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int,mixed>
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function fetchFirstColumn(): array
|
||||
{
|
||||
return FetchUtils::fetchFirstColumn($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -298,22 +401,31 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
|
||||
return sasql_stmt_affected_rows($this->stmt);
|
||||
}
|
||||
|
||||
public function free(): void
|
||||
{
|
||||
sasql_stmt_reset($this->stmt);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @deprecated Use one of the fetch- or iterate-related methods.
|
||||
*/
|
||||
public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
|
||||
{
|
||||
$this->defaultFetchMode = $fetchMode;
|
||||
$this->defaultFetchClass = $arg2 ?: $this->defaultFetchClass;
|
||||
$this->defaultFetchClassCtorArgs = $arg3 ? (array) $arg3 : $this->defaultFetchClassCtorArgs;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Casts a stdClass object to the given class name mapping its' properties.
|
||||
*
|
||||
* @param stdClass $sourceObject Object to cast from.
|
||||
* @param string|object $destinationClass Name of the class or class instance to cast to.
|
||||
* @param mixed[] $ctorArgs Arguments to use for constructing the destination class instance.
|
||||
* @param stdClass $sourceObject Object to cast from.
|
||||
* @param class-string|object $destinationClass Name of the class or class instance to cast to.
|
||||
* @param mixed[] $ctorArgs Arguments to use for constructing the destination class instance.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
|
Reference in New Issue
Block a user