ryanfowler / SwiftData

Simple and Effective SQLite Handling in Swift
MIT License
518 stars 93 forks source link

Combining queries in transaction and outside transactions from multiple threads #22

Open Lopdo opened 9 years ago

Lopdo commented 9 years ago

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?

dziedziela commented 9 years ago

Is anyone going to look into this?

8ggmaker commented 8 years ago

It makes me confused ,too