updated-packages
This commit is contained in:
@@ -2,24 +2,30 @@
|
||||
|
||||
namespace Doctrine\DBAL\Driver\PDOSqlsrv;
|
||||
|
||||
use Doctrine\DBAL\Driver\PDOConnection;
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
use PDO;
|
||||
use function strpos;
|
||||
use function substr;
|
||||
use Doctrine\DBAL\Driver\PDO;
|
||||
use Doctrine\DBAL\Driver\Result;
|
||||
|
||||
/**
|
||||
* Sqlsrv Connection implementation.
|
||||
*
|
||||
* @deprecated Use {@link PDO\SQLSrv\Connection} instead.
|
||||
*/
|
||||
class Connection extends PDOConnection
|
||||
class Connection extends PDO\Connection
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @internal The connection can be only instantiated by its driver.
|
||||
*
|
||||
* @param string $dsn
|
||||
* @param string|null $user
|
||||
* @param string|null $password
|
||||
* @param mixed[]|null $options
|
||||
*/
|
||||
public function __construct($dsn, $user = null, $password = null, ?array $options = null)
|
||||
{
|
||||
parent::__construct($dsn, $user, $password, $options);
|
||||
$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, [Statement::class, []]);
|
||||
$this->setAttribute(\PDO::ATTR_STATEMENT_CLASS, [PDO\SQLSrv\Statement::class, []]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,21 +40,10 @@ class Connection extends PDOConnection
|
||||
$stmt = $this->prepare('SELECT CONVERT(VARCHAR(MAX), current_value) FROM sys.sequences WHERE name = ?');
|
||||
$stmt->execute([$name]);
|
||||
|
||||
return $stmt->fetchColumn();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function quote($value, $type = ParameterType::STRING)
|
||||
{
|
||||
$val = parent::quote($value, $type);
|
||||
|
||||
// Fix for a driver version terminating all values with null byte
|
||||
if (strpos($val, "\0") !== false) {
|
||||
$val = substr($val, 0, -1);
|
||||
if ($stmt instanceof Result) {
|
||||
return $stmt->fetchOne();
|
||||
}
|
||||
|
||||
return $val;
|
||||
return $stmt->fetchColumn();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,17 @@
|
||||
namespace Doctrine\DBAL\Driver\PDOSqlsrv;
|
||||
|
||||
use Doctrine\DBAL\Driver\AbstractSQLServerDriver;
|
||||
use Doctrine\DBAL\Driver\AbstractSQLServerDriver\Exception\PortWithoutHost;
|
||||
use Doctrine\DBAL\Driver\PDO;
|
||||
use Doctrine\Deprecations\Deprecation;
|
||||
|
||||
use function is_int;
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
* The PDO-based Sqlsrv driver.
|
||||
*
|
||||
* @deprecated Use {@link PDO\SQLSrv\Driver} instead.
|
||||
*/
|
||||
class Driver extends AbstractSQLServerDriver
|
||||
{
|
||||
@@ -16,13 +22,21 @@ class Driver extends AbstractSQLServerDriver
|
||||
*/
|
||||
public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
|
||||
{
|
||||
[$driverOptions, $connectionOptions] = $this->splitOptions($driverOptions);
|
||||
$pdoOptions = $dsnOptions = [];
|
||||
|
||||
return new Connection(
|
||||
$this->_constructPdoDsn($params, $connectionOptions),
|
||||
foreach ($driverOptions as $option => $value) {
|
||||
if (is_int($option)) {
|
||||
$pdoOptions[$option] = $value;
|
||||
} else {
|
||||
$dsnOptions[$option] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return new PDO\SQLSrv\Connection(
|
||||
$this->_constructPdoDsn($params, $dsnOptions),
|
||||
$username,
|
||||
$password,
|
||||
$driverOptions
|
||||
$pdoOptions
|
||||
);
|
||||
}
|
||||
|
||||
@@ -40,10 +54,12 @@ class Driver extends AbstractSQLServerDriver
|
||||
|
||||
if (isset($params['host'])) {
|
||||
$dsn .= $params['host'];
|
||||
}
|
||||
|
||||
if (isset($params['port']) && ! empty($params['port'])) {
|
||||
$dsn .= ',' . $params['port'];
|
||||
if (isset($params['port'])) {
|
||||
$dsn .= ',' . $params['port'];
|
||||
}
|
||||
} elseif (isset($params['port'])) {
|
||||
throw PortWithoutHost::new();
|
||||
}
|
||||
|
||||
if (isset($params['dbname'])) {
|
||||
@@ -57,35 +73,12 @@ class Driver extends AbstractSQLServerDriver
|
||||
return $dsn . $this->getConnectionOptionsDsn($connectionOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Separates a connection options from a driver options
|
||||
*
|
||||
* @param int[]|string[] $options
|
||||
*
|
||||
* @return int[][]|string[][]
|
||||
*/
|
||||
private function splitOptions(array $options) : array
|
||||
{
|
||||
$driverOptions = [];
|
||||
$connectionOptions = [];
|
||||
|
||||
foreach ($options as $optionKey => $optionValue) {
|
||||
if (is_int($optionKey)) {
|
||||
$driverOptions[$optionKey] = $optionValue;
|
||||
} else {
|
||||
$connectionOptions[$optionKey] = $optionValue;
|
||||
}
|
||||
}
|
||||
|
||||
return [$driverOptions, $connectionOptions];
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a connection options array to the DSN
|
||||
*
|
||||
* @param string[] $connectionOptions
|
||||
*/
|
||||
private function getConnectionOptionsDsn(array $connectionOptions) : string
|
||||
private function getConnectionOptionsDsn(array $connectionOptions): string
|
||||
{
|
||||
$connectionOptionsDsn = '';
|
||||
|
||||
@@ -98,9 +91,17 @@ class Driver extends AbstractSQLServerDriver
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
Deprecation::trigger(
|
||||
'doctrine/dbal',
|
||||
'https://github.com/doctrine/dbal/issues/3580',
|
||||
'Driver::getName() is deprecated'
|
||||
);
|
||||
|
||||
return 'pdo_sqlsrv';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,27 +2,38 @@
|
||||
|
||||
namespace Doctrine\DBAL\Driver\PDOSqlsrv;
|
||||
|
||||
use Doctrine\DBAL\Driver\PDOStatement;
|
||||
use Doctrine\DBAL\Driver\PDO;
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
use PDO;
|
||||
|
||||
/**
|
||||
* PDO SQL Server Statement
|
||||
*
|
||||
* @deprecated Use {@link PDO\SQLSrv\Statement} instead.
|
||||
*/
|
||||
class Statement extends PDOStatement
|
||||
class Statement extends PDO\Statement
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null, $driverOptions = null)
|
||||
public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null, $driverOptions = null)
|
||||
{
|
||||
if (($type === ParameterType::LARGE_OBJECT || $type === ParameterType::BINARY)
|
||||
&& $driverOptions === null
|
||||
) {
|
||||
$driverOptions = PDO::SQLSRV_ENCODING_BINARY;
|
||||
switch ($type) {
|
||||
case ParameterType::LARGE_OBJECT:
|
||||
case ParameterType::BINARY:
|
||||
if ($driverOptions === null) {
|
||||
$driverOptions = \PDO::SQLSRV_ENCODING_BINARY;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case ParameterType::ASCII:
|
||||
$type = ParameterType::STRING;
|
||||
$length = 0;
|
||||
$driverOptions = \PDO::SQLSRV_ENCODING_SYSTEM;
|
||||
break;
|
||||
}
|
||||
|
||||
return parent::bindParam($column, $variable, $type, $length, $driverOptions);
|
||||
return parent::bindParam($param, $variable, $type, $length ?? 0, $driverOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user