diff options
Diffstat (limited to 'vendor/doctrine/dbal/src/Driver/PDO/Result.php')
| -rw-r--r-- | vendor/doctrine/dbal/src/Driver/PDO/Result.php | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/vendor/doctrine/dbal/src/Driver/PDO/Result.php b/vendor/doctrine/dbal/src/Driver/PDO/Result.php new file mode 100644 index 0000000..1a844d1 --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/PDO/Result.php | |||
| @@ -0,0 +1,110 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\DBAL\Driver\PDO; | ||
| 6 | |||
| 7 | use Doctrine\DBAL\Driver\Result as ResultInterface; | ||
| 8 | use PDO; | ||
| 9 | use PDOException; | ||
| 10 | use PDOStatement; | ||
| 11 | |||
| 12 | final class Result implements ResultInterface | ||
| 13 | { | ||
| 14 | /** @internal The result can be only instantiated by its driver connection or statement. */ | ||
| 15 | public function __construct(private readonly PDOStatement $statement) | ||
| 16 | { | ||
| 17 | } | ||
| 18 | |||
| 19 | public function fetchNumeric(): array|false | ||
| 20 | { | ||
| 21 | return $this->fetch(PDO::FETCH_NUM); | ||
| 22 | } | ||
| 23 | |||
| 24 | public function fetchAssociative(): array|false | ||
| 25 | { | ||
| 26 | return $this->fetch(PDO::FETCH_ASSOC); | ||
| 27 | } | ||
| 28 | |||
| 29 | public function fetchOne(): mixed | ||
| 30 | { | ||
| 31 | return $this->fetch(PDO::FETCH_COLUMN); | ||
| 32 | } | ||
| 33 | |||
| 34 | /** | ||
| 35 | * {@inheritDoc} | ||
| 36 | */ | ||
| 37 | public function fetchAllNumeric(): array | ||
| 38 | { | ||
| 39 | return $this->fetchAll(PDO::FETCH_NUM); | ||
| 40 | } | ||
| 41 | |||
| 42 | /** | ||
| 43 | * {@inheritDoc} | ||
| 44 | */ | ||
| 45 | public function fetchAllAssociative(): array | ||
| 46 | { | ||
| 47 | return $this->fetchAll(PDO::FETCH_ASSOC); | ||
| 48 | } | ||
| 49 | |||
| 50 | /** | ||
| 51 | * {@inheritDoc} | ||
| 52 | */ | ||
| 53 | public function fetchFirstColumn(): array | ||
| 54 | { | ||
| 55 | return $this->fetchAll(PDO::FETCH_COLUMN); | ||
| 56 | } | ||
| 57 | |||
| 58 | public function rowCount(): int | ||
| 59 | { | ||
| 60 | try { | ||
| 61 | return $this->statement->rowCount(); | ||
| 62 | } catch (PDOException $exception) { | ||
| 63 | throw Exception::new($exception); | ||
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 | public function columnCount(): int | ||
| 68 | { | ||
| 69 | try { | ||
| 70 | return $this->statement->columnCount(); | ||
| 71 | } catch (PDOException $exception) { | ||
| 72 | throw Exception::new($exception); | ||
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 76 | public function free(): void | ||
| 77 | { | ||
| 78 | $this->statement->closeCursor(); | ||
| 79 | } | ||
| 80 | |||
| 81 | /** | ||
| 82 | * @psalm-param PDO::FETCH_* $mode | ||
| 83 | * | ||
| 84 | * @throws Exception | ||
| 85 | */ | ||
| 86 | private function fetch(int $mode): mixed | ||
| 87 | { | ||
| 88 | try { | ||
| 89 | return $this->statement->fetch($mode); | ||
| 90 | } catch (PDOException $exception) { | ||
| 91 | throw Exception::new($exception); | ||
| 92 | } | ||
| 93 | } | ||
| 94 | |||
| 95 | /** | ||
| 96 | * @psalm-param PDO::FETCH_* $mode | ||
| 97 | * | ||
| 98 | * @return list<mixed> | ||
| 99 | * | ||
| 100 | * @throws Exception | ||
| 101 | */ | ||
| 102 | private function fetchAll(int $mode): array | ||
| 103 | { | ||
| 104 | try { | ||
| 105 | return $this->statement->fetchAll($mode); | ||
| 106 | } catch (PDOException $exception) { | ||
| 107 | throw Exception::new($exception); | ||
| 108 | } | ||
| 109 | } | ||
| 110 | } | ||
