diff options
author | Joas Schilling <coding@schilljs.com> | 2020-11-05 10:50:53 +0100 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2020-11-09 12:28:17 +0100 |
commit | 8027dcbc6f6b1653f5ebcf04b1862ac1e1f51d32 (patch) | |
tree | 1bf182f477bfbead7b75ae14a8cd0fce5bb38ada /lib | |
parent | 72545ffd07a07f142c9c18b3e4afc9ae1b5c8da2 (diff) | |
download | nextcloud-server-8027dcbc6f6b1653f5ebcf04b1862ac1e1f51d32.tar.gz nextcloud-server-8027dcbc6f6b1653f5ebcf04b1862ac1e1f51d32.zip |
Don't leave cursors open when tests fail
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Files/Cache/Cache.php | 68 | ||||
-rw-r--r-- | lib/private/Files/Cache/HomeCache.php | 1 | ||||
-rw-r--r-- | lib/private/Files/Cache/StorageGlobal.php | 6 | ||||
-rw-r--r-- | lib/private/Files/Config/UserMountCache.php | 17 | ||||
-rw-r--r-- | lib/private/Files/Node/Folder.php | 6 | ||||
-rw-r--r-- | lib/private/Files/Type/Loader.php | 10 | ||||
-rw-r--r-- | lib/private/Security/CredentialsManager.php | 5 | ||||
-rw-r--r-- | lib/private/Share/Share.php | 7 | ||||
-rw-r--r-- | lib/private/TagManager.php | 6 | ||||
-rw-r--r-- | lib/private/Tags.php | 3 | ||||
-rw-r--r-- | lib/private/legacy/OC_DB_StatementWrapper.php | 9 | ||||
-rw-r--r-- | lib/private/legacy/OC_Util.php | 1 |
12 files changed, 114 insertions, 25 deletions
diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index 8a173f35197..e74cc86d9c9 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -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 { diff --git a/lib/private/Files/Cache/HomeCache.php b/lib/private/Files/Cache/HomeCache.php index e66ed7d9722..f7fc806456d 100644 --- a/lib/private/Files/Cache/HomeCache.php +++ b/lib/private/Files/Cache/HomeCache.php @@ -72,6 +72,7 @@ class HomeCache extends Cache { $this->update($id, ['size' => $totalSize]); } } + $result->closeCursor(); } return $totalSize; } diff --git a/lib/private/Files/Cache/StorageGlobal.php b/lib/private/Files/Cache/StorageGlobal.php index 26a7be24634..8bf37514b8b 100644 --- a/lib/private/Files/Cache/StorageGlobal.php +++ b/lib/private/Files/Cache/StorageGlobal.php @@ -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; } diff --git a/lib/private/Files/Config/UserMountCache.php b/lib/private/Files/Config/UserMountCache.php index 6fa9cd96bfe..441a4a45326 100644 --- a/lib/private/Files/Config/UserMountCache.php +++ b/lib/private/Files/Config/UserMountCache.php @@ -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'], diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php index 668893f6549..134455dd945 100644 --- a/lib/private/Files/Node/Folder.php +++ b/lib/private/Files/Node/Folder.php @@ -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) { diff --git a/lib/private/Files/Type/Loader.php b/lib/private/Files/Type/Loader.php index d128bc724b6..489ed65c228 100644 --- a/lib/private/Files/Type/Loader.php +++ b/lib/private/Files/Type/Loader.php @@ -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']; diff --git a/lib/private/Security/CredentialsManager.php b/lib/private/Security/CredentialsManager.php index ace8e6889ec..a40a7e1d88e 100644 --- a/lib/private/Security/CredentialsManager.php +++ b/lib/private/Security/CredentialsManager.php @@ -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; diff --git a/lib/private/Share/Share.php b/lib/private/Share/Share.php index 32801fe4c08..d898254938e 100644 --- a/lib/private/Share/Share.php +++ b/lib/private/Share/Share.php @@ -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: ' . diff --git a/lib/private/TagManager.php b/lib/private/TagManager.php index 4613b6247f4..155efccfaa7 100644 --- a/lib/private/TagManager.php +++ b/lib/private/TagManager.php @@ -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; } } diff --git a/lib/private/Tags.php b/lib/private/Tags.php index 16ec7a1d25a..51f3b4689bb 100644 --- a/lib/private/Tags.php +++ b/lib/private/Tags.php @@ -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__, diff --git a/lib/private/legacy/OC_DB_StatementWrapper.php b/lib/private/legacy/OC_DB_StatementWrapper.php index 668e97c5650..64806cd205d 100644 --- a/lib/private/legacy/OC_DB_StatementWrapper.php +++ b/lib/private/legacy/OC_DB_StatementWrapper.php @@ -105,6 +105,15 @@ class OC_DB_StatementWrapper { } /** + * 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. * diff --git a/lib/private/legacy/OC_Util.php b/lib/private/legacy/OC_Util.php index 80e43a0514a..66d8d95b52d 100644 --- a/lib/private/legacy/OC_Util.php +++ b/lib/private/legacy/OC_Util.php @@ -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', '<')) { |