diff options
Diffstat (limited to 'vendor/doctrine/dbal/src/Driver/OCI8/Result.php')
-rw-r--r-- | vendor/doctrine/dbal/src/Driver/OCI8/Result.php | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/vendor/doctrine/dbal/src/Driver/OCI8/Result.php b/vendor/doctrine/dbal/src/Driver/OCI8/Result.php new file mode 100644 index 0000000..609e651 --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/OCI8/Result.php | |||
@@ -0,0 +1,128 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Doctrine\DBAL\Driver\OCI8; | ||
6 | |||
7 | use Doctrine\DBAL\Driver\Exception; | ||
8 | use Doctrine\DBAL\Driver\FetchUtils; | ||
9 | use Doctrine\DBAL\Driver\OCI8\Exception\Error; | ||
10 | use Doctrine\DBAL\Driver\Result as ResultInterface; | ||
11 | |||
12 | use function oci_cancel; | ||
13 | use function oci_error; | ||
14 | use function oci_fetch_all; | ||
15 | use function oci_fetch_array; | ||
16 | use function oci_num_fields; | ||
17 | use function oci_num_rows; | ||
18 | |||
19 | use const OCI_ASSOC; | ||
20 | use const OCI_FETCHSTATEMENT_BY_COLUMN; | ||
21 | use const OCI_FETCHSTATEMENT_BY_ROW; | ||
22 | use const OCI_NUM; | ||
23 | use const OCI_RETURN_LOBS; | ||
24 | use const OCI_RETURN_NULLS; | ||
25 | |||
26 | final class Result implements ResultInterface | ||
27 | { | ||
28 | /** | ||
29 | * @internal The result can be only instantiated by its driver connection or statement. | ||
30 | * | ||
31 | * @param resource $statement | ||
32 | */ | ||
33 | public function __construct(private readonly mixed $statement) | ||
34 | { | ||
35 | } | ||
36 | |||
37 | public function fetchNumeric(): array|false | ||
38 | { | ||
39 | return $this->fetch(OCI_NUM); | ||
40 | } | ||
41 | |||
42 | public function fetchAssociative(): array|false | ||
43 | { | ||
44 | return $this->fetch(OCI_ASSOC); | ||
45 | } | ||
46 | |||
47 | public function fetchOne(): mixed | ||
48 | { | ||
49 | return FetchUtils::fetchOne($this); | ||
50 | } | ||
51 | |||
52 | /** | ||
53 | * {@inheritDoc} | ||
54 | */ | ||
55 | public function fetchAllNumeric(): array | ||
56 | { | ||
57 | return $this->fetchAll(OCI_NUM, OCI_FETCHSTATEMENT_BY_ROW); | ||
58 | } | ||
59 | |||
60 | /** | ||
61 | * {@inheritDoc} | ||
62 | */ | ||
63 | public function fetchAllAssociative(): array | ||
64 | { | ||
65 | return $this->fetchAll(OCI_ASSOC, OCI_FETCHSTATEMENT_BY_ROW); | ||
66 | } | ||
67 | |||
68 | /** | ||
69 | * {@inheritDoc} | ||
70 | */ | ||
71 | public function fetchFirstColumn(): array | ||
72 | { | ||
73 | return $this->fetchAll(OCI_NUM, OCI_FETCHSTATEMENT_BY_COLUMN)[0]; | ||
74 | } | ||
75 | |||
76 | public function rowCount(): int | ||
77 | { | ||
78 | $count = oci_num_rows($this->statement); | ||
79 | |||
80 | if ($count !== false) { | ||
81 | return $count; | ||
82 | } | ||
83 | |||
84 | return 0; | ||
85 | } | ||
86 | |||
87 | public function columnCount(): int | ||
88 | { | ||
89 | $count = oci_num_fields($this->statement); | ||
90 | |||
91 | if ($count !== false) { | ||
92 | return $count; | ||
93 | } | ||
94 | |||
95 | return 0; | ||
96 | } | ||
97 | |||
98 | public function free(): void | ||
99 | { | ||
100 | oci_cancel($this->statement); | ||
101 | } | ||
102 | |||
103 | /** @throws Exception */ | ||
104 | private function fetch(int $mode): mixed | ||
105 | { | ||
106 | $result = oci_fetch_array($this->statement, $mode | OCI_RETURN_NULLS | OCI_RETURN_LOBS); | ||
107 | |||
108 | if ($result === false && oci_error($this->statement) !== false) { | ||
109 | throw Error::new($this->statement); | ||
110 | } | ||
111 | |||
112 | return $result; | ||
113 | } | ||
114 | |||
115 | /** @return array<mixed> */ | ||
116 | private function fetchAll(int $mode, int $fetchStructure): array | ||
117 | { | ||
118 | oci_fetch_all( | ||
119 | $this->statement, | ||
120 | $result, | ||
121 | 0, | ||
122 | -1, | ||
123 | $mode | OCI_RETURN_NULLS | $fetchStructure | OCI_RETURN_LOBS, | ||
124 | ); | ||
125 | |||
126 | return $result; | ||
127 | } | ||
128 | } | ||