From 865661ed75a542245abcc6639adee769a13267d0 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Wed, 5 May 2021 10:31:54 +0200 Subject: [PATCH] Rename IQueryBuilder::executeUpdate to IQueryBuilder::executeStatement Because executeUpdate wasn't a great name. And in DBAL they also use executeStatement more consistently now. Ref https://github.com/doctrine/dbal/issues/4607 Signed-off-by: Christoph Wurst --- lib/private/DB/QueryBuilder/QueryBuilder.php | 19 +++++++++++++++++-- lib/public/AppFramework/Db/QBMapper.php | 6 +++--- lib/public/DB/QueryBuilder/IQueryBuilder.php | 8 ++++---- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/lib/private/DB/QueryBuilder/QueryBuilder.php b/lib/private/DB/QueryBuilder/QueryBuilder.php index 3549606c2d..ec2c3667fd 100644 --- a/lib/private/DB/QueryBuilder/QueryBuilder.php +++ b/lib/private/DB/QueryBuilder/QueryBuilder.php @@ -309,9 +309,24 @@ class QueryBuilder implements IQueryBuilder { throw new \RuntimeException('Invalid return type for query'); } + /** + * Monkey-patched compatibility layer for apps that were adapted for Nextcloud 22 before + * the first beta, where executeStatement was named executeUpdate. + * + * Static analysis should catch those misuses, but until then let's try to keep things + * running. + * + * @internal + * @deprecated + * @todo drop ASAP + */ public function executeUpdate(): int { + return $this->executeStatement(); + } + + public function executeStatement(): int { if ($this->getType() === \Doctrine\DBAL\Query\QueryBuilder::SELECT) { - throw new \RuntimeException('Invalid query type, expected INSERT, DELETE or UPDATE query'); + throw new \RuntimeException('Invalid query type, expected INSERT, DELETE or UPDATE statement'); } try { @@ -321,7 +336,7 @@ class QueryBuilder implements IQueryBuilder { } if (!is_int($result)) { - throw new \RuntimeException('Invalid return type for query'); + throw new \RuntimeException('Invalid return type for statement'); } return $result; diff --git a/lib/public/AppFramework/Db/QBMapper.php b/lib/public/AppFramework/Db/QBMapper.php index ac6520a9d0..f1450b5dd4 100644 --- a/lib/public/AppFramework/Db/QBMapper.php +++ b/lib/public/AppFramework/Db/QBMapper.php @@ -101,7 +101,7 @@ abstract class QBMapper { ->where( $qb->expr()->eq('id', $qb->createNamedParameter($entity->getId(), $idType)) ); - $qb->executeUpdate(); + $qb->executeStatement(); return $entity; } @@ -132,7 +132,7 @@ abstract class QBMapper { $qb->setValue($column, $qb->createNamedParameter($value, $type)); } - $qb->executeUpdate(); + $qb->executeStatement(); if ($entity->id === null) { // When autoincrement is used id is always an int @@ -211,7 +211,7 @@ abstract class QBMapper { $qb->where( $qb->expr()->eq('id', $qb->createNamedParameter($id, $idType)) ); - $qb->executeUpdate(); + $qb->executeStatement(); return $entity; } diff --git a/lib/public/DB/QueryBuilder/IQueryBuilder.php b/lib/public/DB/QueryBuilder/IQueryBuilder.php index a4f3f3b10b..fa861ed6ee 100644 --- a/lib/public/DB/QueryBuilder/IQueryBuilder.php +++ b/lib/public/DB/QueryBuilder/IQueryBuilder.php @@ -149,7 +149,7 @@ interface IQueryBuilder { /** * Executes this query using the bound parameters and their types. * - * Uses {@see Connection::executeQuery} for select statements and {@see Connection::executeUpdate} + * Uses {@see Connection::executeQuery} for select statements and {@see Connection::executeStatement} * for insert, update and delete statements. * * Warning: until Nextcloud 20, this method could return a \Doctrine\DBAL\Driver\Statement but since @@ -175,15 +175,15 @@ interface IQueryBuilder { public function executeQuery(): IResult; /** - * Execute for insert, update and delete statements + * Execute insert, update and delete statements * - * @return int + * @return int the number of affected rows * @since 22.0.0 * * @throws Exception * @throws \RuntimeException in case of usage with select query */ - public function executeUpdate(): int; + public function executeStatement(): int; /** * Gets the complete SQL string formed by the current specifications of this QueryBuilder.