Skip to content

Commit 1089ad5

Browse files
authored
Merge pull request #26877 from nextcloud/chore/query-builder-execute-statement
Rename IQueryBuilder::executeUpdate to IQueryBuilder::executeStatement
2 parents 4d82a94 + 99f2fa7 commit 1089ad5

8 files changed

Lines changed: 60 additions & 45 deletions

File tree

apps/dav/lib/CalDAV/CalDavBackend.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ public function createCalendar($principalUri, $calendarUri, array $properties) {
805805
foreach ($values as $column => $value) {
806806
$query->setValue($column, $query->createNamedParameter($value));
807807
}
808-
$query->executeUpdate();
808+
$query->executeStatement();
809809
$calendarId = $query->getLastInsertId();
810810

811811
$calendarData = $this->getCalendarById($calendarId);
@@ -860,7 +860,7 @@ public function updateCalendar($calendarId, PropPatch $propPatch) {
860860
$query->set($fieldName, $query->createNamedParameter($value));
861861
}
862862
$query->where($query->expr()->eq('id', $query->createNamedParameter($calendarId)));
863-
$query->executeUpdate();
863+
$query->executeStatement();
864864

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

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

910910
// Only dispatch if we actually deleted anything
911911
if ($calendarData) {
@@ -1130,7 +1130,7 @@ public function createCalendarObject($calendarId, $objectUri, $calendarData, $ca
11301130
'uid' => $query->createNamedParameter($extraData['uid']),
11311131
'calendartype' => $query->createNamedParameter($calendarType),
11321132
])
1133-
->executeUpdate();
1133+
->executeStatement();
11341134

11351135
$this->updateProperties($calendarId, $objectUri, $calendarData, $calendarType);
11361136
$this->addChange($calendarId, $objectUri, 1, $calendarType);
@@ -1203,7 +1203,7 @@ public function updateCalendarObject($calendarId, $objectUri, $calendarData, $ca
12031203
->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId)))
12041204
->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri)))
12051205
->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter($calendarType)))
1206-
->executeUpdate();
1206+
->executeStatement();
12071207

12081208
$this->updateProperties($calendarId, $objectUri, $calendarData, $calendarType);
12091209
$this->addChange($calendarId, $objectUri, 2, $calendarType);
@@ -1257,7 +1257,7 @@ public function setClassification($calendarObjectId, $classification) {
12571257
$query->update('calendarobjects')
12581258
->set('classification', $query->createNamedParameter($classification))
12591259
->where($query->expr()->eq('id', $query->createNamedParameter($calendarObjectId)))
1260-
->executeUpdate();
1260+
->executeStatement();
12611261
}
12621262

