SwiftData icon indicating copy to clipboard operation
SwiftData copied to clipboard

Combining queries in transaction and outside transactions from multiple threads

Open Lopdo opened this issue 9 years ago • 2 comments

I have an app that downloads bunch of data and saves it into DB, I save this data in transaction in background thread. I also make simple SELECT queries from main thread that are not in any transaction. There are some weird crashes in my app (transaction closure, not sure where exactly) that led me to check this method:

private static func putOnThread(task: ()->Void) {
    if SQLiteDB.sharedInstance.inTransaction || SQLiteDB.sharedInstance.savepointsOpen > 0 || SQLiteDB.sharedInstance.openWithFlags {
        task()
    } else {
        dispatch_sync(SQLiteDB.sharedInstance.queue) {
            task()
        }
    }
}

If I am reading this correctly then it means that if I execute any query while one of transactions is in progress (in background thread), that new query will not be run in SD queue but it will be executed immediately. Is this intentional? Can it cause some problems in situation I described above?

Lopdo avatar Mar 16 '15 12:03 Lopdo

Is anyone going to look into this?

dziedziela avatar May 27 '15 08:05 dziedziela

It makes me confused ,too

8ggmaker avatar Jul 29 '16 15:07 8ggmaker