diff --git a/lib/private/DB/ResultAdapter.php b/lib/private/DB/ResultAdapter.php index 63881b71e7dc6..e08b956d60444 100644 --- a/lib/private/DB/ResultAdapter.php +++ b/lib/private/DB/ResultAdapter.php @@ -25,7 +25,9 @@ */ namespace OC\DB; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Result; +use OC\DB\Exceptions\DbalException; use OCP\DB\IResult; use PDO; @@ -50,6 +52,22 @@ public function fetch(int $fetchMode = PDO::FETCH_ASSOC) { return $this->inner->fetch($fetchMode); } + public function fetchAssociative(): array|false { + try { + return $this->inner->fetchAssociative(); + } catch (Exception $e) { + throw DbalException::wrap($e); + } + } + + public function fetchAllAssociative(): array { + try { + return $this->inner->fetchAllAssociative(); + } catch (Exception $e) { + throw DbalException::wrap($e); + } + } + public function fetchAll(int $fetchMode = PDO::FETCH_ASSOC): array { if ($fetchMode !== PDO::FETCH_ASSOC && $fetchMode !== PDO::FETCH_NUM && $fetchMode !== PDO::FETCH_COLUMN) { throw new \Exception('Fetch mode needs to be assoc, num or column.'); @@ -61,10 +79,34 @@ public function fetchColumn($columnIndex = 0) { return $this->inner->fetchOne(); } + public function fetchNumeric(): array|false { + try { + return $this->inner->fetchNumeric(); + } catch (Exception $e) { + throw DbalException::wrap($e); + } + } + + public function fetchAllNumeric(): array { + try { + return $this->inner->fetchAllNumeric(); + } catch (Exception $e) { + throw DbalException::wrap($e); + } + } + public function fetchOne() { return $this->inner->fetchOne(); } + public function fetchFirstColumn(): array { + try { + return $this->inner->fetchFirstColumn(); + } catch (Exception $e) { + throw DbalException::wrap($e); + } + } + public function rowCount(): int { return $this->inner->rowCount(); } diff --git a/lib/public/DB/IResult.php b/lib/public/DB/IResult.php index 10a60cd5ff4e1..369fa8b166855 100644 --- a/lib/public/DB/IResult.php +++ b/lib/public/DB/IResult.php @@ -57,15 +57,37 @@ public function closeCursor(): bool; * @return mixed * * @since 21.0.0 + * @deprecated 28.0.0 use fetchAssociative instead of fetch(), fetchNumeric instead of fetch(\PDO::FETCH_NUM) and fetchOne instead of fetch(\PDO::FETCH_COLUMN) */ public function fetch(int $fetchMode = PDO::FETCH_ASSOC); + /** + * Returns the next row of the result as an associative array or FALSE if there are no more rows. + * + * @return array|false + * @throws Exception + * + * @since 28.0.0 + */ + public function fetchAssociative(): array|false; + + /** + * Returns an array containing all of the result rows represented as associative arrays + * + * @return list> + * @throws Exception + * + * @since 28.0.0 + */ + public function fetchAllAssociative(): array; + /** * @param int $fetchMode (one of PDO::FETCH_ASSOC, PDO::FETCH_NUM or PDO::FETCH_COLUMN (2, 3 or 7) * * @return mixed[] * * @since 21.0.0 + * @deprecated 28.0.0 use fetchAllAssociative instead of fetchAll(), fetchAllNumeric instead of fetchAll(FETCH_NUM) and fetchOne instead of fetchAll(FETCH_COLUMN) */ public function fetchAll(int $fetchMode = PDO::FETCH_ASSOC): array; @@ -77,6 +99,26 @@ public function fetchAll(int $fetchMode = PDO::FETCH_ASSOC): array; */ public function fetchColumn(); + /** + * Returns the next row of the result as a numeric array or FALSE if there are no more rows + * + * @return list|false + * @throws Exception + * + * @since 28.0.0 + */ + public function fetchNumeric(): array|false; + + /** + * Returns an array containing all of the result rows represented as numeric arrays + * + * @return list> + * @throws Exception + * + * @since 28.0.0 + */ + public function fetchAllNumeric(): array; + /** * Returns the first value of the next row of the result or FALSE if there are no more rows. * @@ -86,6 +128,16 @@ public function fetchColumn(); */ public function fetchOne(); + /** + * Returns an array containing the values of the first column of the result + * + * @return list + * @throws Exception + * + * @since 28.0.0 + */ + public function fetchFirstColumn(): array; + /** * @return int *