Data transferred from:
Http://blog.csdn.net/yifanernei/article/details/5642127
SQLite supports three thread modes:
1. Single-thread modeSqlite_config_singlethread
In this mode, mutual exclusion is not performed, and multithreading is insecure.
2. MultithreadingSqlite_config_multithread
In this mode, using a single database connection in multiple threads is not safe, otherwise it is safe.(Note: you cannot share database connections among multiple threads)
3. Serial ModeSqlite_config_serialized
In this mode, SQLite is thread-safe..Note: use the same database connection without mutual exclusion in multiple threads)
Select thread mode during running
If the single-thread mode is not specified at the time of compilation and startup, each database connection can be separately specified as a multi-thread mode or a serial mode at the time of creation, but cannot be specified as a single-thread mode. If it is set to single-thread mode during compilation or startup, you cannot specify multi-thread or serial mode during connection creation.
When creating a connection, use the third parameter of the sqlite3_open_v2 () function to specify the thread mode. Sqlite_open_nomutex identifies a connection to create a multi-threaded connection
Sqlite_open_fullmutex identifies the connection to create a serial mode. If no identifier is specified, or sqlite3_open () or
Sqlite3_open16 () function to create a database connection. The thread mode specified during compilation or startup will be used as the default thread mode.
In the iPhone, write at startupCode:
Sqlite3_config (sqlite_config_serialized); // This sentence does not have this effect //.....
Data consistency should be guaranteed.
// Sqlite3_config (sqlite_config_serialized );
// Sqlite3_exec (Database, "Pragma cache_size = 8000;", null );
// Sqlite3_exec (Database, "Pragma synchronous = off", null );
Sqlite3_busy_timeout (Database, 500); // The Code takes effect, and the effect of using a thread lock...
The current solution is to use the thread lock together with the code.
Currently, the database operation does not use a singleton. That is, the database will be connected to each read operation. The effect of using a singleton is the same ..
Continuous learning ing