Open stoprocent opened 9 years ago
Does your solution actually work better than sqlite3_interrupt([db sqliteHandle]), inside a block? Something like this:
_q = [FMDatabaseQueue databaseQueueWithPath:nil];
__block sqlite3 *dbHandle;
[_q inDatabase:^(FMDatabase *db) {
dbHandle = [db sqliteHandle];
}];
// do stuff with dbHandle later on, which of course will not be thread safe unless it's inside a fmdatabasequeue block
Problem with that "inDatabase" will runs block with dispatch_sync on a private queue and if one query is taking very long to run and you just want to cancel it from outside inDatabase block you cant do it :(
With your solution what will happen is that long running query will finish and you will have nothing to cancel :)
I see. Can you add a test to your pull request, so I can see how it's used, as well as making sure it doesn't break in future updates (assuming I add it). Sounds like a reasonable idea- I just want to make sure I understand everything completely.
Sure thing
stoprocent, have you continued to use this (which I see you submitted in pull request [cbc418841115f05358a676ded83c85cb2a6eb7b2]) with success?
Hi I'm running long search queries and I wanted to be able to cancel a query with sqlite3_interrupt. All my database operations are runing on FBDatabaseQueue because of the nature my code is structured. Thing is if I run a sqlite3_interrupt([db sqliteHandle]) inside inDatabase block it will wait until long query is done.
I can develop this feature and create pull request but I didnt dig deep enough in fmdb code to see if it will have impact in other places like transactions etc.
From SQLite Docs it looks like its safe: https://www.sqlite.org/c3ref/interrupt.html An SQL operation that is interrupted will return SQLITE_INTERRUPT. If the interrupted SQL operation is an INSERT, UPDATE, or DELETE that is inside an explicit transaction, then the entire transaction will be rolled back automatically.
For now i have a very DIRTY solution :)