summaryrefslogtreecommitdiff
path: root/vendor/doctrine/dbal/src/Driver/SQLSrv/Result.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/doctrine/dbal/src/Driver/SQLSrv/Result.php')
-rw-r--r--vendor/doctrine/dbal/src/Driver/SQLSrv/Result.php104
1 files changed, 104 insertions, 0 deletions
diff --git a/vendor/doctrine/dbal/src/Driver/SQLSrv/Result.php b/vendor/doctrine/dbal/src/Driver/SQLSrv/Result.php
new file mode 100644
index 0000000..316368f
--- /dev/null
+++ b/vendor/doctrine/dbal/src/Driver/SQLSrv/Result.php
@@ -0,0 +1,104 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Doctrine\DBAL\Driver\SQLSrv;
6
7use Doctrine\DBAL\Driver\FetchUtils;
8use Doctrine\DBAL\Driver\Result as ResultInterface;
9
10use function sqlsrv_fetch;
11use function sqlsrv_fetch_array;
12use function sqlsrv_num_fields;
13use function sqlsrv_rows_affected;
14
15use const SQLSRV_FETCH_ASSOC;
16use const SQLSRV_FETCH_NUMERIC;
17
18final class Result implements ResultInterface
19{
20 /**
21 * @internal The result can be only instantiated by its driver connection or statement.
22 *
23 * @param resource $statement
24 */
25 public function __construct(private readonly mixed $statement)
26 {
27 }
28
29 public function fetchNumeric(): array|false
30 {
31 return $this->fetch(SQLSRV_FETCH_NUMERIC);
32 }
33
34 public function fetchAssociative(): array|false
35 {
36 return $this->fetch(SQLSRV_FETCH_ASSOC);
37 }
38
39 public function fetchOne(): mixed
40 {
41 return FetchUtils::fetchOne($this);
42 }
43
44 /**
45 * {@inheritDoc}
46 */
47 public function fetchAllNumeric(): array
48 {
49 return FetchUtils::fetchAllNumeric($this);
50 }
51
52 /**
53 * {@inheritDoc}
54 */
55 public function fetchAllAssociative(): array
56 {
57 return FetchUtils::fetchAllAssociative($this);
58 }
59
60 /**
61 * {@inheritDoc}
62 */
63 public function fetchFirstColumn(): array
64 {
65 return FetchUtils::fetchFirstColumn($this);
66 }
67
68 public function rowCount(): int
69 {
70 $count = sqlsrv_rows_affected($this->statement);
71
72 if ($count !== false) {
73 return $count;
74 }
75
76 return 0;
77 }
78
79 public function columnCount(): int
80 {
81 $count = sqlsrv_num_fields($this->statement);
82
83 if ($count !== false) {
84 return $count;
85 }
86
87 return 0;
88 }
89
90 public function free(): void
91 {
92 // emulate it by fetching and discarding rows, similarly to what PDO does in this case
93 // @link http://php.net/manual/en/pdostatement.closecursor.php
94 // @link https://github.com/php/php-src/blob/php-7.0.11/ext/pdo/pdo_stmt.c#L2075
95 // deliberately do not consider multiple result sets, since doctrine/dbal doesn't support them
96 while (sqlsrv_fetch($this->statement)) {
97 }
98 }
99
100 private function fetch(int $fetchType): mixed
101 {
102 return sqlsrv_fetch_array($this->statement, $fetchType) ?? false;
103 }
104}