12631263
/**
@@ -2151,7 +2151,7 @@ public function createSubscription($principalUri, $uri, array $properties) {
21512151

21522152
$query->insert('calendarsubscriptions')
21532153
->values($valuesToInsert)
2154-
->executeUpdate();
2154+
->executeStatement();
21552155

21562156
$subscriptionId = $query->getLastInsertId();
21572157

@@ -2206,7 +2206,7 @@ public function updateSubscription($subscriptionId, PropPatch $propPatch) {
22062206
$query->set($fieldName, $query->createNamedParameter($value));
22072207
}
22082208
$query->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId)))
2209-
->executeUpdate();
2209+
->executeStatement();
22102210

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

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

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

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

22622262
if ($subscriptionRow) {
22632263
$this->dispatcher->dispatchTyped(new SubscriptionDeletedEvent((int)$subscriptionId, $subscriptionRow, []));
@@ -2347,7 +2347,7 @@ public function deleteSchedulingObject($principalUri, $objectUri) {
23472347
$query->delete('schedulingobjects')
23482348
->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri)))
23492349
->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri)))
2350-
->executeUpdate();
2350+
->executeStatement();
23512351
}
23522352

23532353
/**
@@ -2369,7 +2369,7 @@ public function createSchedulingObject($principalUri, $objectUri, $objectData) {
23692369
'etag' => $query->createNamedParameter(md5($objectData)),
23702370
'size' => $query->createNamedParameter(strlen($objectData))
23712371
])
2372-
->executeUpdate();
2372+
->executeStatement();
23732373
}
23742374

23752375
/**
@@ -2401,7 +2401,7 @@ protected function addChange($calendarId, $objectUri, $operation, $calendarType
24012401
'operation' => $query->createNamedParameter($operation),
24022402
'calendartype' => $query->createNamedParameter($calendarType),
24032403
])
2404-
->executeUpdate();
2404+
->executeStatement();
24052405

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

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

25972597
$this->dispatcher->dispatchTyped(new CalendarUnpublishedEvent((int)$calendarId, $calendarData));
25982598
return null;
@@ -2676,7 +2676,7 @@ public function updateProperties($calendarId, $objectUri, $calendarData, $calend
26762676
$query->setParameter('name', $property->name);
26772677
$query->setParameter('parameter', null);
26782678
$query->setParameter('value', $value);
2679-
$query->executeUpdate();
2679+
$query->executeStatement();
26802680
}
26812681

26822682
if (array_key_exists($property->name, self::$indexParameters)) {
@@ -2693,7 +2693,7 @@ public function updateProperties($calendarId, $objectUri, $calendarData, $calend
26932693
$query->setParameter('name', $property->name);
26942694
$query->setParameter('parameter', mb_strcut($key, 0, 254));
26952695
$query->setParameter('value', mb_strcut($value, 0, 254));
2696-
$query->executeUpdate();
2696+
$query->executeStatement();
26972697
}
26982698
}
26992699
}
@@ -2737,17 +2737,17 @@ public function purgeAllCachedEventsForSubscription($subscriptionId) {
27372737
$query->delete('calendarobjects')
27382738
->where($query->expr()->eq('calendarid', $query->createNamedParameter($subscriptionId)))
27392739
->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter(self::CALENDAR_TYPE_SUBSCRIPTION)))
2740-
->executeUpdate();
2740+
->executeStatement();
27412741

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

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

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

27752775
/**
@@ -2793,7 +2793,7 @@ protected function purgeProperties($calendarId, $objectId) {
27932793
$query->delete($this->dbObjectPropertiesTable)
27942794
->where($query->expr()->eq('objectid', $query->createNamedParameter($objectId)))
27952795
->andWhere($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId)));
2796-
$query->executeUpdate();
2796+
$query->executeStatement();
27972797
}
27982798

27992799
/**

apps/federatedfilesharing/lib/Controller/RequestHandlerController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ public function move($id) {
442442
->set('remote_id', $qb->createNamedParameter($newRemoteId))
443443
->where($qb->expr()->eq('remote_id', $qb->createNamedParameter($id)))
444444
->andWhere($qb->expr()->eq('share_token', $qb->createNamedParameter($token)));
445-
$affected = $query->executeUpdate();
445+
$affected = $query->executeStatement();
446446

447447
if ($affected > 0) {
448448
return new Http\DataResponse(['remote' => $cloudId->getRemote(), 'owner' => $cloudId->getUser()]);

apps/files_trashbin/lib/Trashbin.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ private static function copyFilesToUser($sourcePath, $owner, $targetPath, $user,
226226
->setValue('timestamp', $query->createNamedParameter($timestamp))
227227
->setValue('location', $query->createNamedParameter($targetLocation))
228228
->setValue('user', $query->createNamedParameter($user));
229-
$result = $query->executeUpdate();
229+
$result = $query->executeStatement();
230230
if (!$result) {
231231
\OC::$server->getLogger()->error('trash bin database couldn\'t be updated for the files owner', ['app' => 'files_trashbin']);
232232
}
@@ -353,7 +353,7 @@ public static function move2trash($file_path, $ownerOnly = false) {
353353
->setValue('timestamp', $query->createNamedParameter($timestamp))
354354
->setValue('location', $query->createNamedParameter($location))
355355
->setValue('user', $query->createNamedParameter($owner));
356-
$result = $query->executeUpdate();
356+
$result = $query->executeStatement();
357357
if (!$result) {
358358
\OC::$server->getLogger()->error('trash bin database couldn\'t be updated', ['app' => 'files_trashbin']);
359359
}
@@ -516,7 +516,7 @@ public static function restore($file, $filename, $timestamp) {
516516
->where($query->expr()->eq('user', $query->createNamedParameter($user)))
517517
->andWhere($query->expr()->eq('id', $query->createNamedParameter($filename)))
518518
->andWhere($query->expr()->eq('timestamp', $query->createNamedParameter($timestamp)));
519-
$query->executeUpdate();
519+
$query->executeStatement();
520520
}
521521

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

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

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

752752
/**

apps/oauth2/lib/Db/AccessTokenMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,6 @@ public function deleteByClientId(int $id) {
7777
$qb
7878
->delete($this->tableName)
7979
->where($qb->expr()->eq('client_id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
80-
$qb->executeUpdate();
80+
$qb->executeStatement();
8181
}
8282
}

apps/sharebymail/lib/ShareByMailProvider.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $
696696
*/
697697
$qb->setValue('file_target', $qb->createNamedParameter(''));
698698

