ResultAdapter.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2021 Christoph Wurst <christoph@winzerhof-wurst.at>
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OC\DB;
  25. use Doctrine\DBAL\Result;
  26. use OCP\DB\IResult;
  27. use PDO;
  28. /**
  29. * Adapts DBAL 2.6 API for DBAL 3.x for backwards compatibility of a leaked type
  30. */
  31. class ResultAdapter implements IResult {
  32. /** @var Result */
  33. private $inner;
  34. public function __construct(Result $inner) {
  35. $this->inner = $inner;
  36. }
  37. public function closeCursor(): bool {
  38. $this->inner->free();
  39. return true;
  40. }
  41. public function fetch(int $fetchMode = PDO::FETCH_ASSOC) {
  42. return $this->inner->fetch($fetchMode);
  43. }
  44. public function fetchAll(int $fetchMode = PDO::FETCH_ASSOC): array {
  45. if ($fetchMode !== PDO::FETCH_ASSOC && $fetchMode !== PDO::FETCH_NUM && $fetchMode !== PDO::FETCH_COLUMN) {
  46. throw new \Exception('Fetch mode needs to be assoc, num or column.');
  47. }
  48. return $this->inner->fetchAll($fetchMode);
  49. }
  50. public function fetchColumn($columnIndex = 0) {
  51. return $this->inner->fetchOne();
  52. }
  53. public function fetchOne() {
  54. return $this->inner->fetchOne();
  55. }
  56. public function rowCount(): int {
  57. return $this->inner->rowCount();
  58. }
  59. }