Skip to content

Commit

Permalink
Rename IQueryBuilder::executeUpdate to IQueryBuilder::executeStatement
Browse files Browse the repository at this point in the history
Because executeUpdate wasn't a great name. And in DBAL they also use
executeStatement more consistently now.

Ref doctrine/dbal#4607

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
  • Loading branch information
ChristophWurst committed May 5, 2021
1 parent 6d3aef1 commit 865661e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
19 changes: 17 additions & 2 deletions lib/private/DB/QueryBuilder/QueryBuilder.php
Expand Up @@ -309,9 +309,24 @@ public function executeQuery(): IResult {
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 {
Expand All @@ -321,7 +336,7 @@ public function executeUpdate(): int {
}

if (!is_int($result)) {
throw new \RuntimeException('Invalid return type for query');
throw new \RuntimeException('Invalid return type for statement');
}

return $result;
Expand Down
6 changes: 3 additions & 3 deletions lib/public/AppFramework/Db/QBMapper.php
Expand Up @@ -101,7 +101,7 @@ public function delete(Entity $entity): Entity {
->where(
$qb->expr()->eq('id', $qb->createNamedParameter($entity->getId(), $idType))
);
$qb->executeUpdate();
$qb->executeStatement();
return $entity;
}

Expand Down Expand Up @@ -132,7 +132,7 @@ public function insert(Entity $entity): Entity {
$qb->setValue($column, $qb->createNamedParameter($value, $type));
}

$qb->executeUpdate();
$qb->executeStatement();

if ($entity->id === null) {
// When autoincrement is used id is always an int
Expand Down Expand Up @@ -211,7 +211,7 @@ public function update(Entity $entity): Entity {
$qb->where(
$qb->expr()->eq('id', $qb->createNamedParameter($id, $idType))
);
$qb->executeUpdate();
$qb->executeStatement();

return $entity;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/public/DB/QueryBuilder/IQueryBuilder.php
Expand Up @@ -149,7 +149,7 @@ public function getState();
/**
* 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
Expand All @@ -175,15 +175,15 @@ public function execute();
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.
Expand Down

0 comments on commit 865661e

Please sign in to comment.