Skip to content

Commit

Permalink
Merge pull request #26877 from nextcloud/chore/query-builder-execute-…
Browse files Browse the repository at this point in the history
…statement

Rename IQueryBuilder::executeUpdate to IQueryBuilder::executeStatement
  • Loading branch information
MorrisJobke committed May 5, 2021
2 parents 4d82a94 + 99f2fa7 commit 1089ad5
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 45 deletions.
48 changes: 24 additions & 24 deletions apps/dav/lib/CalDAV/CalDavBackend.php
Expand Up @@ -805,7 +805,7 @@ public function createCalendar($principalUri, $calendarUri, array $properties) {
foreach ($values as $column => $value) {
$query->setValue($column, $query->createNamedParameter($value));
}
$query->executeUpdate();
$query->executeStatement();
$calendarId = $query->getLastInsertId();

$calendarData = $this->getCalendarById($calendarId);
Expand Down Expand Up @@ -860,7 +860,7 @@ public function updateCalendar($calendarId, PropPatch $propPatch) {
$query->set($fieldName, $query->createNamedParameter($value));
}
$query->where($query->expr()->eq('id', $query->createNamedParameter($calendarId)));
$query->executeUpdate();
$query->executeStatement();

$this->addChange($calendarId, "", 2);

Expand Down Expand Up @@ -905,7 +905,7 @@ public function deleteCalendar($calendarId) {
$query->delete($this->dbObjectPropertiesTable)
->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId)))
->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter(self::CALENDAR_TYPE_CALENDAR)))
->executeUpdate();
->executeStatement();

// Only dispatch if we actually deleted anything
if ($calendarData) {
Expand Down Expand Up @@ -1130,7 +1130,7 @@ public function createCalendarObject($calendarId, $objectUri, $calendarData, $ca
'uid' => $query->createNamedParameter($extraData['uid']),
'calendartype' => $query->createNamedParameter($calendarType),
])
->executeUpdate();
->executeStatement();

$this->updateProperties($calendarId, $objectUri, $calendarData, $calendarType);
$this->addChange($calendarId, $objectUri, 1, $calendarType);
Expand Down Expand Up @@ -1203,7 +1203,7 @@ public function updateCalendarObject($calendarId, $objectUri, $calendarData, $ca
->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId)))
->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri)))
->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter($calendarType)))
->executeUpdate();
->executeStatement();

$this->updateProperties($calendarId, $objectUri, $calendarData, $calendarType);
$this->addChange($calendarId, $objectUri, 2, $calendarType);
Expand Down Expand Up @@ -1257,7 +1257,7 @@ public function setClassification($calendarObjectId, $classification) {
$query->update('calendarobjects')
->set('classification', $query->createNamedParameter($classification))
->where($query->expr()->eq('id', $query->createNamedParameter($calendarObjectId)))
->executeUpdate();
->executeStatement();
}

