Setting sqlite config SQLITE_CONFIG_SERIALIZED returns SQLITE_MISUSE on iOS 5

后端 未结 2 2012
夕颜
夕颜 2021-01-06 14:42

With the release of iOS 5 we are getting more and more errors when setting the serialized option for the sqlite database (so its save to be used for multithreading). We are

2条回答
  •  醉话见心
    2021-01-06 15:19

    I struggled long and hard with this as well and finally got the solution.

    As @enobufs said, sqlite3_config() needs to be called before sqlite3_initialize(). However, the OS might initialize SQLite for us so I also do a sqlite3_shutdown() before the sqlite3_config().

    1. sqlite3_shutdown()
    2. sqlite3_config()
    3. sqlite3_initialize().

    Then its also necessary to use the same connection for every query as it is the access to the database connection that gets serialized. As described here http://www.sqlite.org/capi3ref.html#sqliteconfigserialized

    So I create a connection as soon as the app starts up and the pass that connection to every class that needs it.

提交回复
热议问题