Skip to content

Commit 9bd8e85

Browse files
committed
adjust changes to develop branch
1 parent 1794a9c commit 9bd8e85

File tree

6 files changed

+74
-92
lines changed

6 files changed

+74
-92
lines changed

lib/Doctrine/DBAL/Driver/PDOSqlsrv/LastInsertId.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Doctrine\DBAL\Driver\PDOSqlsrv;
46

57
/**

lib/Doctrine/DBAL/Driver/PDOSqlsrv/PDOSqlsrvConnection.php

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Doctrine\DBAL\Driver\PDOSqlsrv;
46

57
use Doctrine\DBAL\Driver\Connection;
68
use Doctrine\DBAL\Driver\PDOConnection;
9+
use Doctrine\DBAL\Driver\PDOException;
10+
use Doctrine\DBAL\Driver\ResultStatement;
711
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
8-
use Doctrine\DBAL\ParameterType;
9-
use function func_get_args;
12+
use Doctrine\DBAL\Driver\Statement;
1013
use function strpos;
1114
use function substr;
1215

@@ -33,40 +36,46 @@ public function __construct($dsn, $user = null, $password = null, ?array $option
3336
/**
3437
* {@inheritDoc}
3538
*/
36-
public function prepare($sql)
39+
public function prepare($sql) : Statement
3740
{
3841
$this->lastInsertId = new LastInsertId();
3942

40-
return new PDOSqlsrvStatement($this->conn, $sql, $this->lastInsertId);
43+
try {
44+
return new PDOSqlsrvStatement($this->conn, $sql, $this->lastInsertId);
45+
} catch (\PDOException $exception) {
46+
throw new PDOException($exception);
47+
}
4148
}
4249

4350
/**
4451
* {@inheritDoc}
4552
*/
46-
public function query()
53+
public function query(string $sql) : ResultStatement
4754
{
48-
$args = func_get_args();
49-
$sql = $args[0];
50-
$stmt = $this->prepare($sql);
51-
$stmt->execute();
55+
try {
56+
$stmt = $this->prepare($sql);
57+
$stmt->execute();
5258

53-
return $stmt;
59+
return $stmt;
60+
} catch (\PDOException $exception) {
61+
throw new PDOException($exception);
62+
}
5463
}
5564

5665
/**
5766
* {@inheritDoc}
5867
*/
59-
public function exec($statement)
68+
public function exec($statement) : int
6069
{
6170
return $this->conn->exec($statement);
6271
}
6372

