crate /
crate-dbal
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Crate\DBAL\Driver\PDOCrate; |
||
| 6 | |||
| 7 | use Doctrine\DBAL\Driver\FetchUtils; |
||
| 8 | use Doctrine\DBAL\Driver\Result as ResultInterface; |
||
| 9 | use PDO; |
||
| 10 | use PDOException; |
||
| 11 | |||
| 12 | final class Result implements ResultInterface |
||
| 13 | { |
||
| 14 | private CrateStatement $statement; |
||
| 15 | |||
| 16 | /** @internal The result can be only instantiated by its driver connection or statement. */ |
||
| 17 | 106 | public function __construct(CrateStatement $statement) |
|
| 18 | { |
||
| 19 | 106 | $this->statement = $statement; |
|
| 20 | } |
||
| 21 | |||
| 22 | /** |
||
| 23 | * {@inheritDoc} |
||
| 24 | */ |
||
| 25 | 28 | public function fetchNumeric(): false|array |
|
| 26 | { |
||
| 27 | 28 | return $this->fetch(PDO::FETCH_NUM); |
|
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * {@inheritDoc} |
||
| 32 | */ |
||
| 33 | 54 | public function fetchAssociative(): false|array |
|
| 34 | { |
||
| 35 | 54 | return $this->fetch(PDO::FETCH_ASSOC); |
|
|
0 ignored issues
–
show
|
|||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * {@inheritDoc} |
||
| 40 | */ |
||
| 41 | 20 | public function fetchOne(): mixed |
|
| 42 | { |
||
| 43 | 20 | return FetchUtils::fetchOne($this); |
|
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * {@inheritDoc} |
||
| 48 | */ |
||
| 49 | 4 | public function fetchAllNumeric(): array |
|
| 50 | { |
||
| 51 | 4 | return FetchUtils::fetchAllNumeric($this); |
|
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * {@inheritDoc} |
||
| 56 | */ |
||
| 57 | 44 | public function fetchAllAssociative(): array |
|
| 58 | { |
||
| 59 | 44 | return FetchUtils::fetchAllAssociative($this); |
|
| 60 | } |
||
| 61 | |||
| 62 | /** |
||
| 63 | * {@inheritDoc} |
||
| 64 | */ |
||
| 65 | 2 | public function fetchFirstColumn(): array |
|
| 66 | { |
||
| 67 | 2 | return FetchUtils::fetchFirstColumn($this); |
|
| 68 | } |
||
| 69 | |||
| 70 | 88 | public function rowCount(): int |
|
| 71 | { |
||
| 72 | try { |
||
| 73 | 88 | return $this->statement->rowCount(); |
|
| 74 | } catch (PDOException $exception) { |
||
| 75 | throw Exception::new($exception); |
||
| 76 | } |
||
| 77 | } |
||
| 78 | |||
| 79 | public function columnCount(): int |
||
| 80 | { |
||
| 81 | try { |
||
| 82 | return $this->statement->columnCount(); |
||
| 83 | } catch (PDOException $exception) { |
||
| 84 | throw Exception::new($exception); |
||
| 85 | } |
||
| 86 | } |
||
| 87 | |||
| 88 | public function free(): void |
||
| 89 | { |
||
| 90 | $this->statement->closeCursor(); |
||
| 91 | } |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @phpstan-param PDO::FETCH_* $mode |
||
| 95 | * |
||
| 96 | * @return mixed |
||
| 97 | * |
||
| 98 | * @throws Exception |
||
| 99 | */ |
||
| 100 | 72 | private function fetch(int $mode) |
|
| 101 | { |
||
| 102 | try { |
||
| 103 | 72 | return $this->statement->fetch($mode); |
|
| 104 | } catch (PDOException $exception) { |
||
| 105 | throw Exception::new($exception); |
||
| 106 | } |
||
| 107 | } |
||
| 108 | } |
||
| 109 |