From 52c5d28bebe0ba2ec037806cf47c89f589296a2c Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Mon, 13 Oct 2025 16:03:47 +0200 Subject: [PATCH 1/3] refactor(QueryBuilder): Port away from deprecated execute method Signed-off-by: Carl Schwan --- CHANGELOG.md | 2 + lib/Db/RecipeDb.php | 50 +++++++++---------- .../Version000000Date20210701093123.php | 6 +-- 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9d41ba2e..b76837d4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,6 +68,8 @@ Sorry for the inconvience. [#2846](https://github.com/nextcloud/cookbook/pull/2846) @dependabot - Udpate the composer dependencies [#2864](https://github.com/nextcloud/cookbook/pull/2864) @christianlupus +- Port away from deprecated execute method + [#2882](https://github.com/nextcloud/cookbook/pull/2882) @CarlSchwan ## 0.11.3 - 2025-03-07 diff --git a/lib/Db/RecipeDb.php b/lib/Db/RecipeDb.php index e951ea690..f4c1d6be2 100755 --- a/lib/Db/RecipeDb.php +++ b/lib/Db/RecipeDb.php @@ -43,7 +43,7 @@ public function findRecipeById(int $id) { ->where('recipe_id = :id'); $qb->setParameter('id', $id, IQueryBuilder::PARAM_INT); - $cursor = $qb->execute(); + $cursor = $qb->executeQuery(); $row = $cursor->fetch(); $cursor->closeCursor(); @@ -67,7 +67,7 @@ public function deleteRecipeById(int $id) { ->where('recipe_id = :id'); $qb->setParameter('id', $id, IQueryBuilder::PARAM_INT); - $qb->execute(); + $qb->executeStatement(); $qb = $this->db->getQueryBuilder(); @@ -75,7 +75,7 @@ public function deleteRecipeById(int $id) { ->where('recipe_id = :id'); $qb->setParameter('id', $id, IQueryBuilder::PARAM_INT); - $qb->execute(); + $qb->executeStatement(); $qb = $this->db->getQueryBuilder(); @@ -83,7 +83,7 @@ public function deleteRecipeById(int $id) { ->where('recipe_id = :id'); $qb->setParameter('id', $id, IQueryBuilder::PARAM_INT); - $qb->execute(); + $qb->executeStatement(); } public function findAllRecipes(string $user_id) { @@ -108,7 +108,7 @@ public function findAllRecipes(string $user_id) { ) ); - $cursor = $qb->execute(); + $cursor = $qb->executeQuery(); $result = $cursor->fetchAll(); $cursor->closeCursor(); @@ -173,7 +173,7 @@ public function findAllKeywords(string $user_id) { ->orderBy('k.name'); $qb->setParameter('user', $user_id, Types::STRING); - $cursor = $qb->execute(); + $cursor = $qb->executeQuery(); $result = $cursor->fetchAll(); $cursor->closeCursor(); @@ -202,7 +202,7 @@ public function findAllCategories(string $user_id) { ->orderBy('c.name'); $qb->setParameter('user', $user_id, Types::STRING); - $cursor = $qb->execute(); + $cursor = $qb->executeQuery(); $result = $cursor->fetchAll(); $cursor->closeCursor(); @@ -230,7 +230,7 @@ public function findAllCategories(string $user_id) { $qb->expr()->isNull('c.name') ); - $cursor = $qb->execute(); + $cursor = $qb->executeQuery(); $row = $cursor->fetch(); $cursor->closeCursor(); @@ -289,7 +289,7 @@ public function getRecipesByCategory(string $category, string $user_id) { ); } - $cursor = $qb->execute(); + $cursor = $qb->executeQuery(); $result = $cursor->fetchAll(); $cursor->closeCursor(); @@ -333,7 +333,7 @@ public function getRecipesByKeywords(string $keywords, string $user_id) { $qb->groupBy(['r.name', 'r.recipe_id', 'kk.name', 'r.date_created', 'r.date_modified', 'c.name']); $qb->orderBy('r.name'); - $cursor = $qb->execute(); + $cursor = $qb->executeQuery(); $result = $cursor->fetchAll(); $cursor->closeCursor(); @@ -388,7 +388,7 @@ public function findRecipes(array $keywords, string $user_id) { $qb->groupBy(['r.name', 'r.recipe_id', 'kk.name', 'r.date_created', 'r.date_modified', 'c.name']); $qb->orderBy('r.name'); - $cursor = $qb->execute(); + $cursor = $qb->executeQuery(); $result = $cursor->fetchAll(); $cursor->closeCursor(); @@ -430,7 +430,7 @@ public function emptySearchIndex(string $user_id) { ->orWhere('user_id = :empty'); $qb->setParameter('user', $user_id, Types::STRING); $qb->setParameter('empty', 'empty', Types::STRING); - $qb->execute(); + $qb->executeStatement(); $qb = $this->db->getQueryBuilder(); $qb->delete(self::DB_TABLE_KEYWORDS) @@ -438,7 +438,7 @@ public function emptySearchIndex(string $user_id) { ->orWhere('user_id = :empty'); $qb->setParameter('user', $user_id, Types::STRING); $qb->setParameter('empty', 'empty', Types::STRING); - $qb->execute(); + $qb->executeStatement(); $qb = $this->db->getQueryBuilder(); $qb->delete(self::DB_TABLE_CATEGORIES) @@ -446,7 +446,7 @@ public function emptySearchIndex(string $user_id) { ->orWhere('user_id = :empty'); $qb->setParameter('user', $user_id, Types::STRING); $qb->setParameter('empty', 'empty', Types::STRING); - $qb->execute(); + $qb->executeStatement(); } private function isRecipeEmpty($json) { @@ -484,7 +484,7 @@ public function deleteRecipes(array $ids, string $userId) { )); } - $qb->execute(); + $qb->executeStatement(); } /** @@ -518,7 +518,7 @@ public function insertRecipes(array $recipes, string $userId) { $dateModified = $this->parseDate($recipe['dateModified']); $qb->setParameter('dateModified', $dateModified, Types::DATETIME); - $qb->execute(); + $qb->executeStatement(); } } @@ -544,7 +544,7 @@ public function updateRecipes(array $recipes, string $userId) { $qb->setParameter('uid', $userId); try { - $qb->execute(); + $qb->executeStatement(); } catch (\Exception $ex) { throw $ex; } @@ -561,7 +561,7 @@ public function getKeywordsOfRecipe(int $recipeId, string $userId) { $qb->setParameter('rid', $recipeId); $qb->setParameter('uid', $userId); - $cursor = $qb->execute(); + $cursor = $qb->executeQuery(); $result = $cursor->fetchAll(); $cursor->closeCursor(); @@ -583,7 +583,7 @@ public function getCategoryOfRecipe(int $recipeId, string $userId) { $qb->setParameter('rid', $recipeId); $qb->setParameter('uid', $userId); - $cursor = $qb->execute(); + $cursor = $qb->executeQuery(); $result = $cursor->fetch(); $cursor->closeCursor(); @@ -601,7 +601,7 @@ public function updateCategoryOfRecipe(int $recipeId, string $categoryName, stri $qb->set('name', $qb->createNamedParameter($categoryName, IQueryBuilder::PARAM_STR)); $qb->setParameter('rid', $recipeId, Types::INTEGER); $qb->setParameter('user', $userId, Types::STRING); - $qb->execute(); + $qb->executeStatement(); } public function addCategoryOfRecipe(int $recipeId, string $categoryName, string $userId) { @@ -623,7 +623,7 @@ public function addCategoryOfRecipe(int $recipeId, string $categoryName, string $qb->setParameter('user', $userId, Types::STRING); try { - $qb->execute(); + $qb->executeStatement(); } catch (\Exception $e) { // Category didn't meet restrictions, skip it } @@ -635,7 +635,7 @@ public function removeCategoryOfRecipe(int $recipeId, string $userId) { ->where('recipe_id = :rid', 'user_id = :user'); $qb->setParameter('rid', $recipeId, Types::INTEGER); $qb->setParameter('user', $userId, Types::STRING); - $qb->execute(); + $qb->executeStatement(); } public function addKeywordPairs(array $pairs, string $userId) { @@ -653,9 +653,9 @@ public function addKeywordPairs(array $pairs, string $userId) { $qb->setParameter('name', $p['name'], Types::STRING); try { - $qb->execute(); + $qb->executeStatement(); } catch (\Exception $ex) { - // The insertion of a keywaord might conflict with the requirements. Skip it. + // The insertion of a keyword might conflict with the requirements. Skip it. } } } @@ -678,7 +678,7 @@ public function removeKeywordPairs(array $pairs, string $userId) { ); } - $qb->execute(); + $qb->executeStatement(); } private function parseDate(?string $date) { diff --git a/lib/Migration/Version000000Date20210701093123.php b/lib/Migration/Version000000Date20210701093123.php index 329bbdf74..c07bf3201 100644 --- a/lib/Migration/Version000000Date20210701093123.php +++ b/lib/Migration/Version000000Date20210701093123.php @@ -38,7 +38,7 @@ public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array ->having('COUNT(*) > 1'); //echo $qb->getSQL() . "\n"; - $cursor = $qb->execute(); + $cursor = $qb->executeQuery(); $result = $cursor->fetchAll(); if (sizeof($result) > 0) { @@ -66,10 +66,10 @@ public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array foreach ($result as $r) { $qb->setParameter('user', $r['user']); $qb->setParameter('recipe', $r['recipe']); - $qb->execute(); + $qb->executeStatement(); $qb2->setParameter('user', $r['user']); - $qb2->execute(); + $qb2->executeStatement(); } } From c801cc8b4aa596ee997dad068fd64541812ca43d Mon Sep 17 00:00:00 2001 From: Christian Wolf Date: Wed, 22 Oct 2025 09:04:29 +0200 Subject: [PATCH 2/3] Update Changelog Signed-off-by: Christian Wolf --- .changelog/current/2882-deprecated-sql-execute.md | 4 ++++ CHANGELOG.md | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 .changelog/current/2882-deprecated-sql-execute.md diff --git a/.changelog/current/2882-deprecated-sql-execute.md b/.changelog/current/2882-deprecated-sql-execute.md new file mode 100644 index 000000000..598396f03 --- /dev/null +++ b/.changelog/current/2882-deprecated-sql-execute.md @@ -0,0 +1,4 @@ +# Maintenance + +- Port away from deprecated execute method + diff --git a/CHANGELOG.md b/CHANGELOG.md index b76837d4f..b9d41ba2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,8 +68,6 @@ Sorry for the inconvience. [#2846](https://github.com/nextcloud/cookbook/pull/2846) @dependabot - Udpate the composer dependencies [#2864](https://github.com/nextcloud/cookbook/pull/2864) @christianlupus -- Port away from deprecated execute method - [#2882](https://github.com/nextcloud/cookbook/pull/2882) @CarlSchwan ## 0.11.3 - 2025-03-07 From 950e8b9503d821a731f632b918d683d4f4b9a9e6 Mon Sep 17 00:00:00 2001 From: Christian Wolf Date: Wed, 22 Oct 2025 09:29:36 +0200 Subject: [PATCH 3/3] Fix test code Signed-off-by: Christian Wolf --- .../Setup/Migrations/AbstractMigrationTestCase.php | 2 +- .../Migrations/Version000000Date20210701093123Test.php | 6 +++--- .../Migrations/Version000000Date20220703174647Test.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Migration/Setup/Migrations/AbstractMigrationTestCase.php b/tests/Migration/Setup/Migrations/AbstractMigrationTestCase.php index 8f836ff3c..949df738e 100644 --- a/tests/Migration/Setup/Migrations/AbstractMigrationTestCase.php +++ b/tests/Migration/Setup/Migrations/AbstractMigrationTestCase.php @@ -128,7 +128,7 @@ private function resetSQLite(): void { $qb = $this->db->getQueryBuilder(); $qb->delete('migrations')->where('app = :app'); $qb->setParameter('app', 'cookbook'); - $qb->execute(); + $qb->executeStatement(); $this->schema->performDropTableCalls(); diff --git a/tests/Migration/Setup/Migrations/Version000000Date20210701093123Test.php b/tests/Migration/Setup/Migrations/Version000000Date20210701093123Test.php index 9da646367..62864f5e0 100644 --- a/tests/Migration/Setup/Migrations/Version000000Date20210701093123Test.php +++ b/tests/Migration/Setup/Migrations/Version000000Date20210701093123Test.php @@ -28,7 +28,7 @@ public function testRedundantEntriesInDB($data, $updatedUsers) { $qb->setParameter('user', $d[0]); $qb->setParameter('recipe', $d[1]); - $this->assertEquals(1, $qb->execute()); + $this->assertEquals(1, $qb->executeStatement()); } // Initialize configuration values to track reindex timestamps @@ -52,7 +52,7 @@ public function testRedundantEntriesInDB($data, $updatedUsers) { }, $data)); foreach ($users as $u) { $qb->setParameter('user', $u); - $this->assertEquals(1, $qb->execute()); + $this->assertEquals(1, $qb->executeStatement()); } // Run the migration under test @@ -69,7 +69,7 @@ public function testRedundantEntriesInDB($data, $updatedUsers) { $qb->setParameter('appid', 'cookbook'); $qb->setParameter('property', 'last_index_update'); - $cursor = $qb->execute(); + $cursor = $qb->executeQuery(); $result = $cursor->fetchAll(); // Filter those entries from the configuration that were marked as to be reindexed diff --git a/tests/Migration/Setup/Migrations/Version000000Date20220703174647Test.php b/tests/Migration/Setup/Migrations/Version000000Date20220703174647Test.php index 0a6f679c1..f176062e4 100644 --- a/tests/Migration/Setup/Migrations/Version000000Date20220703174647Test.php +++ b/tests/Migration/Setup/Migrations/Version000000Date20220703174647Test.php @@ -25,7 +25,7 @@ public function testRedundantEntriesInDB(/*$data, $updatedUsers*/) { $qb->setParameter('user', 'username'); $qb->setParameter('recipe', 1234); - $this->assertEquals(1, $qb->execute()); + $this->assertEquals(1, $qb->executeStatement()); $table = $this->schema->getTable('cookbook_names'); $this->assertFalse($table->hasColumn('date_created')); @@ -41,7 +41,7 @@ public function testRedundantEntriesInDB(/*$data, $updatedUsers*/) { $qb = $this->db->getQueryBuilder(); $qb->select('date_created', 'date_modified')->from('cookbook_names'); - $res = $qb->execute(); + $res = $qb->executeQuery(); $data = $res->fetchAll(); $this->assertEquals(1, count($data));