6473
/**
6574
* {@inheritDoc}
6675
*/
67-
public function quote($value, $type = ParameterType::STRING)
76+
public function quote(string $input) : string
6877
{
69-
$val = $this->conn->quote($value, $type);
78+
$val = $this->conn->quote($input);
7079

7180
// Fix for a driver version terminating all values with null byte
7281
if (strpos($val, "\0") !== false) {
@@ -98,41 +107,25 @@ public function lastInsertId($name = null)
98107
/**
99108
* {@inheritDoc}
100109
*/
101-
public function beginTransaction()
102-
{
103-
return $this->conn->beginTransaction();
104-
}
105-
106-
/**
107-
* {@inheritDoc}
108-
*/
109-
public function commit()
110-
{
111-
return $this->conn->commit();
112-
}
113-
114-
/**
115-
* {@inheritDoc}
116-
*/
117-
public function rollBack()
110+
public function beginTransaction() : void
118111
{
119-
return $this->conn->rollBack();
112+
$this->conn->beginTransaction();
120113
}
121114

122115
/**
123116
* {@inheritDoc}
124117
*/
125-
public function errorCode()
118+
public function commit() : void
126119
{
127-
return $this->conn->errorCode();
120+
$this->conn->commit();
128121
}
129122

130123
/**
131124
* {@inheritDoc}
132125
*/
133-
public function errorInfo()
126+
public function rollBack() : void
134127
{
135-
return $this->conn->errorInfo();
128+
$this->conn->rollBack();
136129
}
137130

138131
/**

lib/Doctrine/DBAL/Driver/PDOSqlsrv/PDOSqlsrvStatement.php

Lines changed: 28 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Doctrine\DBAL\Driver\PDOSqlsrv;
46

57
use Doctrine\DBAL\Driver\PDOConnection;
68
use Doctrine\DBAL\Driver\PDOStatement;
79
use Doctrine\DBAL\Driver\Statement;
8-
use Doctrine\DBAL\Driver\StatementIterator;
910
use Doctrine\DBAL\ParameterType;
1011
use IteratorAggregate;
1112
use PDO;
12-
use function array_key_exists;
13-
use function is_int;
1413
use function stripos;
1514

1615
/**
@@ -58,10 +57,7 @@ class PDOSqlsrvStatement implements IteratorAggregate, Statement
5857
*/
5958
public const LAST_INSERT_ID_SQL = ';SELECT SCOPE_IDENTITY() AS LastInsertId;';
6059

61-
/**
62-
* @param string $sql
63-
*/
64-
public function __construct(PDOConnection $conn, $sql, ?LastInsertId $lastInsertId = null)
60+
public function __construct(PDOConnection $conn, string $sql, ?LastInsertId $lastInsertId = null)
6561
{
6662
$this->conn = $conn;
6763
$this->sql = $sql;
@@ -77,31 +73,31 @@ public function __construct(PDOConnection $conn, $sql, ?LastInsertId $lastInsert
7773
/**
7874
* {@inheritdoc}
7975
*/
80-
public function bindValue($param, $value, $type = ParameterType::STRING)
76+
public function bindValue($param, $value, $type = ParameterType::STRING) : void
8177
{
82-
return $this->bindParam($param, $value, $type);
78+
$this->bindParam($param, $value, $type);
8379
}
8480

8581
/**
8682
* {@inheritdoc}
8783
*/
88-
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null, $driverOptions = null)
84+
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null, $driverOptions = null) : void
8985
{
9086
if (($type === ParameterType::LARGE_OBJECT || $type === ParameterType::BINARY)
9187
&& $driverOptions === null
9288
) {
9389
$driverOptions = PDO::SQLSRV_ENCODING_BINARY;
9490
}
9591

96-
return $this->stmt->bindParam($column, $variable, $type, $length, $driverOptions);
92+
$this->stmt->bindParam($column, $variable, $type, $length, $driverOptions);
9793
}
9894

99-
/**
100-
* {@inheritdoc}
101-
*/
102-
public function closeCursor()
95+
/**
96+
* {@inheritdoc}
97+
*/
98+
public function closeCursor() : void
10399
{
104-
return $this->stmt->closeCursor();
100+
$this->stmt->closeCursor();
105101
}
106102

107103
/**
@@ -115,40 +111,13 @@ public function columnCount()
115111
/**
116112
* {@inheritdoc}
117113
*/
118-
public function errorCode()
119-
{
120-
return $this->stmt->errorCode();
121-
}
122-
123-
/**
124-
* {@inheritdoc}
125-
*/
126-
public function errorInfo()
127-
{
128-
return $this->stmt->errorInfo();
129-
}
130-
131-
/**
132-
* {@inheritdoc}
133-
*/
134-
public function execute($params = null)
114+
public function execute($params = null) : void
135115
{
136-
if ($params) {
137-
$hasZeroIndex = array_key_exists(0, $params);
138-
foreach ($params as $key => $val) {
139-
if ($hasZeroIndex && is_int($key)) {
140-
$this->bindValue($key + 1, $val);
141-
} else {
142-
$this->bindValue($key, $val);
143-
}
144-
}
145-
}
146-
147-
$result = $this->stmt->execute($params);
116+
$this->stmt->execute($params);
148117
$this->rowCount = $this->rowCount();
149118

150119
if (! $this->lastInsertId) {
151-
return $result;
120+
return;
152121
}
153122

154123
$id = null;
@@ -169,8 +138,6 @@ public function execute($params = null)
169138
}
170139

171140
$this->lastInsertId->setId($id);
172-
173-
return $result;
174141
}
175142

176143
/**
@@ -189,33 +156,33 @@ private function prepare()
189156
/**
190157
* {@inheritdoc}
191158
*/
192-
public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
159+
public function setFetchMode($fetchMode, ...$args) : void
193160
{
194-
return $this->stmt->setFetchMode($fetchMode, $arg2, $arg3);
161+
$this->stmt->setFetchMode($fetchMode, ...$args);
195162
}
196163

197164
/**
198165
* {@inheritdoc}
199166
*/
200167
public function getIterator()
201168
{
202-
return new StatementIterator($this);
169+
yield from $this->stmt;
203170
}
204171

205172
/**
206173
* {@inheritdoc}
207174
*/
208-
public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
175+
public function fetch($fetchMode = null, ...$args)
209176
{
210-
return $this->stmt->fetch($fetchMode, $cursorOrientation, $cursorOffset);
177+
return $this->stmt->fetch($fetchMode, ...$args);
211178
}
212179

213180
/**
214181
* {@inheritdoc}
215182
*/
216-
public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null)
183+
public function fetchAll($fetchMode = null, ...$args)
217184
{
218-
return $this->stmt->fetchAll($fetchMode, $fetchArgument, $ctorArgs);
185+
return $this->stmt->fetchAll($fetchMode, ...$args);
219186
}
220187

