beginReadOnly only increments _readOnlyDepth if it succeeds

This commit is contained in:
Gwendal Roué committed 2019-12-03 19:18:05 +01:00
1 parent bbf8e773f8
commit 831ded3ec2
1 file changed
+5 -3
+5 -3
View File
@@ -537,18 +537,20 @@ public final class Database {
// MARK: - Read-Only Access
func beginReadOnly() throws {
_readOnlyDepth += 1
if _readOnlyDepth == 1 && configuration.readonly == false {
if configuration.readonly { return }
if _readOnlyDepth == 0 {
// PRAGMA query_only was added in SQLite 3.8.0 http://www.sqlite.org/changes.html#version_3_8_0
// It is available from iOS 8.2 and OS X 10.10
// https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS)
try internalCachedUpdateStatement(sql: "PRAGMA query_only = 1").execute()
}
_readOnlyDepth += 1
}
func endReadOnly() throws {
if configuration.readonly { return }
_readOnlyDepth -= 1
if _readOnlyDepth == 0 && configuration.readonly == false {
if _readOnlyDepth == 0 {
// PRAGMA query_only was added in SQLite 3.8.0 http://www.sqlite.org/changes.html#version_3_8_0
// It is available from iOS 8.2 and OS X 10.10
// https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS)