ResultAdapter.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\DB;
  8. use Doctrine\DBAL\Result;
  9. use OCP\DB\IResult;
  10. use PDO;
  11. /**
  12. * Adapts DBAL 2.6 API for DBAL 3.x for backwards compatibility of a leaked type
  13. */
  14. class ResultAdapter implements IResult {
  15. /** @var Result */
  16. private $inner;
  17. public function __construct(Result $inner) {
  18. $this->inner = $inner;
  19. }
  20. public function closeCursor(): bool {
  21. $this->inner->free();
  22. return true;
  23. }
  24. public function fetch(int $fetchMode = PDO::FETCH_ASSOC) {
  25. return $this->inner->fetch($fetchMode);
  26. }
  27. public function fetchAll(int $fetchMode = PDO::FETCH_ASSOC): array {
  28. if ($fetchMode !== PDO::FETCH_ASSOC && $fetchMode !== PDO::FETCH_NUM && $fetchMode !== PDO::FETCH_COLUMN) {
  29. throw new \Exception('Fetch mode needs to be assoc, num or column.');
  30. }
  31. return $this->inner->fetchAll($fetchMode);
  32. }
  33. public function fetchColumn($columnIndex = 0) {
  34. return $this->inner->fetchOne();
  35. }
  36. public function fetchOne() {
  37. return $this->inner->fetchOne();
  38. }
  39. public function rowCount(): int {
  40. return $this->inner->rowCount();
  41. }
  42. }