Tried to do a read.
Data to be read with no issues.
A crash.
GRDB flavor(s): GRDB
GRDB version: v4.0.1
Installation method: CocoaPods
Xcode version: 10.2.1
Swift version: 5
Platform(s) running GRDB: iOS
macOS version running Xcode: 10.14.5
The app crashed with in the simulator this error:
Fatal error: 'try!' expression unexpectedly raised an error: SQLite error 10 with statementPRAGMA query_only = 1: disk I/O error: file /Projects/ProjectName/ProjectName/Pods/GRDB.swift/GRDB/Core/Database.swift, line 547
Hello @ahmedk92,
So the crash happens there: https://github.com/groue/GRDB.swift/blob/v4.0.1/GRDB/Core/Database.swift#L547
I've never witnessed this, so your help is needed: please provide as much context as you can, please.
For example, which version of iOS is it?
Do you happen to run your app in the background with Data Protection?
Do you follow the Concurrency Rules?
Be as precise as you can, because this piece of code runs thousands of time every day without any trouble. Your app must be running is some particular setup. Your particular support is needed in order to fix this for everybody.
iOS 12.2
It doesn't crash every time.
I'm currently doing this:
private static let dbQueue = try! DatabaseQueue(path: Bundle.main.path(forResource: "Rects", ofType: "db")!)
private static let queue = DispatchQueue(label: "SelectionRect")
static func getRects(forPage page: Int, completion: @escaping ([SelectionRect]) -> Void) {
queue.async {
dbQueue.read({ (db) in
do {
let rects = try SelectionRect.fetchAll(db, sql: "select * from exportline where pageno = ?", arguments: [page])
DispatchQueue.main.async {
completion(rects)
}
} catch {
print(error)
}
})
}
}
OK @ahmedk92. Thank you for the report. You'll be notified when the crash is fixed.
I updated to the latest GRDB and the crash is fixed. However, the error still appeared. I handle the error, but retries are no avail. I needed to restart the app for it to work.
That was to be expected. Did you investigate the reasons for this SQLite error?
It only reported that error:
SQLite error 10 with statement PRAGMA query_only = 1: disk I/O error: file
I don't remember seeing a stack trace relevant to my code. Anyways I'll check again if it happened 馃憤
Data protection may trigger an SQLite error 10 when your app attempts at accessing the database, in the background, on a locked device.
Great hint. Will have this in mind when I trace this problem tomorrow. Thanks for the idea!
Most helpful comment
Data protection may trigger an SQLite error 10 when your app attempts at accessing the database, in the background, on a locked device.