I have some code using the FMDB sqllite wrapper (https://github.com/ccgus/fmdb) and I'm expecting this code to be executed from multiple threads. As such, I'm using the FMDatabaseQueue
class to execute all DB work.
I'm a little bit confused by the pattern, e.g.
FMDatabaseQueue *q = [FMDatabaseQueue databaseQueueWithPath:@""];
[q inDatabase:^(FMDatabase *db) {
NSLog(@"1");
BOOL yn = [db executeUpdate:@"CREATE TABLE IF NOT EXISTS Foo (Bar TEXT)"];
NSLog(@"2%@", yn ? @"YES" : @"NO");
}];
NSLog(@"3");
If you look at the code above.. is it guaranteed that 3 will always be logged after 2 and 1? Such that the executing thread is blocked until the block provided to the queue actually gets to execute?
If so, should I remove any non-database work outside and after the block so that any other threads using the queue are not blocked by work that doesn't need to be synchronized across threads?
Also, do I need to call [db open]
when using FMDatabaseQueue
?