221188
/**
@@ -229,8 +196,13 @@ public function fetchColumn($columnIndex = 0)
229196
/**
230197
* {@inheritdoc}
231198
*/
232-
public function rowCount()
199+
public function rowCount() : int
233200
{
234201
return $this->rowCount ?: $this->stmt->rowCount();
235202
}
203+
204+
public function nextRowset() : bool
205+
{
206+
return $this->stmt->nextRowset();
207+
}
236208
}

lib/Doctrine/DBAL/Driver/PDOStatement.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,14 @@ public function getIterator()
244244
{
245245
yield from $this->stmt;
246246
}
247+
248+
/**
249+
* Advances to the next rowset in a multi-rowset statement handle
250+
*
251+
* @return bool Returns TRUE on success or FALSE on failure.
252+
*/
253+
public function nextRowset() : bool
254+
{
255+
return $this->stmt->nextRowset();
256+
}
247257
}

tests/Doctrine/Tests/DBAL/Functional/StatementTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Doctrine\DBAL\DBALException;
88
use Doctrine\DBAL\Driver\PDOConnection;
99
use Doctrine\DBAL\Driver\PDOOracle\Driver as PDOOracleDriver;
10+
use Doctrine\DBAL\Driver\PDOSqlsrv\PDOSqlsrvConnection;
1011
use Doctrine\DBAL\Driver\Statement;
1112
use Doctrine\DBAL\FetchMode;
1213
use Doctrine\DBAL\ParameterType;
@@ -373,7 +374,9 @@ public function testExecWithRedundantParameters() : void
373374
*/
374375
public function testFetchColumnNonExistingIndex(int $index) : void
375376
{
376-
if ($this->connection->getWrappedConnection() instanceof PDOConnection) {
377+
$wrappedConnection = $this->connection->getWrappedConnection();
378+
379+
if ($wrappedConnection instanceof PDOConnection || $wrappedConnection instanceof PDOSqlsrvConnection) {
377380
$this->markTestSkipped('PDO supports this behavior natively but throws a different exception');
378381
}
379382

tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL3516Test.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Doctrine\Tests\DBAL\Functional\Ticket;
46

57
use Doctrine\Tests\DbalFunctionalTestCase;

0 commit comments

Comments
 (0)