699-
$qb->executeUpdate();
699+
$qb->executeStatement();
700700
return $qb->getLastInsertId();
701701
}
702702

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

737737
if ($originalShare->getNote() !== $share->getNote() && $share->getNote() !== '') {
738738
$this->sendNote($share);
@@ -964,7 +964,7 @@ protected function removeShareFromTable($shareId) {
964964
$qb = $this->dbConnection->getQueryBuilder();
965965
$qb->delete('share')
966966
->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId)));
967-
$qb->executeUpdate();
967+
$qb->executeStatement();
968968
}
969969

970970
/**
@@ -1058,7 +1058,7 @@ public function userDeleted($uid, $shareType) {
10581058
$qb->delete('share')
10591059
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_EMAIL)))
10601060
->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)))
1061-
->executeUpdate();
1061+
->executeStatement();
10621062
}
10631063

10641064
/**

lib/private/DB/QueryBuilder/QueryBuilder.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,24 @@ public function executeQuery(): IResult {
309309
throw new \RuntimeException('Invalid return type for query');
310310
}
311311

312+
/**
313+
* Monkey-patched compatibility layer for apps that were adapted for Nextcloud 22 before
314+
* the first beta, where executeStatement was named executeUpdate.
315+
*
316+
* Static analysis should catch those misuses, but until then let's try to keep things
317+
* running.
318+
*
319+
* @internal
320+
* @deprecated
321+
* @todo drop ASAP
322+
*/
312323
public function executeUpdate(): int {
324+
return $this->executeStatement();
325+
}
326+
327+
public function executeStatement(): int {
313328
if ($this->getType() === \Doctrine\DBAL\Query\QueryBuilder::SELECT) {
314-
throw new \RuntimeException('Invalid query type, expected INSERT, DELETE or UPDATE query');
329+
throw new \RuntimeException('Invalid query type, expected INSERT, DELETE or UPDATE statement');
315330
}
316331

317332
try {
@@ -321,7 +336,7 @@ public function executeUpdate(): int {
321336
}
322337

323338
if (!is_int($result)) {
324-
throw new \RuntimeException('Invalid return type for query');
339+
throw new \RuntimeException('Invalid return type for statement');
325340
}
326341

327342
return $result;

lib/public/AppFramework/Db/QBMapper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function delete(Entity $entity): Entity {
101101
->where(
102102
$qb->expr()->eq('id', $qb->createNamedParameter($entity->getId(), $idType))
103103
);
104-
$qb->executeUpdate();
104+
$qb->executeStatement();
105105
return $entity;
106106
}
107107

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

135-
$qb->executeUpdate();
135+
$qb->executeStatement();
136136

137137
if ($entity->id === null) {
138138
// When autoincrement is used id is always an int
@@ -211,7 +211,7 @@ public function update(Entity $entity): Entity {
211211
$qb->where(
212212
$qb->expr()->eq('id', $qb->createNamedParameter($id, $idType))
213213
);
214-
$qb->executeUpdate();
214+
$qb->executeStatement();
215215

216216
return $entity;
217217
}

lib/public/DB/QueryBuilder/IQueryBuilder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function getState();
149149
/**
150150
* Executes this query using the bound parameters and their types.
151151
*
152-
* Uses {@see Connection::executeQuery} for select statements and {@see Connection::executeUpdate}
152+
* Uses {@see Connection::executeQuery} for select statements and {@see Connection::executeStatement}
153153
* for insert, update and delete statements.
154154
*
155155
* Warning: until Nextcloud 20, this method could return a \Doctrine\DBAL\Driver\Statement but since
@@ -175,15 +175,15 @@ public function execute();
175175
public function executeQuery(): IResult;
176176

177177
/**
178-
* Execute for insert, update and delete statements
178+
* Execute insert, update and delete statements
179179
*
180-
* @return int
180+
* @return int the number of affected rows
181181
* @since 22.0.0
182182
*
183183
* @throws Exception
184184
* @throws \RuntimeException in case of usage with select query
185185
*/
186-
public function executeUpdate(): int;
186+
public function executeStatement(): int;
187187

188188
/**
189189
* Gets the complete SQL string formed by the current specifications of this QueryBuilder.

0 commit comments

Comments
 (0)