diff options
Diffstat (limited to 'vendor/doctrine/dbal/src/Driver/IBMDB2/Result.php')
| -rw-r--r-- | vendor/doctrine/dbal/src/Driver/IBMDB2/Result.php | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/vendor/doctrine/dbal/src/Driver/IBMDB2/Result.php b/vendor/doctrine/dbal/src/Driver/IBMDB2/Result.php new file mode 100644 index 0000000..461f44a --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/IBMDB2/Result.php | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\DBAL\Driver\IBMDB2; | ||
| 6 | |||
| 7 | use Doctrine\DBAL\Driver\FetchUtils; | ||
| 8 | use Doctrine\DBAL\Driver\IBMDB2\Exception\StatementError; | ||
| 9 | use Doctrine\DBAL\Driver\Result as ResultInterface; | ||
| 10 | |||
| 11 | use function db2_fetch_array; | ||
| 12 | use function db2_fetch_assoc; | ||
| 13 | use function db2_free_result; | ||
| 14 | use function db2_num_fields; | ||
| 15 | use function db2_num_rows; | ||
| 16 | use function db2_stmt_error; | ||
| 17 | |||
| 18 | final 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 | $row = @db2_fetch_array($this->statement); | ||
| 32 | |||
| 33 | if ($row === false && db2_stmt_error($this->statement) !== '02000') { | ||
| 34 | throw StatementError::new($this->statement); | ||
| 35 | } | ||
| 36 | |||
| 37 | return $row; | ||
| 38 | } | ||
| 39 | |||
| 40 | public function fetchAssociative(): array|false | ||
| 41 | { | ||
| 42 | $row = @db2_fetch_assoc($this->statement); | ||
| 43 | |||
| 44 | if ($row === false && db2_stmt_error($this->statement) !== '02000') { | ||
| 45 | throw StatementError::new($this->statement); | ||
| 46 | } | ||
| 47 | |||
| 48 | return $row; | ||
| 49 | } | ||
| 50 | |||
| 51 | public function fetchOne(): mixed | ||
| 52 | { | ||
| 53 | return FetchUtils::fetchOne($this); | ||
| 54 | } | ||
| 55 | |||
| 56 | /** | ||
| 57 | * {@inheritDoc} | ||
| 58 | */ | ||
| 59 | public function fetchAllNumeric(): array | ||
| 60 | { | ||
| 61 | return FetchUtils::fetchAllNumeric($this); | ||
| 62 | } | ||
| 63 | |||
| 64 | /** | ||
| 65 | * {@inheritDoc} | ||
| 66 | */ | ||
| 67 | public function fetchAllAssociative(): array | ||
| 68 | { | ||
| 69 | return FetchUtils::fetchAllAssociative($this); | ||
| 70 | } | ||
| 71 | |||
| 72 | /** | ||
| 73 | * {@inheritDoc} | ||
| 74 | */ | ||
| 75 | public function fetchFirstColumn(): array | ||
| 76 | { | ||
| 77 | return FetchUtils::fetchFirstColumn($this); | ||
| 78 | } | ||
| 79 | |||
| 80 | public function rowCount(): int | ||
| 81 | { | ||
| 82 | $numRows = @db2_num_rows($this->statement); | ||
| 83 | |||
| 84 | if ($numRows === false) { | ||
| 85 | throw StatementError::new($this->statement); | ||
| 86 | } | ||
| 87 | |||
| 88 | return $numRows; | ||
| 89 | } | ||
| 90 | |||
| 91 | public function columnCount(): int | ||
| 92 | { | ||
| 93 | $count = db2_num_fields($this->statement); | ||
| 94 | |||
| 95 | if ($count !== false) { | ||
| 96 | return $count; | ||
| 97 | } | ||
| 98 | |||
| 99 | return 0; | ||
| 100 | } | ||
| 101 | |||
| 102 | public function free(): void | ||
| 103 | { | ||
| 104 | db2_free_result($this->statement); | ||
| 105 | } | ||
| 106 | } | ||
