3

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? As I see inTransaction just do putting the sql actions in a queue, but beginTransaction seems to do something in sqlite level. Which one is a better choice for thread-safe and what's the difference between them?

debuggenius
  • 449
  • 5
  • 15

1 Answers1

0

The difference is that the latter, besides having a somewhat nicer, declarative syntax is reasonably safe to be used in a multi-threaded application, especially where multiple threads share a single database connection. The latter uses a FIFO queue that performs one operation at a time.

Jasper Blues
  • 28,258
  • 22
  • 102
  • 185