From 831ded3ec2c7a54cc8db01569cf3e14fa7e0577b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Tue, 3 Dec 2019 19:18:05 +0100 Subject: [PATCH] beginReadOnly only increments _readOnlyDepth if it succeeds --- GRDB/Core/Database.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/GRDB/Core/Database.swift b/GRDB/Core/Database.swift index 2c937a904..54f2aebdb 100644 --- a/GRDB/Core/Database.swift +++ b/GRDB/Core/Database.swift @@ -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)