From 35968f2d9186bbb497164187c2533a262db53e7e Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Wed, 27 Sep 2023 14:23:10 +0200 Subject: [PATCH 1/5] feat(database): Add replacements for deprecated fetch and fetchAll DBAL deprecated these and will remove them it in the future. Signed-off-by: Christoph Wurst --- lib/private/DB/ResultAdapter.php | 42 ++++++++++++++++++++++++++ lib/public/DB/IResult.php | 52 ++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/lib/private/DB/ResultAdapter.php b/lib/private/DB/ResultAdapter.php index 63881b71e7dc6..7f80575e5385b 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->fetchAllNumeric(); + } 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..2823462d1b815 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, fetchNumeric or fetchOne */ 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, fetchAllNumeric or fetchOne */ 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 all of the result rows represented as numeric arrays + * + * @return list> + * @throws Exception + * + * @since 21.0.0 + */ + public function fetchFirstColumn(): array; + /** * @return int * From e1fb2a655fc09d26441b42fab1179df4272ab5de Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Wed, 27 Sep 2023 14:37:19 +0200 Subject: [PATCH 2/5] fixup! feat(database): Add replacements for deprecated fetch and fetchAll Signed-off-by: Christoph Wurst --- lib/private/DB/ResultAdapter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/DB/ResultAdapter.php b/lib/private/DB/ResultAdapter.php index 7f80575e5385b..e08b956d60444 100644 --- a/lib/private/DB/ResultAdapter.php +++ b/lib/private/DB/ResultAdapter.php @@ -101,7 +101,7 @@ public function fetchOne() { public function fetchFirstColumn(): array { try { - return $this->inner->fetchAllNumeric(); + return $this->inner->fetchFirstColumn(); } catch (Exception $e) { throw DbalException::wrap($e); } From a6c3a7dfbc9b450fb5961543e572ca827a95506f Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Thu, 5 Oct 2023 13:29:05 +0200 Subject: [PATCH 3/5] fixup! feat(database): Add replacements for deprecated fetch and fetchAll Signed-off-by: Christoph Wurst --- lib/public/DB/IResult.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/public/DB/IResult.php b/lib/public/DB/IResult.php index 2823462d1b815..2389a81c3f663 100644 --- a/lib/public/DB/IResult.php +++ b/lib/public/DB/IResult.php @@ -131,10 +131,10 @@ public function fetchOne(); /** * Returns an array containing all of the result rows represented as numeric arrays * - * @return list> + * @return list * @throws Exception * - * @since 21.0.0 + * @since 28.0.0 */ public function fetchFirstColumn(): array; From d25712d36bfe0ea1cfddec8a7906c3ced54ccfc9 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Thu, 5 Oct 2023 18:38:20 +0200 Subject: [PATCH 4/5] fixup! feat(database): Add replacements for deprecated fetch and fetchAll Signed-off-by: Christoph Wurst --- lib/public/DB/IResult.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/public/DB/IResult.php b/lib/public/DB/IResult.php index 2389a81c3f663..abf411d4c84b9 100644 --- a/lib/public/DB/IResult.php +++ b/lib/public/DB/IResult.php @@ -129,7 +129,7 @@ public function fetchAllNumeric(): array; public function fetchOne(); /** - * Returns an array containing all of the result rows represented as numeric arrays + * Returns an array containing the values of the first column of the result * * @return list * @throws Exception From c2d50245991679d89d8cebfa9c9ce4e50b54e7d9 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Fri, 6 Oct 2023 09:44:29 +0200 Subject: [PATCH 5/5] fixup! feat(database): Add replacements for deprecated fetch and fetchAll Signed-off-by: Christoph Wurst --- lib/public/DB/IResult.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/public/DB/IResult.php b/lib/public/DB/IResult.php index abf411d4c84b9..369fa8b166855 100644 --- a/lib/public/DB/IResult.php +++ b/lib/public/DB/IResult.php @@ -57,7 +57,7 @@ public function closeCursor(): bool; * @return mixed * * @since 21.0.0 - * @deprecated 28.0.0 use fetchAssociative, fetchNumeric or fetchOne + * @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); @@ -87,7 +87,7 @@ public function fetchAllAssociative(): array; * @return mixed[] * * @since 21.0.0 - * @deprecated 28.0.0 use fetchAllAssociative, fetchAllNumeric or fetchOne + * @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;