Don't leave cursors open when tests fail

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2020-11-05 10:50:53 +01:00 committed by backportbot[bot]
parent 6a5b921284
commit 19816fe85f
36 changed files with 376 additions and 91 deletions

View File

@ -248,7 +248,10 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$query->andWhere($query->expr()->neq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI)));
}
return (int)$query->execute()->fetchColumn();
$result = $query->execute();
$column = (int)$result->fetchColumn();
$result->closeCursor();
return $column;
}
/**
@ -2346,7 +2349,9 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$query->select('synctoken')
->from($table)
->where($query->expr()->eq('id', $query->createNamedParameter($calendarId)));
$syncToken = (int)$query->execute()->fetchColumn();
$result = $query->execute();
$syncToken = (int)$result->fetchColumn();
$result->closeCursor();
$query = $this->db->getQueryBuilder();
$query->insert('calendarchanges')

View File

@ -138,7 +138,10 @@ class CardDavBackend implements BackendInterface, SyncSupport {
->from('addressbooks')
->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri)));
return (int)$query->execute()->fetchColumn();
$result = $query->execute();
$column = (int) $result->fetchColumn();
$result->closeCursor();
return $column;
}
/**

View File

@ -75,7 +75,9 @@ class BuildCalendarSearchIndex implements IRepairStep {
$query = $this->db->getQueryBuilder();
$query->select($query->createFunction('MAX(' . $query->getColumnName('id') . ')'))
->from('calendarobjects');
$maxId = (int)$query->execute()->fetchColumn();
$result = $query->execute();
$maxId = (int) $result->fetchColumn();
$result->closeCursor();
$output->info('Add background job');
$this->jobList->add(BuildCalendarSearchIndexBackgroundJob::class, [

View File

@ -86,7 +86,9 @@ class RegisterBuildReminderIndexBackgroundJob implements IRepairStep {
$query = $this->db->getQueryBuilder();
$query->select($query->createFunction('MAX(' . $query->getColumnName('id') . ')'))
->from('calendarobjects');
$maxId = (int)$query->execute()->fetchColumn();
$result = $query->execute();
$maxId = (int) $result->fetchColumn();
$result->closeCursor();
$output->info('Add background job');
$this->jobList->add(BuildReminderIndexBackgroundJob::class, [

View File

@ -549,7 +549,12 @@ class CardDavBackendTest extends TestCase {
$this->invokePrivate($backend, 'updateProperties', [$bookId, $cardUri, $vCard->serialize()]);
$query = $this->db->getQueryBuilder();
$result = $query->select('*')->from('cards_properties')->execute()->fetchAll();
$query->select('*')
->from('cards_properties');
$qResult = $query->execute();
$result = $qResult->fetchAll();
$qResult->closeCursor();
$this->assertSame(2, count($result));
@ -569,7 +574,12 @@ class CardDavBackendTest extends TestCase {
$this->invokePrivate($backend, 'updateProperties', [$bookId, $cardUri, $vCard->serialize()]);
$query = $this->db->getQueryBuilder();
$result = $query->select('*')->from('cards_properties')->execute()->fetchAll();
$query->select('*')
->from('cards_properties');
$qResult = $query->execute();
$result = $qResult->fetchAll();
$qResult->closeCursor();
$this->assertSame(1, count($result));
@ -609,7 +619,13 @@ class CardDavBackendTest extends TestCase {
$this->invokePrivate($this->backend, 'purgeProperties', [1, 1]);
$query = $this->db->getQueryBuilder();
$result = $query->select('*')->from('cards_properties')->execute()->fetchAll();
$query->select('*')
->from('cards_properties');
$qResult = $query->execute();
$result = $qResult->fetchAll();
$qResult->closeCursor();
$this->assertSame(1, count($result));
$this->assertSame(1 ,(int)$result[0]['addressbookid']);
$this->assertSame(2 ,(int)$result[0]['cardid']);

View File

@ -109,7 +109,12 @@ class CustomPropertiesBackendTest extends TestCase {
->from('properties')
->where($query->expr()->eq('userid', $query->createNamedParameter($user)))
->where($query->expr()->eq('propertypath', $query->createNamedParameter($this->formatPath($path))));
return $query->execute()->fetchAll(\PDO::FETCH_KEY_PAIR);
$result = $query->execute();
$data = $result->fetchAll(\PDO::FETCH_KEY_PAIR);
$result->closeCursor();
return $data;
}
public function testPropFindNoDbCalls() {

View File

@ -347,7 +347,9 @@ class FederatedShareProvider implements IShareProvider {
$query->select('*')->from($this->externalShareTable)
->where($query->expr()->eq('user', $query->createNamedParameter($share->getShareOwner())))
->andWhere($query->expr()->eq('mountpoint', $query->createNamedParameter($share->getTarget())));
$result = $query->execute()->fetchAll();
$qResult = $query->execute();
$result = $qResult->fetchAll();
$qResult->closeCursor();
if (isset($result[0]) && (int)$result[0]['remote_id'] > 0) {
return $result[0];
@ -483,7 +485,9 @@ class FederatedShareProvider implements IShareProvider {
$query = $this->dbConnection->getQueryBuilder();
$query->select('remote_id')->from('federated_reshares')
->where($query->expr()->eq('share_id', $query->createNamedParameter((int)$share->getId())));
$data = $query->execute()->fetch();
$result = $query->execute();
$data = $result->fetch();
$result->closeCursor();
if (!is_array($data) || !isset($data['remote_id'])) {
throw new ShareNotFound();

View File

@ -120,8 +120,10 @@ class DbHandler {
$query->select('*')->from($this->dbTable)
->where($query->expr()->eq('id', $query->createParameter('id')))
->setParameter('id', $id);
$query->execute();
$result = $query->execute()->fetchAll();
$qResult = $query->execute();
$result = $qResult->fetchAll();
$qResult->closeCursor();
if (empty($result)) {
throw new \Exception('No Server found with ID: ' . $id);

View File

@ -62,7 +62,10 @@ class DbHandlerTest extends TestCase {
);
$query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable);
$result = $query->execute()->fetchAll();
$qResult = $query->execute();
$result = $qResult->fetchAll();
$qResult->closeCursor();
$this->assertEmpty($result, 'we need to start with a empty trusted_servers table');
}
@ -83,7 +86,10 @@ class DbHandlerTest extends TestCase {
$id = $this->dbHandler->addServer($url);
$query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable);
$result = $query->execute()->fetchAll();
$qResult = $query->execute();
$result = $qResult->fetchAll();
$qResult->closeCursor();
$this->assertSame(1, count($result));
$this->assertSame($expectedUrl, $result[0]['url']);
$this->assertSame($id, (int)$result[0]['id']);
@ -104,7 +110,10 @@ class DbHandlerTest extends TestCase {
$id2 = $this->dbHandler->addServer('server2');
$query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable);
$result = $query->execute()->fetchAll();
$qResult = $query->execute();
$result = $qResult->fetchAll();
$qResult->closeCursor();
$this->assertSame(2, count($result));
$this->assertSame('server1', $result[0]['url']);
$this->assertSame('server2', $result[1]['url']);
@ -113,7 +122,10 @@ class DbHandlerTest extends TestCase {
$this->dbHandler->removeServer($id2);
$query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable);
$result = $query->execute()->fetchAll();
$qResult = $query->execute();
$result = $qResult->fetchAll();
$qResult->closeCursor();
$this->assertSame(1, count($result));
$this->assertSame('server1', $result[0]['url']);
$this->assertSame($id1, (int)$result[0]['id']);
@ -165,12 +177,18 @@ class DbHandlerTest extends TestCase {
public function XtestAddToken() {
$this->dbHandler->addServer('server1');
$query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable);
$result = $query->execute()->fetchAll();
$qResult = $query->execute();
$result = $qResult->fetchAll();
$qResult->closeCursor();
$this->assertSame(1, count($result));
$this->assertSame(null, $result[0]['token']);
$this->dbHandler->addToken('http://server1', 'token');
$query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable);
$result = $query->execute()->fetchAll();
$qResult = $query->execute();
$result = $qResult->fetchAll();
$qResult->closeCursor();
$this->assertSame(1, count($result));
$this->assertSame('token', $result[0]['token']);
}
@ -186,12 +204,18 @@ class DbHandlerTest extends TestCase {
public function XtestAddSharedSecret() {
$this->dbHandler->addServer('server1');
$query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable);
$result = $query->execute()->fetchAll();
$qResult = $query->execute();
$result = $qResult->fetchAll();
$qResult->closeCursor();
$this->assertSame(1, count($result));
$this->assertSame(null, $result[0]['shared_secret']);
$this->dbHandler->addSharedSecret('http://server1', 'secret');
$query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable);
$result = $query->execute()->fetchAll();
$qResult = $query->execute();
$result = $qResult->fetchAll();
$qResult->closeCursor();
$this->assertSame(1, count($result));
$this->assertSame('secret', $result[0]['shared_secret']);
}
@ -207,12 +231,18 @@ class DbHandlerTest extends TestCase {
public function testSetServerStatus() {
$this->dbHandler->addServer('server1');
$query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable);
$result = $query->execute()->fetchAll();
$qResult = $query->execute();
$result = $qResult->fetchAll();
$qResult->closeCursor();
$this->assertSame(1, count($result));
$this->assertSame(TrustedServers::STATUS_PENDING, (int)$result[0]['status']);
$this->dbHandler->setServerStatus('http://server1', TrustedServers::STATUS_OK);
$query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable);
$result = $query->execute()->fetchAll();
$qResult = $query->execute();
$result = $qResult->fetchAll();
$qResult->closeCursor();
$this->assertSame(1, count($result));
$this->assertSame(TrustedServers::STATUS_OK, (int)$result[0]['status']);
}

View File

@ -452,7 +452,10 @@ class DBConfigService {
$query = $builder->select($fields)
->from($table)
->where($builder->expr()->in('mount_id', $placeHolders));
$rows = $query->execute()->fetchAll();
$result = $query->execute();
$rows = $result->fetchAll();
$result->closeCursor();
$result = [];
foreach ($mountIds as $mountId) {

View File

@ -334,7 +334,10 @@ abstract class StoragesServiceTest extends \Test\TestCase {
$storageCheckQuery = $qb->select('*')
->from('storages')
->where($qb->expr()->eq('numeric_id', $qb->expr()->literal($numericId)));
$storages = $storageCheckQuery->execute()->fetchAll();
$result = $storageCheckQuery->execute();
$storages = $result->fetchAll();
$result->closeCursor();
$this->assertCount($expectedCountAfterDeletion, $storages, "expected $expectedCountAfterDeletion storages, got " . json_encode($storages));
}

View File

@ -142,7 +142,10 @@ class CleanupRemoteStoragesTest extends TestCase {
$qb->select('*')
->from('storages')
->where($qb->expr()->eq('numeric_id', $qb->createNamedParameter($numericId)));
$result = $qb->execute()->fetchAll();
$qResult = $qb->execute();
$result = $qResult->fetchAll();
$qResult->closeCursor();
if (!empty($result)) {
return true;
}
@ -151,7 +154,10 @@ class CleanupRemoteStoragesTest extends TestCase {
$qb->select('*')
->from('filecache')
->where($qb->expr()->eq('storage', $qb->createNamedParameter($numericId)));
$result = $qb->execute()->fetchAll();
$qResult = $qb->execute();
$result = $qResult->fetchAll();
$qResult->closeCursor();
if (!empty($result)) {
return true;
}

View File

@ -107,7 +107,9 @@ class SetPasswordColumnTest extends TestCase {
$query = $this->connection->getQueryBuilder();
$query->select('*')
->from('share');
$allShares = $query->execute()->fetchAll();
$result = $query->execute();
$allShares = $result->fetchAll();
$result->closeCursor();
foreach ($allShares as $share) {
if ((int)$share['share_type'] === IShare::TYPE_LINK) {

View File

@ -994,10 +994,14 @@ class Trashbin {
->andWhere($query->expr()->eq('parent', $query->createNamedParameter($parentId)))
->andWhere($query->expr()->iLike('name', $query->createNamedParameter($pattern)));
$result = $query->execute();
$entries = $result->fetchAll();
$result->closeCursor();
/** @var CacheEntry[] $matches */
$matches = array_map(function (array $data) {
return Cache::cacheEntryFromData($data, \OC::$server->getMimeTypeLoader());
}, $query->execute()->fetchAll());
}, $entries);
foreach ($matches as $ma) {
if ($timestamp) {

View File

@ -124,9 +124,13 @@ class CleanUpTest extends TestCase {
// if the delete operation was execute only files from user1
// should be left.
$query = $this->dbConnection->getQueryBuilder();
$result = $query->select('user')
->from($this->trashTable)
->execute()->fetchAll();
$query->select('user')
->from($this->trashTable);
$qResult = $query->execute();
$result = $qResult->fetchAll();
$qResult->closeCursor();
$this->assertSame(5, count($result));
foreach ($result as $r) {
$this->assertSame('user1', $r['user']);

View File

@ -545,10 +545,13 @@ class ShareByMailProviderTest extends TestCase {
);
$qb = $this->connection->getQueryBuilder();
$result = $qb->select('*')
$qb->select('*')
->from('share')
->where($qb->expr()->eq('id', $qb->createNamedParameter($id)))
->execute()->fetchAll();
->where($qb->expr()->eq('id', $qb->createNamedParameter($id)));
$qResult = $qb->execute();
$result = $qResult->fetchAll();
$qResult->closeCursor();
$this->assertSame(1, count($result));
@ -590,10 +593,13 @@ class ShareByMailProviderTest extends TestCase {
);
$qb = $this->connection->getQueryBuilder();
$result = $qb->select('*')
$qb->select('*')
->from('share')
->where($qb->expr()->eq('id', $qb->createNamedParameter($id)))
->execute()->fetchAll();
->where($qb->expr()->eq('id', $qb->createNamedParameter($id)));
$qResult = $qb->execute();
$result = $qResult->fetchAll();
$qResult->closeCursor();
$this->assertSame(1, count($result));
@ -831,7 +837,10 @@ class ShareByMailProviderTest extends TestCase {
$query = $this->connection->getQueryBuilder();
$query->select('*')->from('share')
->where($query->expr()->eq('id', $query->createNamedParameter($id)));
$before = $query->execute()->fetchAll();
$result = $query->execute();
$before = $result->fetchAll();
$result->closeCursor();
$this->assertTrue(is_array($before));
$this->assertSame(1, count($before));
@ -841,7 +850,10 @@ class ShareByMailProviderTest extends TestCase {
$query = $this->connection->getQueryBuilder();
$query->select('*')->from('share')
->where($query->expr()->eq('id', $query->createNamedParameter($id)));
$after = $query->execute()->fetchAll();
$result = $query->execute();
$after = $result->fetchAll();
$result->closeCursor();
$this->assertTrue(is_array($after));
$this->assertEmpty($after);
@ -861,7 +873,10 @@ class ShareByMailProviderTest extends TestCase {
$query = $this->connection->getQueryBuilder();
$query->select('*')->from('share');
$before = $query->execute()->fetchAll();
$result = $query->execute();
$before = $result->fetchAll();
$result->closeCursor();
$this->assertTrue(is_array($before));
$this->assertSame(2, count($before));
@ -873,7 +888,10 @@ class ShareByMailProviderTest extends TestCase {
$query = $this->connection->getQueryBuilder();
$query->select('*')->from('share');
$after = $query->execute()->fetchAll();
$result = $query->execute();
$after = $result->fetchAll();
$result->closeCursor();
$this->assertTrue(is_array($after));
$this->assertSame(1, count($after));

View File

@ -151,7 +151,9 @@ class Cache implements ICache {
$query->whereFileId($file);
}
$data = $query->execute()->fetch();
$result = $query->execute();
$data = $result->fetch();
$result->closeCursor();
//merge partial data
if (!$data and is_string($file) and isset($this->partial[$file])) {
@ -220,7 +222,10 @@ class Cache implements ICache {
->whereParent($fileId)
->orderBy('name', 'ASC');
$files = $query->execute()->fetchAll();
$result = $query->execute();
$files = $result->fetchAll();
$result->closeCursor();
return array_map(function (array $data) {
return self::cacheEntryFromData($data, $this->mimetypeLoader);
}, $files);
@ -467,7 +472,10 @@ class Cache implements ICache {
->whereStorageId()
->wherePath($file);
$id = $query->execute()->fetchColumn();
$result = $query->execute();
$id = $result->fetchColumn();
$result->closeCursor();
return $id === false ? -1 : (int)$id;
}
@ -710,7 +718,11 @@ class Cache implements ICache {
->from('filecache')
->whereStorageId()
->wherePath($file);
$size = $query->execute()->fetchColumn();
$result = $query->execute();
$size = $result->fetchColumn();
$result->closeCursor();
if ($size !== false) {
if ((int)$size === -1) {
return self::SHALLOW;
@ -745,9 +757,13 @@ class Cache implements ICache {
->whereStorageId()
->andWhere($query->expr()->iLike('name', $query->createNamedParameter($pattern)));
$result = $query->execute();
$files = $result->fetchAll();
$result->closeCursor();
return array_map(function (array $data) {
return self::cacheEntryFromData($data, $this->mimetypeLoader);
}, $query->execute()->fetchAll());
}, $files);
}
/**
@ -782,9 +798,13 @@ class Cache implements ICache {
$query->andWhere($query->expr()->eq('mimepart', $query->createNamedParameter($mimeId, IQueryBuilder::PARAM_INT)));
}
$result = $query->execute();
$files = $result->fetchAll();
$result->closeCursor();
return array_map(function (array $data) {
return self::cacheEntryFromData($data, $this->mimetypeLoader);
}, $query->execute()->fetchAll());
}, $files);
}
public function searchQuery(ISearchQuery $searchQuery) {
@ -865,7 +885,11 @@ class Cache implements ICache {
->whereParent($fileId)
->andWhere($query->expr()->lt('size', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT)));
return (int)$query->execute()->fetchColumn();
$result = $query->execute();
$size = (int)$result->fetchColumn();
$result->closeCursor();
return $size;
}
return -1;
}
@ -892,7 +916,11 @@ class Cache implements ICache {
->whereStorageId()
->whereParent($id);
if ($row = $query->execute()->fetch()) {
$result = $query->execute();
$row = $result->fetch();
$result->closeCursor();
if ($row) {
[$sum, $min] = array_values($row);
$sum = 0 + $sum;
$min = 0 + $min;
@ -920,9 +948,13 @@ class Cache implements ICache {
->from('filecache')
->whereStorageId();
$result = $query->execute();
$files = $result->fetchAll(\PDO::FETCH_COLUMN);
$result->closeCursor();
return array_map(function ($id) {
return (int)$id;
}, $query->execute()->fetchAll(\PDO::FETCH_COLUMN));
}, $files);
}
/**
@ -942,7 +974,11 @@ class Cache implements ICache {
->andWhere($query->expr()->lt('size', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT)))
->orderBy('fileid', 'DESC');
return $query->execute()->fetchColumn();
$result = $query->execute();
$path = $result->fetchColumn();
$result->closeCursor();
return $path;
}
/**
@ -958,7 +994,10 @@ class Cache implements ICache {
->whereStorageId()
->whereFileId($id);
$path = $query->execute()->fetchColumn();
$result = $query->execute();
$path = $result->fetchColumn();
$result->closeCursor();
return $path === false ? null : $path;
}
@ -976,7 +1015,12 @@ class Cache implements ICache {
$query->select('path', 'storage')
->from('filecache')
->where($query->expr()->eq('fileid', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
if ($row = $query->execute()->fetch()) {
$result = $query->execute();
$row = $result->fetch();
$result->closeCursor();
if ($row) {
$numericId = $row['storage'];
$path = $row['path'];
} else {

View File

@ -72,6 +72,7 @@ class HomeCache extends Cache {
$this->update($id, ['size' => $totalSize]);
}
}
$result->closeCursor();
}
return $totalSize;
}

View File

@ -61,6 +61,7 @@ class StorageGlobal {
while ($row = $result->fetch()) {
$this->cache[$row['id']] = $row;
}
$result->closeCursor();
}
/**
@ -74,7 +75,10 @@ class StorageGlobal {
->from('storages')
->where($builder->expr()->eq('id', $builder->createNamedParameter($storageId)));
$row = $query->execute()->fetch();
$result = $query->execute();
$row = $result->fetch();
$result->closeCursor();
if ($row) {
$this->cache[$storageId] = $row;
}

View File

@ -235,7 +235,9 @@ class UserMountCache implements IUserMountCache {
->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid'))
->where($builder->expr()->eq('user_id', $builder->createPositionalParameter($user->getUID())));
$rows = $query->execute()->fetchAll();
$result = $query->execute();
$rows = $result->fetchAll();
$result->closeCursor();
$this->mountsForUsers[$user->getUID()] = array_filter(array_map([$this, 'dbRowToMountInfo'], $rows));
}
@ -258,7 +260,9 @@ class UserMountCache implements IUserMountCache {
$query->andWhere($builder->expr()->eq('user_id', $builder->createPositionalParameter($user)));
}
$rows = $query->execute()->fetchAll();
$result = $query->execute();
$rows = $result->fetchAll();
$result->closeCursor();
return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows));
}
@ -274,7 +278,9 @@ class UserMountCache implements IUserMountCache {
->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid'))
->where($builder->expr()->eq('root_id', $builder->createPositionalParameter($rootFileId, IQueryBuilder::PARAM_INT)));
$rows = $query->execute()->fetchAll();
$result = $query->execute();
$rows = $result->fetchAll();
$result->closeCursor();
return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows));
}
@ -291,7 +297,10 @@ class UserMountCache implements IUserMountCache {
->from('filecache')
->where($builder->expr()->eq('fileid', $builder->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)));
$row = $query->execute()->fetch();
$result = $query->execute();
$row = $result->fetch();
$result->closeCursor();
if (is_array($row)) {
$this->cacheInfoCache[$fileId] = [
(int)$row['storage'],

View File

@ -528,7 +528,11 @@ class Folder extends Node implements \OCP\Files\Folder {
->setMaxResults($limit)
->setFirstResult($offset);
return $query->execute()->fetchAll();
$result = $query->execute();
$rows = $result->fetchAll();
$result->closeCursor();
return $rows;
}
private function recentParse($result, $mountMap, $mimetypeLoader) {

View File

@ -123,7 +123,10 @@ class Loader implements IMimeTypeLoader {
->where(
$fetch->expr()->eq('mimetype', $fetch->createNamedParameter($mimetype)
));
$row = $fetch->execute()->fetch();
$result = $fetch->execute();
$row = $result->fetch();
$result->closeCursor();
if (!$row) {
throw new \Exception("Failed to get mimetype id for $mimetype after trying to store it");
@ -141,7 +144,10 @@ class Loader implements IMimeTypeLoader {
$qb = $this->dbConnection->getQueryBuilder();
$qb->select('id', 'mimetype')
->from('mimetypes');
$results = $qb->execute()->fetchAll();
$result = $qb->execute();
$results = $result->fetchAll();
$result->closeCursor();
foreach ($results as $row) {
$this->mimetypes[$row['id']] = $row['mimetype'];

View File

@ -84,7 +84,10 @@ class CredentialsManager implements ICredentialsManager {
->where($qb->expr()->eq('user', $qb->createNamedParameter((string)$userId)))
->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier)))
;
$result = $qb->execute()->fetch();
$qResult = $qb->execute();
$result = $qResult->fetch();
$qResult->closeCursor();
if (!$result) {
return null;

View File

@ -194,6 +194,7 @@ class Share extends Constants {
}
$shares[] = $row;
}
$result->closeCursor();
//if didn't found a result than let's look for a group share.
if (empty($shares) && $user !== null) {
@ -692,9 +693,9 @@ class Share extends Constants {
->from('share')
->where($query->expr()->eq('id', $query->createNamedParameter($row['parent'])));
$result = $query->execute();
$parentRow = $result->fetch();
$result->closeCursor();
$parentResult = $query->execute();
$parentRow = $parentResult->fetch();
$parentResult->closeCursor();
if ($parentRow === false) {
\OCP\Util::writeLog('OCP\Share', 'Can\'t select parent: ' .

View File

@ -102,6 +102,10 @@ class TagManager implements ITagManager {
->andWhere($query->expr()->eq('c.type', $query->createNamedParameter($objectType)))
->andWhere($query->expr()->eq('c.category', $query->createNamedParameter(ITags::TAG_FAVORITE)));
return $query->execute()->fetchAll(\PDO::FETCH_COLUMN);
$result = $query->execute();
$users = $result->fetchAll(\PDO::FETCH_COLUMN);
$result->closeCursor();
return $users;
}
}

View File

@ -285,6 +285,7 @@ class Tags implements ITags {
$stmt = \OC_DB::prepare($sql);
$result = $stmt->execute([$tagId]);
if ($result === null) {
$stmt->closeCursor();
\OCP\Util::writeLog('core', __METHOD__. 'DB error: ' . \OC::$server->getDatabaseConnection()->getError(), ILogger::ERROR);
return false;
}
@ -301,6 +302,7 @@ class Tags implements ITags {
while ($row = $result->fetchRow()) {
$ids[] = (int)$row['objid'];
}
$result->closeCursor();
}
return $ids;
@ -538,6 +540,7 @@ class Tags implements ITags {
]);
}
}
$result->closeCursor();
} catch (\Exception $e) {
\OC::$server->getLogger()->logException($e, [
'message' => __METHOD__,

View File

@ -104,6 +104,15 @@ class OC_DB_StatementWrapper {
return $this->statement->fetchColumn($column);
}
/**
* Closes the cursor, enabling the statement to be executed again.
*
* @deprecated Use Result::free() instead.
*/
public function closeCursor(): void {
$this->statement->closeCursor();
}
/**
* Binds a PHP variable to a corresponding named or question mark placeholder in the
* SQL statement that was use to prepare the statement.

View File

@ -983,6 +983,7 @@ class OC_Util {
try {
$result = \OC_DB::executeAudited('SHOW SERVER_VERSION');
$data = $result->fetchRow();
$result->closeCursor();
if (isset($data['server_version'])) {
$version = $data['server_version'];
if (version_compare($version, '9.0.0', '<')) {

View File

@ -248,7 +248,10 @@ class AccountsManagerTest extends TestCase {
->where($query->expr()->eq('uid', $query->createParameter('uid')))
->setParameter('uid', $uid);
$query->execute();
$result = $query->execute()->fetchAll();
$qResult = $query->execute();
$result = $qResult->fetchAll();
$qResult->closeCursor();
if (!empty($result)) {
return json_decode($result[0]['data'], true);

View File

@ -89,6 +89,8 @@ class LegacyDBTest extends \Test\TestCase {
$this->assertTrue((bool)$result);
$row = $result->fetchRow();
$this->assertFalse($row);
$result->closeCursor();
$query = OC_DB::prepare('INSERT INTO `*PREFIX*'.$this->table2.'` (`fullname`,`uri`) VALUES (?,?)');
$result = $query->execute(['fullname test', 'uri_1']);
$this->assertEquals(1, $result);
@ -100,6 +102,7 @@ class LegacyDBTest extends \Test\TestCase {
$this->assertEquals($row['fullname'], 'fullname test');
$row = $result->fetchRow();
$this->assertFalse((bool)$row); //PDO returns false, MDB2 returns null
$result->closeCursor();
}
/**
@ -112,6 +115,7 @@ class LegacyDBTest extends \Test\TestCase {
$query = OC_DB::prepare('SELECT `fullname`,`uri` FROM `*PREFIX*'.$this->table2.'` WHERE `uri` = ?');
$result = $query->execute(['uri_2']);
$this->assertTrue((bool)$result);
$result->closeCursor();
}
public function testUNIX_TIMESTAMP() {
@ -121,6 +125,7 @@ class LegacyDBTest extends \Test\TestCase {
$query = OC_DB::prepare('SELECT `fullname`,`uri` FROM `*PREFIX*'.$this->table2.'` WHERE `uri` = ?');
$result = $query->execute(['uri_3']);
$this->assertTrue((bool)$result);
$result->closeCursor();
}
public function testLastInsertId() {
@ -143,7 +148,12 @@ class LegacyDBTest extends \Test\TestCase {
$result = $query->execute([$expected, 'uri_1', 'This is a vCard']);
$this->assertEquals(1, $result);
$actual = OC_DB::prepare("SELECT `fullname` FROM `$table`")->execute()->fetchOne();
$query = OC_DB::prepare("SELECT `fullname` FROM `$table`");
$result = $query->execute();
$actual = $result->fetchOne();
$result->closeCursor();
$this->assertSame($expected, $actual);
}
@ -162,6 +172,7 @@ class LegacyDBTest extends \Test\TestCase {
$result = $query->execute();
$this->assertTrue((bool)$result);
$row = $result->fetchRow();
$result->closeCursor();
$this->assertArrayHasKey($rowname, $row);
$this->assertEquals($expect, $row[$rowname]);
$query = OC_DB::prepare('DELETE FROM `' . $table . '`');
@ -227,14 +238,17 @@ class LegacyDBTest extends \Test\TestCase {
$query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` LIKE ?");
$result = $query->execute(['foobar']);
$this->assertCount(0, $result->fetchAll());
$result->closeCursor();
$query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` ILIKE ?");
$result = $query->execute(['foobar']);
$this->assertCount(1, $result->fetchAll());
$result->closeCursor();
$query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` ILIKE ?");
$result = $query->execute(['foo']);
$this->assertCount(0, $result->fetchAll());
$result->closeCursor();
}
public function testILIKEWildcard() {
@ -246,26 +260,32 @@ class LegacyDBTest extends \Test\TestCase {
$query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` LIKE ?");
$result = $query->execute(['%bar']);
$this->assertCount(0, $result->fetchAll());
$result->closeCursor();
$query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` LIKE ?");
$result = $query->execute(['foo%']);
$this->assertCount(0, $result->fetchAll());
$result->closeCursor();
$query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` LIKE ?");
$result = $query->execute(['%ba%']);
$this->assertCount(0, $result->fetchAll());
$result->closeCursor();
$query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` ILIKE ?");
$result = $query->execute(['%bar']);
$this->assertCount(1, $result->fetchAll());
$result->closeCursor();
$query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` ILIKE ?");
$result = $query->execute(['foo%']);
$this->assertCount(1, $result->fetchAll());
$result->closeCursor();
$query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` ILIKE ?");
$result = $query->execute(['%ba%']);
$this->assertCount(1, $result->fetchAll());
$result->closeCursor();
}
/**
@ -282,7 +302,11 @@ class LegacyDBTest extends \Test\TestCase {
$result = $query->execute([$expected]);
$this->assertEquals(1, $result);
$actual = OC_DB::prepare("SELECT `textfield` FROM `$table`")->execute()->fetchOne();
$query = OC_DB::prepare("SELECT `textfield` FROM `$table`");
$result = $query->execute();
$actual = $result->fetchOne();
$result->closeCursor();
$this->assertSame($expected, $actual);
}

View File

@ -67,7 +67,10 @@ class ExpressionBuilderDBTest extends TestCase {
->from('users')
->where($query->expr()->like($query->createNamedParameter($param1), $query->createNamedParameter($param2)));
$this->assertEquals($match, $query->execute()->fetchColumn());
$result = $query->execute();
$column = $result->fetchColumn();
$result->closeCursor();
$this->assertEquals($match, $column);
}
public function ilikeProvider() {
@ -101,6 +104,9 @@ class ExpressionBuilderDBTest extends TestCase {
->from('users')
->where($query->expr()->iLike($query->createNamedParameter($param1), $query->createNamedParameter($param2)));
$this->assertEquals($match, $query->execute()->fetchColumn());
$result = $query->execute();
$column = $result->fetchColumn();
$result->closeCursor();
$this->assertEquals($match, $column);
}
}

View File

@ -48,7 +48,10 @@ class FunctionBuilderTest extends TestCase {
$query->from('appconfig')
->setMaxResults(1);
$this->assertEquals('foobar', $query->execute()->fetchColumn());
$result = $query->execute();
$column = $result->fetchColumn();
$result->closeCursor();
$this->assertEquals('foobar', $column);
}
public function testMd5() {
@ -58,7 +61,10 @@ class FunctionBuilderTest extends TestCase {
$query->from('appconfig')
->setMaxResults(1);
$this->assertEquals(md5('foobar'), $query->execute()->fetchColumn());
$result = $query->execute();
$column = $result->fetchColumn();
$result->closeCursor();
$this->assertEquals(md5('foobar'), $column);
}
public function testSubstring() {
@ -68,7 +74,10 @@ class FunctionBuilderTest extends TestCase {
$query->from('appconfig')
->setMaxResults(1);
$this->assertEquals('oo', $query->execute()->fetchColumn());
$result = $query->execute();
$column = $result->fetchColumn();
$result->closeCursor();
$this->assertEquals('oo', $column);
}
public function testSubstringNoLength() {
@ -78,7 +87,10 @@ class FunctionBuilderTest extends TestCase {
$query->from('appconfig')
->setMaxResults(1);
$this->assertEquals('oobar', $query->execute()->fetchColumn());
$result = $query->execute();
$column = $result->fetchColumn();
$result->closeCursor();
$this->assertEquals('oobar', $column);
}
public function testLower() {
@ -88,7 +100,10 @@ class FunctionBuilderTest extends TestCase {
$query->from('appconfig')
->setMaxResults(1);
$this->assertEquals('foobar', $query->execute()->fetchColumn());
$result = $query->execute();
$column = $result->fetchColumn();
$result->closeCursor();
$this->assertEquals('foobar', $column);
}
public function testAdd() {
@ -98,7 +113,10 @@ class FunctionBuilderTest extends TestCase {
$query->from('appconfig')
->setMaxResults(1);
$this->assertEquals(3, $query->execute()->fetchColumn());
$result = $query->execute();
$column = $result->fetchColumn();
$result->closeCursor();
$this->assertEquals(3, $column);
}
public function testSubtract() {
@ -108,7 +126,10 @@ class FunctionBuilderTest extends TestCase {
$query->from('appconfig')
->setMaxResults(1);
$this->assertEquals(1, $query->execute()->fetchColumn());
$result = $query->execute();
$column = $result->fetchColumn();
$result->closeCursor();
$this->assertEquals(1, $column);
}
public function testCount() {
@ -118,7 +139,10 @@ class FunctionBuilderTest extends TestCase {
$query->from('appconfig')
->setMaxResults(1);
$this->assertGreaterThan(1, $query->execute()->fetchColumn());
$result = $query->execute();
$column = $result->fetchColumn();
$result->closeCursor();
$this->assertGreaterThan(1, $column);
}
private function setUpMinMax($value) {
@ -151,7 +175,10 @@ class FunctionBuilderTest extends TestCase {
->where($query->expr()->eq('appid', $query->createNamedParameter('minmax')))
->setMaxResults(1);
$this->assertEquals(null, $query->execute()->fetchColumn());
$result = $query->execute();
$row = $result->fetchColumn();
$result->closeCursor();
$this->assertEquals(null, $row);
}
public function testMinEmpty() {
@ -164,7 +191,10 @@ class FunctionBuilderTest extends TestCase {
->where($query->expr()->eq('appid', $query->createNamedParameter('minmax')))
->setMaxResults(1);
$this->assertEquals(null, $query->execute()->fetchColumn());
$result = $query->execute();
$row = $result->fetchColumn();
$result->closeCursor();
$this->assertEquals(null, $row);
}
public function testMax() {
@ -180,7 +210,10 @@ class FunctionBuilderTest extends TestCase {
->where($query->expr()->eq('appid', $query->createNamedParameter('minmax')))
->setMaxResults(1);
$this->assertEquals(20, $query->execute()->fetchColumn());
$result = $query->execute();
$row = $result->fetchColumn();
$result->closeCursor();
$this->assertEquals(20, $row);
}
public function testMin() {
@ -196,7 +229,10 @@ class FunctionBuilderTest extends TestCase {
->where($query->expr()->eq('appid', $query->createNamedParameter('minmax')))
->setMaxResults(1);
$this->assertEquals(10, $query->execute()->fetchColumn());
$result = $query->execute();
$row = $result->fetchColumn();
$result->closeCursor();
$this->assertEquals(10, $row);
}
public function testGreatest() {
@ -206,7 +242,10 @@ class FunctionBuilderTest extends TestCase {
$query->from('appconfig')
->setMaxResults(1);
$this->assertEquals(2, $query->execute()->fetchColumn());
$result = $query->execute();
$row = $result->fetchColumn();
$result->closeCursor();
$this->assertEquals(2, $row);
}
public function testLeast() {
@ -216,6 +255,9 @@ class FunctionBuilderTest extends TestCase {
$query->from('appconfig')
->setMaxResults(1);
$this->assertEquals(1, $query->execute()->fetchColumn());
$result = $query->execute();
$row = $result->fetchColumn();
$result->closeCursor();
$this->assertEquals(1, $row);
}
}

View File

@ -136,7 +136,12 @@ class QuerySearchHelperTest extends TestCase {
private function search(ISearchOperator $operator) {
$dbOperator = $this->querySearchHelper->searchOperatorToDBExpr($this->builder, $operator);
$this->builder->andWhere($dbOperator);
return $this->builder->execute()->fetchAll(\PDO::FETCH_COLUMN);
$result = $this->builder->execute();
$rows = $result->fetchAll(\PDO::FETCH_COLUMN);
$result->closeCursor();
return $rows;
}
public function comparisonProvider() {

View File

@ -76,7 +76,9 @@ class LoaderTest extends \Test\TestCase {
->from('mimetypes')
->where($qb->expr()->eq('id', $qb->createPositionalParameter($mimetypeId)));
$mimetype = $qb->execute()->fetch();
$result = $qb->execute();
$mimetype = $result->fetch();
$result->closeCursor();
$this->assertEquals('testing/mymimetype', $mimetype['mimetype']);
$this->assertEquals('testing/mymimetype', $this->loader->getMimetypeById($mimetypeId));

View File

@ -102,7 +102,12 @@ class DBLockingProviderTest extends LockingProvider {
$query->select('lock')
->from('file_locks')
->where($query->expr()->eq('key', $query->createNamedParameter($key)));
return $query->execute()->fetchColumn();
$result = $query->execute();
$rows = $result->fetchColumn();
$result->closeCursor();
return $rows;
}
public function testDoubleShared() {