ArrayParameters
2 years ago
Cache
9 months ago
Driver
9 months ago
Event
2 years ago
Exception
9 months ago
Id
2 years ago
Logging
2 years ago
Platforms
9 months ago
Portability
2 years ago
Query
2 years ago
SQL
9 months ago
Schema
8 months ago
Types
9 months ago
ArrayParameterType.php
2 years ago
ColumnCase.php
2 years ago
Configuration.php
9 months ago
Connection.php
9 months ago
ConnectionException.php
2 years ago
Driver.php
2 years ago
DriverManager.php
2 years ago
Events.php
2 years ago
Exception.php
2 years ago
ExpandArrayParameters.php
2 years ago
FetchMode.php
2 years ago
LockMode.php
2 years ago
ParameterType.php
2 years ago
Query.php
2 years ago
Result.php
2 years ago
Statement.php
2 years ago
TransactionIsolationLevel.php
2 years ago
VersionAwarePlatformDriver.php
2 years ago
index.php
2 years ago
Result.php
180 lines
| 1 | <?php |
| 2 | declare (strict_types=1); |
| 3 | namespace MailPoetVendor\Doctrine\DBAL; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | use MailPoetVendor\Doctrine\DBAL\Driver\Exception as DriverException; |
| 6 | use MailPoetVendor\Doctrine\DBAL\Driver\Result as DriverResult; |
| 7 | use MailPoetVendor\Doctrine\DBAL\Exception\NoKeyValue; |
| 8 | use MailPoetVendor\Doctrine\Deprecations\Deprecation; |
| 9 | use LogicException; |
| 10 | use Traversable; |
| 11 | use function array_shift; |
| 12 | use function func_num_args; |
| 13 | class Result |
| 14 | { |
| 15 | private DriverResult $result; |
| 16 | private Connection $connection; |
| 17 | public function __construct(DriverResult $result, Connection $connection) |
| 18 | { |
| 19 | $this->result = $result; |
| 20 | $this->connection = $connection; |
| 21 | } |
| 22 | public function fetchNumeric() |
| 23 | { |
| 24 | try { |
| 25 | return $this->result->fetchNumeric(); |
| 26 | } catch (DriverException $e) { |
| 27 | throw $this->connection->convertException($e); |
| 28 | } |
| 29 | } |
| 30 | public function fetchAssociative() |
| 31 | { |
| 32 | try { |
| 33 | return $this->result->fetchAssociative(); |
| 34 | } catch (DriverException $e) { |
| 35 | throw $this->connection->convertException($e); |
| 36 | } |
| 37 | } |
| 38 | public function fetchOne() |
| 39 | { |
| 40 | try { |
| 41 | return $this->result->fetchOne(); |
| 42 | } catch (DriverException $e) { |
| 43 | throw $this->connection->convertException($e); |
| 44 | } |
| 45 | } |
| 46 | public function fetchAllNumeric() : array |
| 47 | { |
| 48 | try { |
| 49 | return $this->result->fetchAllNumeric(); |
| 50 | } catch (DriverException $e) { |
| 51 | throw $this->connection->convertException($e); |
| 52 | } |
| 53 | } |
| 54 | public function fetchAllAssociative() : array |
| 55 | { |
| 56 | try { |
| 57 | return $this->result->fetchAllAssociative(); |
| 58 | } catch (DriverException $e) { |
| 59 | throw $this->connection->convertException($e); |
| 60 | } |
| 61 | } |
| 62 | public function fetchAllKeyValue() : array |
| 63 | { |
| 64 | $this->ensureHasKeyValue(); |
| 65 | $data = []; |
| 66 | foreach ($this->fetchAllNumeric() as [$key, $value]) { |
| 67 | $data[$key] = $value; |
| 68 | } |
| 69 | return $data; |
| 70 | } |
| 71 | public function fetchAllAssociativeIndexed() : array |
| 72 | { |
| 73 | $data = []; |
| 74 | foreach ($this->fetchAllAssociative() as $row) { |
| 75 | $data[array_shift($row)] = $row; |
| 76 | } |
| 77 | return $data; |
| 78 | } |
| 79 | public function fetchFirstColumn() : array |
| 80 | { |
| 81 | try { |
| 82 | return $this->result->fetchFirstColumn(); |
| 83 | } catch (DriverException $e) { |
| 84 | throw $this->connection->convertException($e); |
| 85 | } |
| 86 | } |
| 87 | public function iterateNumeric() : Traversable |
| 88 | { |
| 89 | while (($row = $this->fetchNumeric()) !== \false) { |
| 90 | (yield $row); |
| 91 | } |
| 92 | } |
| 93 | public function iterateAssociative() : Traversable |
| 94 | { |
| 95 | while (($row = $this->fetchAssociative()) !== \false) { |
| 96 | (yield $row); |
| 97 | } |
| 98 | } |
| 99 | public function iterateKeyValue() : Traversable |
| 100 | { |
| 101 | $this->ensureHasKeyValue(); |
| 102 | foreach ($this->iterateNumeric() as [$key, $value]) { |
| 103 | (yield $key => $value); |
| 104 | } |
| 105 | } |
| 106 | public function iterateAssociativeIndexed() : Traversable |
| 107 | { |
| 108 | foreach ($this->iterateAssociative() as $row) { |
| 109 | (yield array_shift($row) => $row); |
| 110 | } |
| 111 | } |
| 112 | public function iterateColumn() : Traversable |
| 113 | { |
| 114 | while (($value = $this->fetchOne()) !== \false) { |
| 115 | (yield $value); |
| 116 | } |
| 117 | } |
| 118 | public function rowCount() : int |
| 119 | { |
| 120 | try { |
| 121 | return $this->result->rowCount(); |
| 122 | } catch (DriverException $e) { |
| 123 | throw $this->connection->convertException($e); |
| 124 | } |
| 125 | } |
| 126 | public function columnCount() : int |
| 127 | { |
| 128 | try { |
| 129 | return $this->result->columnCount(); |
| 130 | } catch (DriverException $e) { |
| 131 | throw $this->connection->convertException($e); |
| 132 | } |
| 133 | } |
| 134 | public function free() : void |
| 135 | { |
| 136 | $this->result->free(); |
| 137 | } |
| 138 | private function ensureHasKeyValue() : void |
| 139 | { |
| 140 | $columnCount = $this->columnCount(); |
| 141 | if ($columnCount < 2) { |
| 142 | throw NoKeyValue::fromColumnCount($columnCount); |
| 143 | } |
| 144 | } |
| 145 | public function fetch(int $mode = FetchMode::ASSOCIATIVE) |
| 146 | { |
| 147 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4007', '%s is deprecated, please use fetchNumeric(), fetchAssociative() or fetchOne() instead.', __METHOD__); |
| 148 | if (func_num_args() > 1) { |
| 149 | throw new LogicException('Only invocations with one argument are still supported by this legacy API.'); |
| 150 | } |
| 151 | if ($mode === FetchMode::ASSOCIATIVE) { |
| 152 | return $this->fetchAssociative(); |
| 153 | } |
| 154 | if ($mode === FetchMode::NUMERIC) { |
| 155 | return $this->fetchNumeric(); |
| 156 | } |
| 157 | if ($mode === FetchMode::COLUMN) { |
| 158 | return $this->fetchOne(); |
| 159 | } |
| 160 | throw new LogicException('Only fetch modes declared on Doctrine\\DBAL\\FetchMode are supported by legacy API.'); |
| 161 | } |
| 162 | public function fetchAll(int $mode = FetchMode::ASSOCIATIVE) : array |
| 163 | { |
| 164 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4007', '%s is deprecated, please use fetchAllNumeric(), fetchAllAssociative() or fetchFirstColumn() instead.', __METHOD__); |
| 165 | if (func_num_args() > 1) { |
| 166 | throw new LogicException('Only invocations with one argument are still supported by this legacy API.'); |
| 167 | } |
| 168 | if ($mode === FetchMode::ASSOCIATIVE) { |
| 169 | return $this->fetchAllAssociative(); |
| 170 | } |
| 171 | if ($mode === FetchMode::NUMERIC) { |
| 172 | return $this->fetchAllNumeric(); |
| 173 | } |
| 174 | if ($mode === FetchMode::COLUMN) { |
| 175 | return $this->fetchFirstColumn(); |
| 176 | } |
| 177 | throw new LogicException('Only fetch modes declared on Doctrine\\DBAL\\FetchMode are supported by legacy API.'); |
| 178 | } |
| 179 | } |
| 180 |