Skip to content

Commit 6f0537b

Browse files
Merge pull request #56494 from nextcloud/carl/result-improv
Improve IResult
2 parents 4534507 + 59e6529 commit 6f0537b

File tree

121 files changed

+698
-389
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+698
-389
lines changed

apps/contactsinteraction/lib/Db/RecentContactMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function findLastUpdatedForUserId(string $uid): ?int {
9494
->setMaxResults(1);
9595

9696
$cursor = $select->executeQuery();
97-
$row = $cursor->fetch();
97+
$row = $cursor->fetchAssociative();
9898

9999
if ($row === false) {
100100
return null;

apps/contactsinteraction/lib/Migration/FixVcardCategory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function run(IOutput $output): void {
5353
->set('card', $query->createParameter('card'))
5454
->where($query->expr()->eq('id', $query->createParameter('id')));
5555

56-
while ($card = $cardsWithTranslatedCategory->fetch()) {
56+
while ($card = $cardsWithTranslatedCategory->fetchAssociative()) {
5757
$output->advance(1);
5858

5959
try {

apps/dav/lib/BackgroundJob/BuildReminderIndexBackgroundJob.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ private function buildIndex(int $offset, int $stopAt):int {
7474
->orderBy('id', 'ASC');
7575

7676
$result = $query->executeQuery();
77-
while ($row = $result->fetch(\PDO::FETCH_ASSOC)) {
77+
while ($row = $result->fetchAssociative()) {
7878
$offset = (int)$row['id'];
7979
if (is_resource($row['calendardata'])) {
8080
$row['calendardata'] = stream_get_contents($row['calendardata']);

apps/dav/lib/BackgroundJob/CleanupOrphanedChildrenJob.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private function cleanUpOrphans(
7272
}
7373

7474
$result = $selectQb->executeQuery();
75-
$rows = $result->fetchAll();
75+
$rows = $result->fetchAllAssociative();
7676
$result->closeCursor();
7777
if (empty($rows)) {
7878
return 0;

apps/dav/lib/CalDAV/CalDavBackend.php

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public function getDeletedCalendars(int $deletedBefore): array {
283283
->andWhere($qb->expr()->lt('deleted_at', $qb->createNamedParameter($deletedBefore)));
284284
$result = $qb->executeQuery();
285285
$calendars = [];
286-
while (($row = $result->fetch()) !== false) {
286+
while (($row = $result->fetchAssociative()) !== false) {
287287
$calendars[] = [
288288
'id' => (int)$row['id'],
289289
'deleted_at' => (int)$row['deleted_at'],
@@ -345,7 +345,7 @@ public function getCalendarsForUser($principalUri) {
345345
$result = $query->executeQuery();
346346

347347
$calendars = [];
348-
while ($row = $result->fetch()) {
348+
while ($row = $result->fetchAssociative()) {
349349
$row['principaluri'] = (string)$row['principaluri'];
350350
$components = [];
351351
if ($row['components']) {
@@ -408,7 +408,7 @@ public function getCalendarsForUser($principalUri) {
408408
$results = $select->executeQuery();
409409

410410
$readOnlyPropertyName = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only';
411-
while ($row = $results->fetch()) {
411+
while ($row = $results->fetchAssociative()) {
412412
$row['principaluri'] = (string)$row['principaluri'];
413413
if ($row['principaluri'] === $principalUri) {
414414
continue;
@@ -478,7 +478,7 @@ public function getUsersOwnCalendars($principalUri) {
478478
->orderBy('calendarorder', 'ASC');
479479
$stmt = $query->executeQuery();
480480
$calendars = [];
481-
while ($row = $stmt->fetch()) {
481+
while ($row = $stmt->fetchAssociative()) {
482482
$row['principaluri'] = (string)$row['principaluri'];
483483
$components = [];
484484
if ($row['components']) {
@@ -528,7 +528,7 @@ public function getPublicCalendars() {
528528
->andWhere($query->expr()->eq('s.type', $query->createNamedParameter('calendar')))
529529
->executeQuery();
530530

531-
while ($row = $result->fetch()) {
531+
while ($row = $result->fetchAssociative()) {
532532
$row['principaluri'] = (string)$row['principaluri'];
533533
[, $name] = Uri\split($row['principaluri']);
534534
$row['displayname'] = $row['displayname'] . "($name)";
@@ -586,7 +586,7 @@ public function getPublicCalendar($uri) {
586586
->andWhere($query->expr()->eq('s.publicuri', $query->createNamedParameter($uri)))
587587
->executeQuery();
588588

589-
$row = $result->fetch();
589+
$row = $result->fetchAssociative();
590590

591591
$result->closeCursor();
592592

@@ -643,7 +643,7 @@ public function getCalendarByUri($principal, $uri) {
643643
->setMaxResults(1);
644644
$stmt = $query->executeQuery();
645645

646-
$row = $stmt->fetch();
646+
$row = $stmt->fetchAssociative();
647647
$stmt->closeCursor();
648648
if ($row === false) {
649649
return null;
@@ -692,7 +692,7 @@ public function getCalendarById(int $calendarId): ?array {
692692
->setMaxResults(1);
693693
$stmt = $query->executeQuery();
694694

695-
$row = $stmt->fetch();
695+
$row = $stmt->fetchAssociative();
696696
$stmt->closeCursor();
697697
if ($row === false) {
698698
return null;
@@ -740,7 +740,7 @@ public function getSubscriptionById($subscriptionId) {
740740
->orderBy('calendarorder', 'asc');
741741
$stmt = $query->executeQuery();
742742

743-
$row = $stmt->fetch();
743+
$row = $stmt->fetchAssociative();
744744
$stmt->closeCursor();
745745
if ($row === false) {
746746
return null;
@@ -777,7 +777,7 @@ public function getSubscriptionByUri(string $principal, string $uri): ?array {
777777
->setMaxResults(1);
778778
$stmt = $query->executeQuery();
779779

780-
$row = $stmt->fetch();
780+
$row = $stmt->fetchAssociative();
781781
$stmt->closeCursor();
782782
if ($row === false) {
783783
return null;
@@ -1044,7 +1044,7 @@ public function exportCalendar(int $calendarId, int $calendarType = self::CALEND
10441044
$rs = $qb->executeQuery();
10451045
// iterate through results
10461046
try {
1047-
while (($row = $rs->fetch()) !== false) {
1047+
while (($row = $rs->fetchAssociative()) !== false) {
10481048
yield $row;
10491049
}
10501050
} finally {
@@ -1076,7 +1076,7 @@ public function getLimitedCalendarObjects(int $calendarId, int $calendarType = s
10761076
$stmt = $query->executeQuery();
10771077

10781078
$result = [];
1079-
while (($row = $stmt->fetch()) !== false) {
1079+
while (($row = $stmt->fetchAssociative()) !== false) {
10801080
$result[$row['uid']] = [
10811081
'id' => $row['id'],
10821082
'etag' => $row['etag'],
@@ -1141,7 +1141,7 @@ public function getCalendarObjects($calendarId, $calendarType = self::CALENDAR_T
11411141
$stmt = $query->executeQuery();
11421142

11431143
$result = [];
1144-
while (($row = $stmt->fetch()) !== false) {
1144+
while (($row = $stmt->fetchAssociative()) !== false) {
11451145
$result[] = [
11461146
'id' => $row['id'],
11471147
'uri' => $row['uri'],
@@ -1168,7 +1168,7 @@ public function getDeletedCalendarObjects(int $deletedBefore): array {
11681168
$stmt = $query->executeQuery();
11691169

11701170
$result = [];
1171-
while (($row = $stmt->fetch()) !== false) {
1171+
while (($row = $stmt->fetchAssociative()) !== false) {
11721172
$result[] = [
11731173
'id' => $row['id'],
11741174
'uri' => $row['uri'],
@@ -1207,7 +1207,7 @@ public function getDeletedCalendarObjectsByPrincipal(string $principalUri): arra
12071207
$stmt = $query->executeQuery();
12081208

12091209
$result = [];
1210-
while ($row = $stmt->fetch()) {
1210+
while ($row = $stmt->fetchAssociative()) {
12111211
$result[] = [
12121212
'id' => $row['id'],
12131213
'uri' => $row['uri'],
@@ -1255,7 +1255,7 @@ public function getCalendarObject($calendarId, $objectUri, int $calendarType = s
12551255
->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri)))
12561256
->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter($calendarType)));
12571257
$stmt = $query->executeQuery();
1258-
$row = $stmt->fetch();
1258+
$row = $stmt->fetchAssociative();
12591259
$stmt->closeCursor();
12601260

12611261
if (!$row) {
@@ -1316,7 +1316,7 @@ public function getMultipleCalendarObjects($calendarId, array $uris, $calendarTy
13161316
$query->setParameter('uri', $uris, IQueryBuilder::PARAM_STR_ARRAY);
13171317
$result = $query->executeQuery();
13181318

1319-
while ($row = $result->fetch()) {
1319+
while ($row = $result->fetchAssociative()) {
13201320
$objects[] = [
13211321
'id' => $row['id'],
13221322
'uri' => $row['uri'],
@@ -1383,7 +1383,7 @@ public function createCalendarObject($calendarId, $objectUri, $calendarData, $ca
13831383
->andWhere($qbDel->expr()->eq('calendartype', $qbDel->createNamedParameter($calendarType)))
13841384
->andWhere($qbDel->expr()->isNotNull('deleted_at'));
13851385
$result = $qbDel->executeQuery();
1386-
$found = $result->fetch();
1386+
$found = $result->fetchAssociative();
13871387
$result->closeCursor();
13881388
if ($found !== false) {
13891389
// the object existed previously but has been deleted
@@ -1675,7 +1675,7 @@ public function restoreCalendarObject(array $objectData): void {
16751675
->from('calendarobjects')
16761676
->where($qb2->expr()->eq('id', $qb2->createNamedParameter($id, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT));
16771677
$result = $selectObject->executeQuery();
1678-
$row = $result->fetch();
1678+
$row = $result->fetchAssociative();
16791679
$result->closeCursor();
16801680
if ($row === false) {
16811681
// Welp, this should possibly not have happened, but let's ignore
@@ -1798,7 +1798,7 @@ public function calendarQuery($calendarId, array $filters, $calendarType = self:
17981798
$stmt = $query->executeQuery();
17991799

18001800
$result = [];
1801-
while ($row = $stmt->fetch()) {
1801+
while ($row = $stmt->fetchAssociative()) {
18021802
// if we leave it as a blob we can't read it both from the post filter and the rowToCalendarObject
18031803
if (isset($row['calendardata'])) {
18041804
$row['calendardata'] = $this->readBlob($row['calendardata']);
@@ -1958,7 +1958,7 @@ public function calendarSearch($principalUri, array $filters, $limit = null, $of
19581958
$stmt = $query->executeQuery();
19591959

19601960
$result = [];
1961-
while ($row = $stmt->fetch()) {
1961+
while ($row = $stmt->fetchAssociative()) {
19621962
$path = $uriMapper[$row['calendarid']] . '/' . $row['uri'];
19631963
if (!in_array($path, $result)) {
19641964
$result[] = $path;
@@ -2171,7 +2171,7 @@ private function searchCalendarObjects(IQueryBuilder $query, ?DateTimeInterface
21712171

21722172
$result = $query->executeQuery();
21732173

2174-
while (($row = $result->fetch()) !== false) {
2174+
while (($row = $result->fetchAssociative()) !== false) {
21752175
if ($filterByTimeRange === false) {
21762176
// No filter required
21772177
$calendarObjects[] = $row;
@@ -2399,7 +2399,7 @@ public function searchPrincipalUri(string $principalUri,
23992399

24002400
$result = $calendarObjectIdQuery->executeQuery();
24012401
$matches = [];
2402-
while (($row = $result->fetch()) !== false) {
2402+
while (($row = $result->fetchAssociative()) !== false) {
24032403
$matches[] = (int)$row['objectid'];
24042404
}
24052405
$result->closeCursor();
@@ -2411,7 +2411,7 @@ public function searchPrincipalUri(string $principalUri,
24112411

24122412
$result = $query->executeQuery();
24132413
$calendarObjects = [];
2414-
while (($array = $result->fetch()) !== false) {
2414+
while (($array = $result->fetchAssociative()) !== false) {
24152415
$array['calendarid'] = (int)$array['calendarid'];
24162416
$array['calendartype'] = (int)$array['calendartype'];
24172417
$array['calendardata'] = $this->readBlob($array['calendardata']);
@@ -2456,7 +2456,7 @@ public function getCalendarObjectByUID($principalUri, $uid, $calendarUri = null)
24562456
}
24572457

24582458
$stmt = $query->executeQuery();
2459-
$row = $stmt->fetch();
2459+
$row = $stmt->fetchAssociative();
24602460
$stmt->closeCursor();
24612461
if ($row) {
24622462
return $row['calendaruri'] . '/' . $row['objecturi'];
@@ -2474,7 +2474,7 @@ public function getCalendarObjectById(string $principalUri, int $id): ?array {
24742474
->where($query->expr()->eq('c.principaluri', $query->createNamedParameter($principalUri)))
24752475
->andWhere($query->expr()->eq('co.id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT));
24762476
$stmt = $query->executeQuery();
2477-
$row = $stmt->fetch();
2477+
$row = $stmt->fetchAssociative();
24782478
$stmt->closeCursor();
24792479

24802480
if (!$row) {
@@ -2600,11 +2600,11 @@ public function getChangesForCalendar($calendarId, $syncToken, $syncLevel, $limi
26002600
$result = ['syncToken' => $currentToken, 'added' => [], 'modified' => [], 'deleted' => []];
26012601
// retrieve results
26022602
if ($initialSync) {
2603-
$result['added'] = $stmt->fetchAll(\PDO::FETCH_COLUMN);
2603+
$result['added'] = $stmt->fetchFirstColumn();
26042604
} else {
26052605
// \PDO::FETCH_NUM is needed due to the inconsistent field names
26062606
// produced by doctrine for MAX() with different databases
2607-
while ($entry = $stmt->fetch(\PDO::FETCH_NUM)) {
2607+
while ($entry = $stmt->fetchNumeric()) {
26082608
// assign uri (column 0) to appropriate mutation based on operation (column 1)
26092609
// forced (int) is needed as doctrine with OCI returns the operation field as string not integer
26102610
match ((int)$entry[1]) {
@@ -2670,7 +2670,7 @@ public function getSubscriptionsForUser($principalUri) {
26702670
$stmt = $query->executeQuery();
26712671

26722672
$subscriptions = [];
2673-
while ($row = $stmt->fetch()) {
2673+
while ($row = $stmt->fetchAssociative()) {
26742674
$subscription = [
26752675
'id' => $row['id'],
26762676
'uri' => $row['uri'],
@@ -2855,7 +2855,7 @@ public function getSchedulingObject($principalUri, $objectUri) {
28552855
->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri)))
28562856
->executeQuery();
28572857

2858-
$row = $stmt->fetch();
2858+
$row = $stmt->fetchAssociative();
28592859

28602860
if (!$row) {
28612861
return null;
@@ -2889,7 +2889,7 @@ public function getSchedulingObjects($principalUri) {
28892889
->executeQuery();
28902890

28912891
$results = [];
2892-
while (($row = $stmt->fetch()) !== false) {
2892+
while (($row = $stmt->fetchAssociative()) !== false) {
28932893
$results[] = [
28942894
'calendardata' => $row['calendardata'],
28952895
'uri' => $row['uri'],
@@ -2939,7 +2939,7 @@ public function deleteOutdatedSchedulingObjects(int $modifiedBefore, int $limit)
29392939
}
29402940
$ids = array_map(static function (array $id) {
29412941
return (int)$id[0];
2942-
}, $result->fetchAll(\PDO::FETCH_NUM));
2942+
}, $result->fetchAllNumeric());
29432943
$result->closeCursor();
29442944

29452945
$numDeleted = 0;
@@ -3040,7 +3040,7 @@ public function restoreChanges(int $calendarId, int $calendarType = self::CALEND
30403040
)
30413041
);
30423042
$resultAdded = $qbAdded->executeQuery();
3043-
$addedUris = $resultAdded->fetchAll(\PDO::FETCH_COLUMN);
3043+
$addedUris = $resultAdded->fetchFirstColumn();
30443044
$resultAdded->closeCursor();
30453045
// Track everything as changed
30463046
// Tracking the creation is not necessary because \OCA\DAV\CalDAV\CalDavBackend::getChangesForCalendar
@@ -3060,7 +3060,7 @@ public function restoreChanges(int $calendarId, int $calendarType = self::CALEND
30603060
$resultDeleted = $qbDeleted->executeQuery();
30613061
$deletedUris = array_map(function (string $uri) {
30623062
return str_replace('-deleted.ics', '.ics', $uri);
3063-
}, $resultDeleted->fetchAll(\PDO::FETCH_COLUMN));
3063+
}, $resultDeleted->fetchFirstColumn());
30643064
$resultDeleted->closeCursor();
30653065
$this->addChanges($calendarId, $deletedUris, 3, $calendarType);
30663066
}, $this->db);
@@ -3306,7 +3306,7 @@ public function preloadPublishStatuses(array $resourceIds): void {
33063306
->executeQuery();
33073307

33083308
$hasPublishStatuses = [];
3309-
while ($row = $result->fetch()) {
3309+
while ($row = $result->fetchAssociative()) {
33103310
$this->publishStatusCache->set((string)$row['resourceid'], $row['publicuri']);
33113311
$hasPublishStatuses[(int)$row['resourceid']] = true;
33123312
}
@@ -3419,7 +3419,7 @@ public function deleteAllBirthdayCalendars() {
34193419
->where($query->expr()->eq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI)))
34203420
->executeQuery();
34213421

3422-
while (($row = $result->fetch()) !== false) {
3422+
while (($row = $result->fetchAssociative()) !== false) {
34233423
$this->deleteCalendar(
34243424
$row['id'],
34253425
true // No data to keep in the trashbin, if the user re-enables then we regenerate
@@ -3442,7 +3442,7 @@ public function purgeAllCachedEventsForSubscription($subscriptionId) {
34423442
$stmt = $query->executeQuery();
34433443

34443444
$uris = [];
3445-
while (($row = $stmt->fetch()) !== false) {
3445+
while (($row = $stmt->fetchAssociative()) !== false) {
34463446
$uris[] = $row['uri'];
34473447
}
34483448
$stmt->closeCursor();
@@ -3568,7 +3568,7 @@ protected function getCalendarObjectId($calendarId, $uri, $calendarType):int {
35683568
->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter($calendarType)));
35693569

35703570
$result = $query->executeQuery();
3571-
$objectIds = $result->fetch();
3571+
$objectIds = $result->fetchAssociative();
35723572
$result->closeCursor();
35733573

35743574
if (!isset($objectIds['id'])) {
@@ -3713,7 +3713,7 @@ protected function purgeCalendarInvitations(int $calendarId): void {
37133713
$cmd->select('uid')
37143714
->from($this->dbObjectsTable)
37153715
->where($cmd->expr()->eq('calendarid', $cmd->createNamedParameter($calendarId)));
3716-
$allIds = $cmd->executeQuery()->fetchAll(\PDO::FETCH_COLUMN);
3716+
$allIds = $cmd->executeQuery()->fetchFirstColumn();
37173717
// delete all links that match object uid's
37183718
$cmd = $this->db->getQueryBuilder();
37193719
$cmd->delete($this->dbObjectInvitationsTable)

apps/dav/lib/CalDAV/Federation/FederatedCalendarMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public function findAll(): \Generator {
148148
->from(self::TABLE_NAME);
149149

150150
$result = $qb->executeQuery();
151-
while ($row = $result->fetch()) {
151+
while ($row = $result->fetchAssociative()) {
152152
yield $this->mapRowToEntity($row);
153153
}
154154
$result->closeCursor();

0 commit comments

Comments
 (0)