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/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(); } } 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));