/**
Expand Down Expand Up @@ -2151,7 +2151,7 @@ public function createSubscription($principalUri, $uri, array $properties) {

$query->insert('calendarsubscriptions')
->values($valuesToInsert)
->executeUpdate();
->executeStatement();

$subscriptionId = $query->getLastInsertId();

Expand Down Expand Up @@ -2206,7 +2206,7 @@ public function updateSubscription($subscriptionId, PropPatch $propPatch) {
$query->set($fieldName, $query->createNamedParameter($value));
}
$query->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId)))
->executeUpdate();
->executeStatement();

$subscriptionRow = $this->getSubscriptionById($subscriptionId);
$this->dispatcher->dispatchTyped(new SubscriptionUpdatedEvent((int)$subscriptionId, $subscriptionRow, [], $mutations));
Expand Down Expand Up @@ -2241,23 +2241,23 @@ public function deleteSubscription($subscriptionId) {
$query = $this->db->getQueryBuilder();
$query->delete('calendarsubscriptions')
->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId)))
->executeUpdate();
->executeStatement();

$query = $this->db->getQueryBuilder();
$query->delete('calendarobjects')
->where($query->expr()->eq('calendarid', $query->createNamedParameter($subscriptionId)))
->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter(self::CALENDAR_TYPE_SUBSCRIPTION)))
->executeUpdate();
->executeStatement();

$query->delete('calendarchanges')
->where($query->expr()->eq('calendarid', $query->createNamedParameter($subscriptionId)))
->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter(self::CALENDAR_TYPE_SUBSCRIPTION)))
->executeUpdate();
->executeStatement();

$query->delete($this->dbObjectPropertiesTable)
->where($query->expr()->eq('calendarid', $query->createNamedParameter($subscriptionId)))
->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter(self::CALENDAR_TYPE_SUBSCRIPTION)))
->executeUpdate();
->executeStatement();

if ($subscriptionRow) {
$this->dispatcher->dispatchTyped(new SubscriptionDeletedEvent((int)$subscriptionId, $subscriptionRow, []));
Expand Down Expand Up @@ -2347,7 +2347,7 @@ public function deleteSchedulingObject($principalUri, $objectUri) {
$query->delete('schedulingobjects')
->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri)))
->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri)))
->executeUpdate();
->executeStatement();
}

/**
Expand All @@ -2369,7 +2369,7 @@ public function createSchedulingObject($principalUri, $objectUri, $objectData) {
'etag' => $query->createNamedParameter(md5($objectData)),
'size' => $query->createNamedParameter(strlen($objectData))
])
->executeUpdate();
->executeStatement();
}

/**
Expand Down Expand Up @@ -2401,7 +2401,7 @@ protected function addChange($calendarId, $objectUri, $operation, $calendarType
'operation' => $query->createNamedParameter($operation),
'calendartype' => $query->createNamedParameter($calendarType),
])
->executeUpdate();
->executeStatement();

$stmt = $this->db->prepare("UPDATE `*PREFIX*$table` SET `synctoken` = `synctoken` + 1 WHERE `id` = ?");
$stmt->execute([
Expand Down Expand Up @@ -2584,15 +2584,15 @@ public function setPublishStatus($value, $calendar) {
'resourceid' => $query->createNamedParameter($calendar->getResourceId()),
'publicuri' => $query->createNamedParameter($publicUri)
]);
$query->executeUpdate();
$query->executeStatement();

$this->dispatcher->dispatchTyped(new CalendarPublishedEvent((int)$calendarId, $calendarData, $publicUri));
return $publicUri;
}
$query->delete('dav_shares')
->where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId())))
->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC)));
$query->executeUpdate();
$query->executeStatement();

$this->dispatcher->dispatchTyped(new CalendarUnpublishedEvent((int)$calendarId, $calendarData));
return null;
Expand Down Expand Up @@ -2676,7 +2676,7 @@ public function updateProperties($calendarId, $objectUri, $calendarData, $calend
$query->setParameter('name', $property->name);
$query->setParameter('parameter', null);
$query->setParameter('value', $value);
$query->executeUpdate();
$query->executeStatement();
}

if (array_key_exists($property->name, self::$indexParameters)) {
Expand All @@ -2693,7 +2693,7 @@ public function updateProperties($calendarId, $objectUri, $calendarData, $calend
$query->setParameter('name', $property->name);
$query->setParameter('parameter', mb_strcut($key, 0, 254));
$query->setParameter('value', mb_strcut($value, 0, 254));
$query->executeUpdate();
$query->executeStatement();
}
}
}
Expand Down Expand Up @@ -2737,17 +2737,17 @@ public function purgeAllCachedEventsForSubscription($subscriptionId) {
$query->delete('calendarobjects')
->where($query->expr()->eq('calendarid', $query->createNamedParameter($subscriptionId)))
->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter(self::CALENDAR_TYPE_SUBSCRIPTION)))
->executeUpdate();
->executeStatement();

$query->delete('calendarchanges')
->where($query->expr()->eq('calendarid', $query->createNamedParameter($subscriptionId)))
->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter(self::CALENDAR_TYPE_SUBSCRIPTION)))
->executeUpdate();
->executeStatement();

$query->delete($this->dbObjectPropertiesTable)
->where($query->expr()->eq('calendarid', $query->createNamedParameter($subscriptionId)))
->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter(self::CALENDAR_TYPE_SUBSCRIPTION)))
->executeUpdate();
->executeStatement();

foreach ($uris as $uri) {
$this->addChange($subscriptionId, $uri, 3, self::CALENDAR_TYPE_SUBSCRIPTION);
Expand All @@ -2769,7 +2769,7 @@ public function moveCalendar($uriName, $uriOrigin, $uriDestination, $newUriName
->set('uri', $query->createNamedParameter($newUriName ?: $uriName))
->where($query->expr()->eq('principaluri', $query->createNamedParameter($uriOrigin)))
->andWhere($query->expr()->eq('uri', $query->createNamedParameter($uriName)))
->executeUpdate();
->executeStatement();
}

/**
Expand All @@ -2793,7 +2793,7 @@ protected function purgeProperties($calendarId, $objectId) {
$query->delete($this->dbObjectPropertiesTable)
->where($query->expr()->eq('objectid', $query->createNamedParameter($objectId)))
->andWhere($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId)));
$query->executeUpdate();
$query->executeStatement();
}

/**
Expand Down
Expand Up @@ -442,7 +442,7 @@ public function move($id) {
->set('remote_id', $qb->createNamedParameter($newRemoteId))
->where($qb->expr()->eq('remote_id', $qb->createNamedParameter($id)))
->andWhere($qb->expr()->eq('share_token', $qb->createNamedParameter($token)));
$affected = $query->executeUpdate();
$affected = $query->executeStatement();

if ($affected > 0) {
return new Http\DataResponse(['remote' => $cloudId->getRemote(), 'owner' => $cloudId->getUser()]);
Expand Down
12 changes: 6 additions & 6 deletions apps/files_trashbin/lib/Trashbin.php
Expand Up @@ -226,7 +226,7 @@ private static function copyFilesToUser($sourcePath, $owner, $targetPath, $user,
->setValue('timestamp', $query->createNamedParameter($timestamp))
->setValue('location', $query->createNamedParameter($targetLocation))
->setValue('user', $query->createNamedParameter($user));
$result = $query->executeUpdate();
$result = $query->executeStatement();
if (!$result) {
\OC::$server->getLogger()->error('trash bin database couldn\'t be updated for the files owner', ['app' => 'files_trashbin']);
}
Expand Down Expand Up @@ -353,7 +353,7 @@ public static function move2trash($file_path, $ownerOnly = false) {
->setValue('timestamp', $query->createNamedParameter($timestamp))
->setValue('location', $query->createNamedParameter($location))
->setValue('user', $query->createNamedParameter($owner));
$result = $query->executeUpdate();
$result = $query->executeStatement();
if (!$result) {
\OC::$server->getLogger()->error('trash bin database couldn\'t be updated', ['app' => 'files_trashbin']);
}
Expand Down Expand Up @@ -516,7 +516,7 @@ public static function restore($file, $filename, $timestamp) {
->where($query->expr()->eq('user', $query->createNamedParameter($user)))
->andWhere($query->expr()->eq('id', $query->createNamedParameter($filename)))
->andWhere($query->expr()->eq('timestamp', $query->createNamedParameter($timestamp)));
$query->executeUpdate();
$query->executeStatement();
}

return true;
Expand Down Expand Up @@ -606,7 +606,7 @@ public static function deleteAll() {
$query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
$query->delete('files_trash')
->where($query->expr()->eq('user', $query->createNamedParameter($user)));
$query->executeUpdate();
$query->executeStatement();

// Bulk PostDelete-Hook
\OC_Hook::emit('\OCP\Trashbin', 'deleteAll', ['paths' => $filePaths]);
Expand Down Expand Up @@ -660,7 +660,7 @@ public static function delete($filename, $user, $timestamp = null) {
->where($query->expr()->eq('user', $query->createNamedParameter($user)))
->andWhere($query->expr()->eq('id', $query->createNamedParameter($filename)))
->andWhere($query->expr()->eq('timestamp', $query->createNamedParameter($timestamp)));
$query->executeUpdate();
$query->executeStatement();

$file = $filename . '.d' . $timestamp;
} else {
Expand Down Expand Up @@ -746,7 +746,7 @@ public static function deleteUser($uid) {
$query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
$query->delete('files_trash')
->where($query->expr()->eq('user', $query->createNamedParameter($uid)));
return (bool) $query->executeUpdate();
return (bool) $query->executeStatement();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion apps/oauth2/lib/Db/AccessTokenMapper.php
Expand Up @@ -77,6 +77,6 @@ public function deleteByClientId(int $id) {
$qb
->delete($this->tableName)
->where($qb->expr()->eq('client_id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
$qb->executeUpdate();
$qb->executeStatement();
}
}
8 changes: 4 additions & 4 deletions apps/sharebymail/lib/ShareByMailProvider.php
Expand Up @@ -696,7 +696,7 @@ protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $
*/
$qb->setValue('file_target', $qb->createNamedParameter(''));

$qb->executeUpdate();
$qb->executeStatement();
return $qb->getLastInsertId();
}

Expand Down Expand Up @@ -732,7 +732,7 @@ public function update(IShare $share, $plainTextPassword = null) {
->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
->set('note', $qb->createNamedParameter($share->getNote()))
->set('hide_download', $qb->createNamedParameter((int)$share->getHideDownload(), IQueryBuilder::PARAM_INT))
->executeUpdate();
->executeStatement();

if ($originalShare->getNote() !== $share->getNote() && $share->getNote() !== '') {
$this->sendNote($share);
Expand Down Expand Up @@ -964,7 +964,7 @@ protected function removeShareFromTable($shareId) {
$qb = $this->dbConnection->getQueryBuilder();
$qb->delete('share')
->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId)));
$qb->executeUpdate();
$qb->executeStatement();
}

/**
Expand Down Expand Up @@ -1058,7 +1058,7 @@ public function userDeleted($uid, $shareType) {
$qb->delete('share')
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_EMAIL)))
->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)))
->executeUpdate();
->executeStatement();
}

/**
Expand Down
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 1089ad5

Please sign in to comment.