Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor OC\DB\QueryBuilder::execute #40157

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions core/Command/Db/ConvertType.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ protected function copyTable(Connection $fromDB, Connection $toDB, Table $table,
$query->automaticTablePrefix(false);
$query->select($query->func()->count('*', 'num_entries'))
->from($table->getName());
$result = $query->execute();
$result = $query->executeQuery();
$count = $result->fetchOne();
$result->closeCursor();

Expand Down Expand Up @@ -337,7 +337,7 @@ protected function copyTable(Connection $fromDB, Connection $toDB, Table $table,
for ($chunk = 0; $chunk < $numChunks; $chunk++) {
$query->setFirstResult($chunk * $chunkSize);

$result = $query->execute();
$result = $query->executeQuery();

try {
$toDB->beginTransaction();
Expand All @@ -359,7 +359,7 @@ protected function copyTable(Connection $fromDB, Connection $toDB, Table $table,
$insertQuery->setParameter($key, $value);
}
}
$insertQuery->execute();
$insertQuery->executeStatement();
}
$result->closeCursor();

Expand Down
4 changes: 2 additions & 2 deletions core/Command/Preview/ResetRenderedTexts.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private function getPreviewsToDelete(): \Iterator {
$qb->select('path', 'mimetype')
->from('filecache')
->where($qb->expr()->eq('fileid', $qb->createNamedParameter($this->previewFolder->getId())));
$cursor = $qb->execute();
$cursor = $qb->executeQuery();
$data = $cursor->fetch();
$cursor->closeCursor();

Expand Down Expand Up @@ -170,7 +170,7 @@ private function getPreviewsToDelete(): \Iterator {
)
);

$cursor = $qb->execute();
$cursor = $qb->executeQuery();

while ($row = $cursor->fetch()) {
yield $row;
Expand Down
2 changes: 1 addition & 1 deletion core/Db/LoginFlowV2Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function cleanup(): void {
$qb->expr()->lt('timestamp', $qb->createNamedParameter($this->timeFactory->getTime() - self::lifetime))
);

$qb->execute();
$qb->executeStatement();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Accounts/AccountManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public function deleteUser(IUser $user): void {
$query = $this->connection->getQueryBuilder();
$query->delete($this->table)
->where($query->expr()->eq('uid', $query->createNamedParameter($uid)))
->execute();
->executeStatement();

$this->deleteUserData($user);
}
Expand All @@ -286,7 +286,7 @@ public function deleteUserData(IUser $user): void {
$query = $this->connection->getQueryBuilder();
$query->delete($this->dataTable)
->where($query->expr()->eq('uid', $query->createNamedParameter($uid)))
->execute();
->executeStatement();
}

/**
Expand Down
8 changes: 4 additions & 4 deletions lib/private/AppConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public function setValue($app, $key, $value) {
}
}

$changedRow = (bool) $sql->execute();
$changedRow = (bool) $sql->executeStatement();

$this->cache[$app][$key] = $value;

Expand All @@ -329,7 +329,7 @@ public function deleteKey($app, $key) {
->andWhere($sql->expr()->eq('configkey', $sql->createParameter('configkey')))
->setParameter('app', $app)
->setParameter('configkey', $key);
$sql->execute();
$sql->executeStatement();

unset($this->cache[$app][$key]);
return false;
Expand All @@ -350,7 +350,7 @@ public function deleteApp($app) {
$sql->delete('appconfig')
->where($sql->expr()->eq('appid', $sql->createParameter('app')))
->setParameter('app', $app);
$sql->execute();
$sql->executeStatement();

unset($this->cache[$app]);
return false;
Expand Down Expand Up @@ -415,7 +415,7 @@ protected function loadConfigValues() {
$sql = $this->conn->getQueryBuilder();
$sql->select('*')
->from('appconfig');
$result = $sql->execute();
$result = $sql->executeQuery();

// we are going to store the result in memory anyway
$rows = $result->fetchAll();
Expand Down
18 changes: 9 additions & 9 deletions lib/private/Authentication/Token/PublicKeyTokenMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function invalidate(string $token) {
$qb->delete($this->tableName)
->where($qb->expr()->eq('token', $qb->createNamedParameter($token)))
->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT)))
->execute();
->executeStatement();
}

/**
Expand All @@ -66,7 +66,7 @@ public function invalidateOld(int $olderThan, int $remember = IToken::DO_NOT_REM
->andWhere($qb->expr()->eq('type', $qb->createNamedParameter(IToken::TEMPORARY_TOKEN, IQueryBuilder::PARAM_INT)))
->andWhere($qb->expr()->eq('remember', $qb->createNamedParameter($remember, IQueryBuilder::PARAM_INT)))
->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT)))
->execute();
->executeStatement();
}

public function invalidateLastUsedBefore(string $uid, int $before): int {
Expand All @@ -90,7 +90,7 @@ public function getToken(string $token): PublicKeyToken {
->from($this->tableName)
->where($qb->expr()->eq('token', $qb->createNamedParameter($token)))
->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT)))
->execute();
->executeQuery();

$data = $result->fetch();
$result->closeCursor();
Expand All @@ -112,7 +112,7 @@ public function getTokenById(int $id): PublicKeyToken {
->from($this->tableName)
->where($qb->expr()->eq('id', $qb->createNamedParameter($id)))
->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT)))
->execute();
->executeQuery();

$data = $result->fetch();
$result->closeCursor();
Expand All @@ -139,7 +139,7 @@ public function getTokenByUser(string $uid): array {
->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid)))
->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT)))
->setMaxResults(1000);
$result = $qb->execute();
$result = $qb->executeQuery();
$data = $result->fetchAll();
$result->closeCursor();

Expand All @@ -157,7 +157,7 @@ public function deleteById(string $uid, int $id) {
->where($qb->expr()->eq('id', $qb->createNamedParameter($id)))
->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($uid)))
->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT)));
$qb->execute();
$qb->executeStatement();
}

/**
Expand All @@ -170,7 +170,7 @@ public function deleteByName(string $name) {
$qb->delete($this->tableName)
->where($qb->expr()->eq('name', $qb->createNamedParameter($name), IQueryBuilder::PARAM_STR))
->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT)));
$qb->execute();
$qb->executeStatement();
}

public function deleteTempToken(PublicKeyToken $except) {
Expand All @@ -182,7 +182,7 @@ public function deleteTempToken(PublicKeyToken $except) {
->andWhere($qb->expr()->neq('id', $qb->createNamedParameter($except->getId())))
->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT)));

$qb->execute();
$qb->executeStatement();
}

public function hasExpiredTokens(string $uid): bool {
Expand All @@ -193,7 +193,7 @@ public function hasExpiredTokens(string $uid): bool {
->andWhere($qb->expr()->eq('password_invalid', $qb->createNamedParameter(true), IQueryBuilder::PARAM_BOOL))
->setMaxResults(1);

$cursor = $qb->execute();
$cursor = $qb->executeQuery();
$data = $cursor->fetchAll();
$cursor->closeCursor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function getState(string $uid): array {
$query = $qb->select('provider_id', 'enabled')
->from(self::TABLE_NAME)
->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid)));
$result = $query->execute();
$result = $query->executeQuery();
$providers = [];
foreach ($result->fetchAll() as $row) {
$providers[(string)$row['provider_id']] = 1 === (int)$row['enabled'];
Expand All @@ -80,14 +80,14 @@ public function persist(string $providerId, string $uid, int $enabled): void {
'enabled' => $qb->createNamedParameter($enabled, IQueryBuilder::PARAM_INT),
]);

$insertQuery->execute();
$insertQuery->executeStatement();
} catch (UniqueConstraintViolationException $ex) {
// There is already an entry -> update it
$updateQuery = $qb->update(self::TABLE_NAME)
->set('enabled', $qb->createNamedParameter($enabled))
->where($qb->expr()->eq('provider_id', $qb->createNamedParameter($providerId)))
->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($uid)));
$updateQuery->execute();
$updateQuery->executeStatement();
}
}

Expand All @@ -103,15 +103,15 @@ public function deleteByUser(string $uid): array {
$selectQuery = $qb1->select('*')
->from(self::TABLE_NAME)
->where($qb1->expr()->eq('uid', $qb1->createNamedParameter($uid)));
$selectResult = $selectQuery->execute();
$selectResult = $selectQuery->executeQuery();
$rows = $selectResult->fetchAll();
$selectResult->closeCursor();

$qb2 = $this->conn->getQueryBuilder();
$deleteQuery = $qb2
->delete(self::TABLE_NAME)
->where($qb2->expr()->eq('uid', $qb2->createNamedParameter($uid)));
$deleteQuery->execute();
$deleteQuery->executeStatement();

return array_map(function (array $row) {
return [
Expand All @@ -128,6 +128,6 @@ public function deleteAll(string $providerId): void {
$deleteQuery = $qb->delete(self::TABLE_NAME)
->where($qb->expr()->eq('provider_id', $qb->createNamedParameter($providerId)));

$deleteQuery->execute();
$deleteQuery->executeStatement();
}
}
4 changes: 2 additions & 2 deletions lib/private/BackgroundJob/JobList.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ public function remove($job, $argument = null): void {
$query->setMaxResults($max);

do {
$deleted = $query->execute();
$deleted = $query->executeStatement();
} while ($deleted === $max);
} else {
// Dont use chunked delete - let the DB handle the large row count natively
$query->execute();
$query->executeStatement();
}
}

Expand Down
8 changes: 4 additions & 4 deletions lib/private/Collaboration/Resources/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function setName(string $name): void {
$query->update(Manager::TABLE_COLLECTIONS)
->set('name', $query->createNamedParameter($name))
->where($query->expr()->eq('id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
$query->execute();
$query->executeStatement();

$this->name = $name;
}
Expand Down Expand Up @@ -142,7 +142,7 @@ public function addResource(IResource $resource): void {
]);

try {
$query->execute();
$query->executeStatement();
} catch (ConstraintViolationException $e) {
throw new ResourceException('Already part of the collection');
}
Expand All @@ -166,7 +166,7 @@ public function removeResource(IResource $resource): void {
->where($query->expr()->eq('collection_id', $query->createNamedParameter($this->id, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->eq('resource_type', $query->createNamedParameter($resource->getType())))
->andWhere($query->expr()->eq('resource_id', $query->createNamedParameter($resource->getId())));
$query->execute();
$query->executeStatement();

if (empty($this->resources)) {
$this->removeCollection();
Expand Down Expand Up @@ -222,7 +222,7 @@ protected function removeCollection(): void {
$query = $this->connection->getQueryBuilder();
$query->delete(Manager::TABLE_COLLECTIONS)
->where($query->expr()->eq('id', $query->createNamedParameter($this->id, IQueryBuilder::PARAM_INT)));
$query->execute();
$query->executeStatement();

$this->manager->invalidateAccessCacheForCollection($this);
$this->id = 0;
Expand Down
Loading