7

The page http://www.sqlite.org/threadsafe.html mentions:

  • Single-thread
  • Multi-thread
  • Serialized

Which mode is the sqlite that is integrated in iOS 5 compiled in?

guruz
  • 1,604
  • 14
  • 21

3 Answers3

7

OK, so sqlite3_threadsafe() returns 2 so it is compiled with SQLITE_CONFIG_MULTITHREAD on iOS. That is unfortunate, I would have liked Serialized.

sqlite3_config(SQLITE_CONFIG_SERIALIZED) unfortunately gives me SQLITE_MISUSE

guruz
  • 1,604
  • 14
  • 21
  • 1
    Try to open the DB connection with full mutex: `sqlite3_open_v2(sqliteFilePath, &sqlite, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE | SQLITE_OPEN_FULLMUTEX, NULL);` – electronix384128 Feb 21 '18 at 22:29
3

As per this answer - https://stackoverflow.com/a/7799021/40444

It appears you can do the following:

sqlite3_shutdown();
if (sqlite3_config(SQLITE_CONFIG_SERIALIZED) == SQLITE_OK) {
    NSLog(@"sqlite configured to be threadsafe);
}
sqlite3_initialize();

However it's unclear if this officially works.

Community
  • 1
  • 1
Glen T
  • 1,550
  • 1
  • 13
  • 22
0

The answer is Multi-thread. We can check by using sqlite3_threadsafe(), which returns 2.

0 - Single-thread
2 - Multi-thread
1 - Serialized

Q: @Ben Marten "unfortunately logging sqlite3_threadsafe() does not show any difference after the setting's been applied... "

A: sqlite3_threadsafe() only reports on the compile-time mutex setting of the [SQLITE_THREADSAFE] flag.

The return value of the sqlite3_threadsafe() interface is determined by the compile-time threading mode selection. If single-thread mode is selected at compile-time, then sqlite3_threadsafe() returns false. If either the multi-thread or serialized modes are selected, then sqlite3_threadsafe() returns true. The sqlite3_threadsafe() interface predates the multi-thread mode and start-time and run-time mode selection and so is unable to distinguish between multi-thread and serialized mode nor is it able to report start-time or run-time mode changes.

Jirui
  • 139
  • 1
  • 6