Difference between FMDB.database.beginTransaction and FMDB.databaseQueue.inTransaction
CODE A
FMDBDatabase *db = xxxxx
[db beginTransaction];
[db executeUpdate:xxxx];
xxxxxxx
CODE B
FMDBDatabaseQueue *queue = xxxxx
[queue inTransaction:^{xxxxxx}]
What is the difference between database.beginTransaction and databaseQueue.inTransaction? Since I can see inTransaction just doing sql actions in the queue, but beginTransaction seems to be doing something at the sqlite level. Which one is the best choice for thread safety and what's the difference between them?
+3
debuggenius
source
to share
1 answer
The difference is that the latter, in addition to the nicer, declarative syntax, is safe enough to use in a multithreaded application, especially when multiple threads share the same database connection. The latter uses a FIFO queue that performs one operation at a time.
0
Jasper blues
source
to share