diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2024-10-17 11:29:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-17 11:29:46 +0200 |
commit | 40fd76f69e601ab5579e8ce9b81318d3924dd463 (patch) | |
tree | 0209b59a3dff7bd3a50629dfb6c8376e02dc43af /apps/dav/lib | |
parent | 4100f583f03464978e622f5765bbef33e363c97f (diff) | |
parent | c254855222ca2776ccaa9c362b84295391cdd208 (diff) | |
download | nextcloud-server-40fd76f69e601ab5579e8ce9b81318d3924dd463.tar.gz nextcloud-server-40fd76f69e601ab5579e8ce9b81318d3924dd463.zip |
Merge pull request #48724 from nextcloud/dbQueriesExecStmt
chore(db): Apply query prepared statements
Diffstat (limited to 'apps/dav/lib')
-rw-r--r-- | apps/dav/lib/CalDAV/Schedule/IMipService.php | 28 | ||||
-rw-r--r-- | apps/dav/lib/CardDAV/CardDavBackend.php | 28 | ||||
-rw-r--r-- | apps/dav/lib/Migration/BuildCalendarSearchIndex.php | 27 | ||||
-rw-r--r-- | apps/dav/lib/Migration/RegisterBuildReminderIndexBackgroundJob.php | 22 |
4 files changed, 35 insertions, 70 deletions
diff --git a/apps/dav/lib/CalDAV/Schedule/IMipService.php b/apps/dav/lib/CalDAV/Schedule/IMipService.php index a101cb05db3..5b6efba9909 100644 --- a/apps/dav/lib/CalDAV/Schedule/IMipService.php +++ b/apps/dav/lib/CalDAV/Schedule/IMipService.php @@ -27,13 +27,7 @@ use Sabre\VObject\Recur\EventIterator; class IMipService { - private URLGenerator $urlGenerator; - private IConfig $config; - private IDBConnection $db; - private ISecureRandom $random; - private L10NFactory $l10nFactory; private IL10N $l10n; - private ITimeFactory $timeFactory; /** @var string[] */ private const STRING_DIFF = [ @@ -43,20 +37,16 @@ class IMipService { 'meeting_location' => 'LOCATION' ]; - public function __construct(URLGenerator $urlGenerator, - IConfig $config, - IDBConnection $db, - ISecureRandom $random, - L10NFactory $l10nFactory, - ITimeFactory $timeFactory) { - $this->urlGenerator = $urlGenerator; - $this->config = $config; - $this->db = $db; - $this->random = $random; - $this->l10nFactory = $l10nFactory; + public function __construct( + private URLGenerator $urlGenerator, + private IConfig $config, + private IDBConnection $db, + private ISecureRandom $random, + private L10NFactory $l10nFactory, + private ITimeFactory $timeFactory, + ) { $default = $this->l10nFactory->findGenericLanguage(); $this->l10n = $this->l10nFactory->get('dav', $default); - $this->timeFactory = $timeFactory; } /** @@ -912,7 +902,7 @@ class IMipService { 'expiration' => $query->createNamedParameter($lastOccurrence), 'uid' => $query->createNamedParameter($uid) ]) - ->execute(); + ->executeStatement(); return $token; } diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php index b94da9fa7ed..f7d0a888efd 100644 --- a/apps/dav/lib/CardDAV/CardDavBackend.php +++ b/apps/dav/lib/CardDAV/CardDavBackend.php @@ -200,7 +200,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { $addressBooks = []; - $result = $query->execute(); + $result = $query->executeQuery(); while ($row = $result->fetch()) { $addressBooks[$row['id']] = [ 'id' => $row['id'], @@ -395,7 +395,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { 'synctoken' => $query->createParameter('synctoken'), ]) ->setParameters($values) - ->execute(); + ->executeStatement(); $addressBookId = $query->getLastInsertId(); return [ @@ -479,7 +479,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { $cards = []; - $result = $query->execute(); + $result = $query->executeQuery(); while ($row = $result->fetch()) { $row['etag'] = '"' . $row['etag'] . '"'; @@ -516,7 +516,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($cardUri))) ->setMaxResults(1); - $result = $query->execute(); + $result = $query->executeQuery(); $row = $result->fetch(); if (!$row) { return false; @@ -560,7 +560,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { foreach ($chunks as $uris) { $query->setParameter('uri', $uris, IQueryBuilder::PARAM_STR_ARRAY); - $result = $query->execute(); + $result = $query->executeQuery(); while ($row = $result->fetch()) { $row['etag'] = '"' . $row['etag'] . '"'; @@ -634,7 +634,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { 'etag' => $query->createNamedParameter($etag), 'uid' => $query->createNamedParameter($uid), ]) - ->execute(); + ->executeStatement(); $etagCacheKey = "$addressBookId#$cardUri"; $this->etagCache[$etagCacheKey] = $etag; @@ -697,7 +697,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { ->set('uid', $query->createNamedParameter($uid)) ->where($query->expr()->eq('uri', $query->createNamedParameter($cardUri))) ->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId))) - ->execute(); + ->executeStatement(); $this->etagCache[$etagCacheKey] = $etag; @@ -1165,7 +1165,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { */ } - $result = $query2->execute(); + $result = $query2->executeQuery(); $matches = $result->fetchAll(); $result->closeCursor(); $matches = array_map(function ($match) { @@ -1207,7 +1207,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { ->from($this->dbCardsPropertiesTable) ->where($query->expr()->eq('name', $query->createNamedParameter($name))) ->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($bookId))) - ->execute(); + ->executeQuery(); $all = $result->fetchAll(PDO::FETCH_COLUMN); $result->closeCursor(); @@ -1227,7 +1227,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { ->where($query->expr()->eq('id', $query->createParameter('id'))) ->setParameter('id', $id); - $result = $query->execute(); + $result = $query->executeQuery(); $uri = $result->fetch(); $result->closeCursor(); @@ -1251,7 +1251,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { $query->select('*')->from($this->dbCardsTable) ->where($query->expr()->eq('uri', $query->createNamedParameter($uri))) ->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId))); - $queryResult = $query->execute(); + $queryResult = $query->executeQuery(); $contact = $queryResult->fetch(); $queryResult->closeCursor(); @@ -1324,7 +1324,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { $query->setParameter('name', $property->name); $query->setParameter('value', mb_strcut($property->getValue(), 0, 254)); $query->setParameter('preferred', $preferred); - $query->execute(); + $query->executeStatement(); } }, $this->db); } @@ -1350,7 +1350,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { $query->delete($this->dbCardsPropertiesTable) ->where($query->expr()->eq('cardid', $query->createNamedParameter($cardId))) ->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId))); - $query->execute(); + $query->executeStatement(); } /** @@ -1362,7 +1362,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { ->where($query->expr()->eq('uri', $query->createNamedParameter($uri))) ->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId))); - $result = $query->execute(); + $result = $query->executeQuery(); $cardIds = $result->fetch(); $result->closeCursor(); diff --git a/apps/dav/lib/Migration/BuildCalendarSearchIndex.php b/apps/dav/lib/Migration/BuildCalendarSearchIndex.php index 592a6f85bdc..b157934a1ff 100644 --- a/apps/dav/lib/Migration/BuildCalendarSearchIndex.php +++ b/apps/dav/lib/Migration/BuildCalendarSearchIndex.php @@ -13,26 +13,11 @@ use OCP\Migration\IRepairStep; class BuildCalendarSearchIndex implements IRepairStep { - /** @var IDBConnection */ - private $db; - - /** @var IJobList */ - private $jobList; - - /** @var IConfig */ - private $config; - - /** - * @param IDBConnection $db - * @param IJobList $jobList - * @param IConfig $config - */ - public function __construct(IDBConnection $db, - IJobList $jobList, - IConfig $config) { - $this->db = $db; - $this->jobList = $jobList; - $this->config = $config; + public function __construct( + private IDBConnection $db, + private IJobList $jobList, + private IConfig $config, + ) { } /** @@ -55,7 +40,7 @@ class BuildCalendarSearchIndex implements IRepairStep { $query = $this->db->getQueryBuilder(); $query->select($query->createFunction('MAX(' . $query->getColumnName('id') . ')')) ->from('calendarobjects'); - $result = $query->execute(); + $result = $query->executeQuery(); $maxId = (int)$result->fetchOne(); $result->closeCursor(); diff --git a/apps/dav/lib/Migration/RegisterBuildReminderIndexBackgroundJob.php b/apps/dav/lib/Migration/RegisterBuildReminderIndexBackgroundJob.php index f9a12ecbfae..7f74390f883 100644 --- a/apps/dav/lib/Migration/RegisterBuildReminderIndexBackgroundJob.php +++ b/apps/dav/lib/Migration/RegisterBuildReminderIndexBackgroundJob.php @@ -22,15 +22,6 @@ use OCP\Migration\IRepairStep; */ class RegisterBuildReminderIndexBackgroundJob implements IRepairStep { - /** @var IDBConnection */ - private $db; - - /** @var IJobList */ - private $jobList; - - /** @var IConfig */ - private $config; - /** @var string */ private const CONFIG_KEY = 'buildCalendarReminderIndex'; @@ -39,12 +30,11 @@ class RegisterBuildReminderIndexBackgroundJob implements IRepairStep { * @param IJobList $jobList * @param IConfig $config */ - public function __construct(IDBConnection $db, - IJobList $jobList, - IConfig $config) { - $this->db = $db; - $this->jobList = $jobList; - $this->config = $config; + public function __construct( + private IDBConnection $db, + private IJobList $jobList, + private IConfig $config, + ) { } /** @@ -67,7 +57,7 @@ class RegisterBuildReminderIndexBackgroundJob implements IRepairStep { $query = $this->db->getQueryBuilder(); $query->select($query->createFunction('MAX(' . $query->getColumnName('id') . ')')) ->from('calendarobjects'); - $result = $query->execute(); + $result = $query->executeQuery(); $maxId = (int)$result->fetchOne(); $result->closeCursor(); |