updated-packages
This commit is contained in:
7
vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/SQLSrv/Connection.php
vendored
Normal file
7
vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/SQLSrv/Connection.php
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\DBAL\Driver\SQLSrv;
|
||||
|
||||
final class Connection extends SQLSrvConnection
|
||||
{
|
||||
}
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace Doctrine\DBAL\Driver\SQLSrv;
|
||||
|
||||
use Doctrine\DBAL\Driver\AbstractSQLServerDriver;
|
||||
use Doctrine\DBAL\Driver\AbstractSQLServerDriver\Exception\PortWithoutHost;
|
||||
use Doctrine\Deprecations\Deprecation;
|
||||
|
||||
/**
|
||||
* Driver for ext/sqlsrv.
|
||||
@@ -14,13 +16,16 @@ class Driver extends AbstractSQLServerDriver
|
||||
*/
|
||||
public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
|
||||
{
|
||||
if (! isset($params['host'])) {
|
||||
throw new SQLSrvException("Missing 'host' in configuration for sqlsrv driver.");
|
||||
}
|
||||
$serverName = '';
|
||||
|
||||
$serverName = $params['host'];
|
||||
if (isset($params['port'])) {
|
||||
$serverName .= ', ' . $params['port'];
|
||||
if (isset($params['host'])) {
|
||||
$serverName = $params['host'];
|
||||
|
||||
if (isset($params['port'])) {
|
||||
$serverName .= ',' . $params['port'];
|
||||
}
|
||||
} elseif (isset($params['port'])) {
|
||||
throw PortWithoutHost::new();
|
||||
}
|
||||
|
||||
if (isset($params['dbname'])) {
|
||||
@@ -43,14 +48,22 @@ class Driver extends AbstractSQLServerDriver
|
||||
$driverOptions['ReturnDatesAsStrings'] = 1;
|
||||
}
|
||||
|
||||
return new SQLSrvConnection($serverName, $driverOptions);
|
||||
return new Connection($serverName, $driverOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
Deprecation::trigger(
|
||||
'doctrine/dbal',
|
||||
'https://github.com/doctrine/dbal/issues/3580',
|
||||
'Driver::getName() is deprecated'
|
||||
);
|
||||
|
||||
return 'sqlsrv';
|
||||
}
|
||||
}
|
||||
|
||||
47
vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/SQLSrv/Exception/Error.php
vendored
Normal file
47
vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/SQLSrv/Exception/Error.php
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\DBAL\Driver\SQLSrv\Exception;
|
||||
|
||||
use Doctrine\DBAL\Driver\SQLSrv\SQLSrvException;
|
||||
|
||||
use function rtrim;
|
||||
use function sqlsrv_errors;
|
||||
|
||||
use const SQLSRV_ERR_ERRORS;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @psalm-immutable
|
||||
*/
|
||||
final class Error extends SQLSrvException
|
||||
{
|
||||
public static function new(): self
|
||||
{
|
||||
$message = '';
|
||||
$sqlState = null;
|
||||
$errorCode = null;
|
||||
|
||||
foreach ((array) sqlsrv_errors(SQLSRV_ERR_ERRORS) as $error) {
|
||||
$message .= 'SQLSTATE [' . $error['SQLSTATE'] . ', ' . $error['code'] . ']: ' . $error['message'] . "\n";
|
||||
|
||||
if ($sqlState === null) {
|
||||
$sqlState = $error['SQLSTATE'];
|
||||
}
|
||||
|
||||
if ($errorCode !== null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$errorCode = $error['code'];
|
||||
}
|
||||
|
||||
if (! $message) {
|
||||
$message = 'SQL Server error occurred but no error message was retrieved from driver.';
|
||||
}
|
||||
|
||||
return new self(rtrim($message), $sqlState, $errorCode);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,8 @@ namespace Doctrine\DBAL\Driver\SQLSrv;
|
||||
|
||||
/**
|
||||
* Last Id Data Container.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class LastInsertId
|
||||
{
|
||||
@@ -12,6 +14,8 @@ class LastInsertId
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
|
||||
@@ -2,10 +2,13 @@
|
||||
|
||||
namespace Doctrine\DBAL\Driver\SQLSrv;
|
||||
|
||||
use Doctrine\DBAL\Driver\Connection;
|
||||
use Doctrine\DBAL\Driver\Connection as ConnectionInterface;
|
||||
use Doctrine\DBAL\Driver\Result;
|
||||
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
|
||||
use Doctrine\DBAL\Driver\SQLSrv\Exception\Error;
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
use const SQLSRV_ERR_ERRORS;
|
||||
use Doctrine\Deprecations\Deprecation;
|
||||
|
||||
use function func_get_args;
|
||||
use function is_float;
|
||||
use function is_int;
|
||||
@@ -21,10 +24,14 @@ use function sqlsrv_rows_affected;
|
||||
use function sqlsrv_server_info;
|
||||
use function str_replace;
|
||||
|
||||
use const SQLSRV_ERR_ERRORS;
|
||||
|
||||
/**
|
||||
* SQL Server implementation for the Connection interface.
|
||||
*
|
||||
* @deprecated Use {@link Connection} instead
|
||||
*/
|
||||
class SQLSrvConnection implements Connection, ServerInfoAwareConnection
|
||||
class SQLSrvConnection implements ConnectionInterface, ServerInfoAwareConnection
|
||||
{
|
||||
/** @var resource */
|
||||
protected $conn;
|
||||
@@ -33,6 +40,8 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection
|
||||
protected $lastInsertId;
|
||||
|
||||
/**
|
||||
* @internal The connection can be only instantiated by its driver.
|
||||
*
|
||||
* @param string $serverName
|
||||
* @param mixed[] $connectionOptions
|
||||
*
|
||||
@@ -41,13 +50,16 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection
|
||||
public function __construct($serverName, $connectionOptions)
|
||||
{
|
||||
if (! sqlsrv_configure('WarningsReturnAsErrors', 0)) {
|
||||
throw SQLSrvException::fromSqlSrvErrors();
|
||||
throw Error::new();
|
||||
}
|
||||
|
||||
$this->conn = sqlsrv_connect($serverName, $connectionOptions);
|
||||
if (! $this->conn) {
|
||||
throw SQLSrvException::fromSqlSrvErrors();
|
||||
$conn = sqlsrv_connect($serverName, $connectionOptions);
|
||||
|
||||
if ($conn === false) {
|
||||
throw Error::new();
|
||||
}
|
||||
|
||||
$this->conn = $conn;
|
||||
$this->lastInsertId = new LastInsertId();
|
||||
}
|
||||
|
||||
@@ -66,6 +78,12 @@ class SQLSrvConnection 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;
|
||||
}
|
||||
|
||||
@@ -74,7 +92,7 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection
|
||||
*/
|
||||
public function prepare($sql)
|
||||
{
|
||||
return new SQLSrvStatement($this->conn, $sql, $this->lastInsertId);
|
||||
return new Statement($this->conn, $sql, $this->lastInsertId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,7 +115,9 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection
|
||||
{
|
||||
if (is_int($value)) {
|
||||
return $value;
|
||||
} elseif (is_float($value)) {
|
||||
}
|
||||
|
||||
if (is_float($value)) {
|
||||
return sprintf('%F', $value);
|
||||
}
|
||||
|
||||
@@ -107,15 +127,21 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function exec($statement)
|
||||
public function exec($sql)
|
||||
{
|
||||
$stmt = sqlsrv_query($this->conn, $statement);
|
||||
$stmt = sqlsrv_query($this->conn, $sql);
|
||||
|
||||
if ($stmt === false) {
|
||||
throw SQLSrvException::fromSqlSrvErrors();
|
||||
throw Error::new();
|
||||
}
|
||||
|
||||
return sqlsrv_rows_affected($stmt);
|
||||
$rowsAffected = sqlsrv_rows_affected($stmt);
|
||||
|
||||
if ($rowsAffected === false) {
|
||||
throw Error::new();
|
||||
}
|
||||
|
||||
return $rowsAffected;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,6 +156,10 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection
|
||||
$stmt = $this->query('SELECT @@IDENTITY');
|
||||
}
|
||||
|
||||
if ($stmt instanceof Result) {
|
||||
return $stmt->fetchOne();
|
||||
}
|
||||
|
||||
return $stmt->fetchColumn();
|
||||
}
|
||||
|
||||
@@ -139,8 +169,10 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection
|
||||
public function beginTransaction()
|
||||
{
|
||||
if (! sqlsrv_begin_transaction($this->conn)) {
|
||||
throw SQLSrvException::fromSqlSrvErrors();
|
||||
throw Error::new();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,8 +181,10 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection
|
||||
public function commit()
|
||||
{
|
||||
if (! sqlsrv_commit($this->conn)) {
|
||||
throw SQLSrvException::fromSqlSrvErrors();
|
||||
throw Error::new();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,12 +193,16 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection
|
||||
public function rollBack()
|
||||
{
|
||||
if (! sqlsrv_rollback($this->conn)) {
|
||||
throw SQLSrvException::fromSqlSrvErrors();
|
||||
throw Error::new();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @deprecated The error information is available via exceptions.
|
||||
*/
|
||||
public function errorCode()
|
||||
{
|
||||
@@ -173,14 +211,16 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection
|
||||
return $errors[0]['code'];
|
||||
}
|
||||
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @deprecated The error information is available via exceptions.
|
||||
*/
|
||||
public function errorInfo()
|
||||
{
|
||||
return sqlsrv_errors(SQLSRV_ERR_ERRORS);
|
||||
return (array) sqlsrv_errors(SQLSRV_ERR_ERRORS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,41 +3,22 @@
|
||||
namespace Doctrine\DBAL\Driver\SQLSrv;
|
||||
|
||||
use Doctrine\DBAL\Driver\AbstractDriverException;
|
||||
use const SQLSRV_ERR_ERRORS;
|
||||
use function rtrim;
|
||||
use function sqlsrv_errors;
|
||||
use Doctrine\DBAL\Driver\SQLSrv\Exception\Error;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link \Doctrine\DBAL\Driver\Exception} instead
|
||||
*
|
||||
* @psalm-immutable
|
||||
*/
|
||||
class SQLSrvException extends AbstractDriverException
|
||||
{
|
||||
/**
|
||||
* Helper method to turn sql server errors into exception.
|
||||
*
|
||||
* @return \Doctrine\DBAL\Driver\SQLSrv\SQLSrvException
|
||||
* @return SQLSrvException
|
||||
*/
|
||||
public static function fromSqlSrvErrors()
|
||||
{
|
||||
$errors = sqlsrv_errors(SQLSRV_ERR_ERRORS);
|
||||
$message = '';
|
||||
$sqlState = null;
|
||||
$errorCode = null;
|
||||
|
||||
foreach ($errors as $error) {
|
||||
$message .= 'SQLSTATE [' . $error['SQLSTATE'] . ', ' . $error['code'] . ']: ' . $error['message'] . "\n";
|
||||
|
||||
if ($sqlState === null) {
|
||||
$sqlState = $error['SQLSTATE'];
|
||||
}
|
||||
|
||||
if ($errorCode !== null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$errorCode = $error['code'];
|
||||
}
|
||||
if (! $message) {
|
||||
$message = 'SQL Server error occurred but no error message was retrieved from driver.';
|
||||
}
|
||||
|
||||
return new self(rtrim($message), $sqlState, $errorCode);
|
||||
return Error::new();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
|
||||
namespace Doctrine\DBAL\Driver\SQLSrv;
|
||||
|
||||
use Doctrine\DBAL\Driver\Statement;
|
||||
use Doctrine\DBAL\Driver\FetchUtils;
|
||||
use Doctrine\DBAL\Driver\Result;
|
||||
use Doctrine\DBAL\Driver\SQLSrv\Exception\Error;
|
||||
use Doctrine\DBAL\Driver\Statement as StatementInterface;
|
||||
use Doctrine\DBAL\Driver\StatementIterator;
|
||||
use Doctrine\DBAL\FetchMode;
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
use IteratorAggregate;
|
||||
use PDO;
|
||||
use const SQLSRV_ENC_BINARY;
|
||||
use const SQLSRV_ERR_ERRORS;
|
||||
use const SQLSRV_FETCH_ASSOC;
|
||||
use const SQLSRV_FETCH_BOTH;
|
||||
use const SQLSRV_FETCH_NUMERIC;
|
||||
use const SQLSRV_PARAM_IN;
|
||||
use ReturnTypeWillChange;
|
||||
|
||||
use function array_key_exists;
|
||||
use function count;
|
||||
use function func_get_args;
|
||||
use function in_array;
|
||||
use function is_int;
|
||||
use function is_numeric;
|
||||
use function sqlsrv_errors;
|
||||
use function sqlsrv_execute;
|
||||
@@ -34,10 +34,20 @@ use function sqlsrv_rows_affected;
|
||||
use function SQLSRV_SQLTYPE_VARBINARY;
|
||||
use function stripos;
|
||||
|
||||
use const SQLSRV_ENC_BINARY;
|
||||
use const SQLSRV_ENC_CHAR;
|
||||
use const SQLSRV_ERR_ERRORS;
|
||||
use const SQLSRV_FETCH_ASSOC;
|
||||
use const SQLSRV_FETCH_BOTH;
|
||||
use const SQLSRV_FETCH_NUMERIC;
|
||||
use const SQLSRV_PARAM_IN;
|
||||
|
||||
/**
|
||||
* SQL Server Statement.
|
||||
*
|
||||
* @deprecated Use {@link Statement} instead
|
||||
*/
|
||||
class SQLSrvStatement implements IteratorAggregate, Statement
|
||||
class SQLSrvStatement implements IteratorAggregate, StatementInterface, Result
|
||||
{
|
||||
/**
|
||||
* The SQLSRV Resource.
|
||||
@@ -122,10 +132,14 @@ class SQLSrvStatement implements IteratorAggregate, Statement
|
||||
|
||||
/**
|
||||
* Append to any INSERT query to retrieve the last insert id.
|
||||
*
|
||||
* @deprecated This constant has been deprecated and will be made private in 3.0
|
||||
*/
|
||||
public const LAST_INSERT_ID_SQL = ';SELECT SCOPE_IDENTITY() AS LastInsertId;';
|
||||
|
||||
/**
|
||||
* @internal The statement can be only instantiated by its driver connection.
|
||||
*
|
||||
* @param resource $conn
|
||||
* @param string $sql
|
||||
*/
|
||||
@@ -155,42 +169,38 @@ class SQLSrvStatement implements IteratorAggregate, Statement
|
||||
|
||||
$this->variables[$param] = $value;
|
||||
$this->types[$param] = $type;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null)
|
||||
public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null)
|
||||
{
|
||||
if (! is_numeric($column)) {
|
||||
throw new SQLSrvException('sqlsrv does not support named parameters to queries, use question mark (?) placeholders instead.');
|
||||
if (! is_numeric($param)) {
|
||||
throw new SQLSrvException(
|
||||
'sqlsrv does not support named parameters to queries, use question mark (?) placeholders instead.'
|
||||
);
|
||||
}
|
||||
|
||||
$this->variables[$column] =& $variable;
|
||||
$this->types[$column] = $type;
|
||||
$this->variables[$param] =& $variable;
|
||||
$this->types[$param] = $type;
|
||||
|
||||
// unset the statement resource if it exists as the new one will need to be bound to the new variable
|
||||
$this->stmt = null;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @deprecated Use free() instead.
|
||||
*/
|
||||
public function closeCursor()
|
||||
{
|
||||
// not having the result means there's nothing to close
|
||||
if (! $this->result) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// emulate it by fetching and discarding rows, similarly to what PDO does in this case
|
||||
// @link http://php.net/manual/en/pdostatement.closecursor.php
|
||||
// @link https://github.com/php/php-src/blob/php-7.0.11/ext/pdo/pdo_stmt.c#L2075
|
||||
// deliberately do not consider multiple result sets, since doctrine/dbal doesn't support them
|
||||
while (sqlsrv_fetch($this->stmt)) {
|
||||
}
|
||||
|
||||
$this->result = false;
|
||||
$this->free();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -200,11 +210,17 @@ class SQLSrvStatement implements IteratorAggregate, Statement
|
||||
*/
|
||||
public function columnCount()
|
||||
{
|
||||
return sqlsrv_num_fields($this->stmt);
|
||||
if ($this->stmt === null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return sqlsrv_num_fields($this->stmt) ?: 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @deprecated The error information is available via exceptions.
|
||||
*/
|
||||
public function errorCode()
|
||||
{
|
||||
@@ -218,10 +234,12 @@ class SQLSrvStatement implements IteratorAggregate, Statement
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @deprecated The error information is available via exceptions.
|
||||
*/
|
||||
public function errorInfo()
|
||||
{
|
||||
return sqlsrv_errors(SQLSRV_ERR_ERRORS);
|
||||
return (array) sqlsrv_errors(SQLSRV_ERR_ERRORS);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -231,9 +249,13 @@ class SQLSrvStatement implements IteratorAggregate, Statement
|
||||
{
|
||||
if ($params) {
|
||||
$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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,7 +264,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
|
||||
}
|
||||
|
||||
if (! sqlsrv_execute($this->stmt)) {
|
||||
throw SQLSrvException::fromSqlSrvErrors();
|
||||
throw Error::new();
|
||||
}
|
||||
|
||||
if ($this->lastInsertId) {
|
||||
@@ -252,6 +274,8 @@ class SQLSrvStatement implements IteratorAggregate, Statement
|
||||
}
|
||||
|
||||
$this->result = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -284,6 +308,14 @@ class SQLSrvStatement implements IteratorAggregate, Statement
|
||||
];
|
||||
break;
|
||||
|
||||
case ParameterType::ASCII:
|
||||
$params[$column - 1] = [
|
||||
&$variable,
|
||||
SQLSRV_PARAM_IN,
|
||||
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
|
||||
];
|
||||
break;
|
||||
|
||||
default:
|
||||
$params[$column - 1] =& $variable;
|
||||
break;
|
||||
@@ -293,7 +325,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
|
||||
$stmt = sqlsrv_prepare($this->conn, $this->sql, $params);
|
||||
|
||||
if (! $stmt) {
|
||||
throw SQLSrvException::fromSqlSrvErrors();
|
||||
throw Error::new();
|
||||
}
|
||||
|
||||
return $stmt;
|
||||
@@ -301,6 +333,8 @@ class SQLSrvStatement implements IteratorAggregate, Statement
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @deprecated Use one of the fetch- or iterate-related methods.
|
||||
*/
|
||||
public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
|
||||
{
|
||||
@@ -313,7 +347,10 @@ class SQLSrvStatement implements IteratorAggregate, Statement
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @deprecated Use iterateNumeric(), iterateAssociative() or iterateColumn() instead.
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function getIterator()
|
||||
{
|
||||
return new StatementIterator($this);
|
||||
@@ -322,13 +359,15 @@ class SQLSrvStatement implements IteratorAggregate, Statement
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @deprecated Use fetchNumeric(), fetchAssociative() or fetchOne() instead.
|
||||
*
|
||||
* @throws SQLSrvException
|
||||
*/
|
||||
public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
|
||||
{
|
||||
// do not try fetching from the statement if it's not expected to contain result
|
||||
// in order to prevent exceptional situation
|
||||
if (! $this->result) {
|
||||
if ($this->stmt === null || ! $this->result) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -360,6 +399,8 @@ class SQLSrvStatement implements IteratorAggregate, Statement
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @deprecated Use fetchAllNumeric(), fetchAllAssociative() or fetchFirstColumn() instead.
|
||||
*/
|
||||
public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null)
|
||||
{
|
||||
@@ -370,12 +411,14 @@ class SQLSrvStatement implements IteratorAggregate, Statement
|
||||
while (($row = $this->fetch(...func_get_args())) !== false) {
|
||||
$rows[] = $row;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case FetchMode::COLUMN:
|
||||
while (($row = $this->fetchColumn()) !== false) {
|
||||
$rows[] = $row;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -389,6 +432,8 @@ class SQLSrvStatement implements IteratorAggregate, Statement
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @deprecated Use fetchOne() instead.
|
||||
*/
|
||||
public function fetchColumn($columnIndex = 0)
|
||||
{
|
||||
@@ -401,11 +446,94 @@ class SQLSrvStatement implements IteratorAggregate, Statement
|
||||
return $row[$columnIndex] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fetchNumeric()
|
||||
{
|
||||
return $this->doFetch(SQLSRV_FETCH_NUMERIC);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fetchAssociative()
|
||||
{
|
||||
return $this->doFetch(SQLSRV_FETCH_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fetchOne()
|
||||
{
|
||||
return FetchUtils::fetchOne($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fetchAllNumeric(): array
|
||||
{
|
||||
return FetchUtils::fetchAllNumeric($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fetchAllAssociative(): array
|
||||
{
|
||||
return FetchUtils::fetchAllAssociative($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fetchFirstColumn(): array
|
||||
{
|
||||
return FetchUtils::fetchFirstColumn($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rowCount()
|
||||
{
|
||||
return sqlsrv_rows_affected($this->stmt);
|
||||
if ($this->stmt === null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return sqlsrv_rows_affected($this->stmt) ?: 0;
|
||||
}
|
||||
|
||||
public function free(): void
|
||||
{
|
||||
// not having the result means there's nothing to close
|
||||
if ($this->stmt === null || ! $this->result) {
|
||||
return;
|
||||
}
|
||||
|
||||
// emulate it by fetching and discarding rows, similarly to what PDO does in this case
|
||||
// @link http://php.net/manual/en/pdostatement.closecursor.php
|
||||
// @link https://github.com/php/php-src/blob/php-7.0.11/ext/pdo/pdo_stmt.c#L2075
|
||||
// deliberately do not consider multiple result sets, since doctrine/dbal doesn't support them
|
||||
while (sqlsrv_fetch($this->stmt)) {
|
||||
}
|
||||
|
||||
$this->result = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed|false
|
||||
*/
|
||||
private function doFetch(int $fetchType)
|
||||
{
|
||||
// do not try fetching from the statement if it's not expected to contain the result
|
||||
// in order to prevent exceptional situation
|
||||
if ($this->stmt === null || ! $this->result) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return sqlsrv_fetch_array($this->stmt, $fetchType) ?? false;
|
||||
}
|
||||
}
|
||||
|
||||
7
vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/SQLSrv/Statement.php
vendored
Normal file
7
vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/SQLSrv/Statement.php
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\DBAL\Driver\SQLSrv;
|
||||
|
||||
final class Statement extends SQLSrvStatement
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user