Here's my scenario,
I have multiple request when I log in to my app, and in one of it's response contains 10,000 + records.
I am using SQLite.swift in my project.
All is working fine if the user doesn't logout or doesn't more than 1 task like searching or retrieving data from db. if any of the case happens then the app gets stuck or crashes.
I am using transactions for bulk insert, but when I try to access another same table data then the app freezes until everything is done.
I tried using multiple connections to insert to db but if another connection is using the db then its locked and app crashes
fatal error: 'try!' expression unexpectedly raised an error: database is locked: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-703.0.18.1/src/swift/stdlib/public/core/ErrorType.swift, line 54
try DataManager.con.transaction {
for index in 0 ... (entity.count - 1) {
try DataManager.con.run(table.insert(
Latitude <- entity[index]["Latitude"].string,
Longitude <- entity[index]["Longitude"].string
))
}
}
Here DataManager.con is a singleton object
Please help.
main thread. - Santosh