sqlite设置串行模式,ios4的做法是:
sqlite3 * database;
sqlite3_config(SQLITE_CONFIG_SERIALIZED);
if (sqlite3_open([dataPath UTF8String], &database) == SQLITE_OK) {
...
}或:
sqlite3 * database;
if (sqlite3_open_v2([dataPath UTF8String], &database, SQLITE_OPEN_FULLMUTEX, NULL) == SQLITE_OK) {
...
}
但在ios5.0.1上试不成功,在网上搜到别人也遇到此问题:
- (sqlite3 *)getNewDBConnection {
NSLog(@"sqlite3 lib version: %s", sqlite3_libversion()); //sqlite3_config() has to be called before any sqlite3_open calls. if (sqlite3_threadsafe() > 0) {
int retCode = sqlite3_config(SQLITE_CONFIG_SERIALIZED);
if (retCode == SQLITE_OK) {
NSLog(@"Can now use sqlite on multiple threads, using the same connection");
} else {
NSLog(@"setting sqlite thread safe mode to serialized failed!!! return code: %d", retCode);
}
} else {
NSLog(@"Your SQLite database is not compiled to be threadsafe.");
} sqlite3 *newDBconnection; // Open the database
if (sqlite3_open([[self getDatabaseFilePath] UTF8String], &newDBconnection) == SQLITE_OK) {
NSLog(@"Database Successfully Opened :)");
} else {
sqlite3_close(newDBconnection);
NSLog(@"Error in opening database :(");
} return newDBconnection;
}输出结果:
sqlite3 lib version: 3.7.7
setting sqlite thread safe mode to serialized failed!!! return code: 21
Database Successfully Opened :)不知如何解决此问题?
sqlite3 * database;
sqlite3_config(SQLITE_CONFIG_SERIALIZED);
if (sqlite3_open([dataPath UTF8String], &database) == SQLITE_OK) {
...
}或:
sqlite3 * database;
if (sqlite3_open_v2([dataPath UTF8String], &database, SQLITE_OPEN_FULLMUTEX, NULL) == SQLITE_OK) {
...
}
但在ios5.0.1上试不成功,在网上搜到别人也遇到此问题:
- (sqlite3 *)getNewDBConnection {
NSLog(@"sqlite3 lib version: %s", sqlite3_libversion()); //sqlite3_config() has to be called before any sqlite3_open calls. if (sqlite3_threadsafe() > 0) {
int retCode = sqlite3_config(SQLITE_CONFIG_SERIALIZED);
if (retCode == SQLITE_OK) {
NSLog(@"Can now use sqlite on multiple threads, using the same connection");
} else {
NSLog(@"setting sqlite thread safe mode to serialized failed!!! return code: %d", retCode);
}
} else {
NSLog(@"Your SQLite database is not compiled to be threadsafe.");
} sqlite3 *newDBconnection; // Open the database
if (sqlite3_open([[self getDatabaseFilePath] UTF8String], &newDBconnection) == SQLITE_OK) {
NSLog(@"Database Successfully Opened :)");
} else {
sqlite3_close(newDBconnection);
NSLog(@"Error in opening database :(");
} return newDBconnection;
}输出结果:
sqlite3 lib version: 3.7.7
setting sqlite thread safe mode to serialized failed!!! return code: 21
Database Successfully Opened :)不知如何解决此问题?
解决方案 »
- iphone多线程问题,高手请入。
- ios开发培训改变就业难
- 什么是第三方框架?
- 难道真的让我放弃sublime
- 初学ios遇到麻烦了,烦请大神讲解
- APP加急审核
- UITableViewController控制器继承于UIViewController ,self.view == self.tableView 问题
- CollectionView的cell 消失时会调用什么方法
- 懒加载中为什么有的地方不能用self.cover语法 ,只能用_cover语法?求助
- iOS中检测手机中是否装有某app
- iphone sdk xcode程序中如何调用web service?
- 有直接把HTML5网页封装成IOS应用的工具吗?
sqlite3_open_v2([dataPath UTF8String], &database, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX, NULL);
也不行,怀疑iphone5 固定sqlite 为多线程模式了。
上楼提议用开源的sqlite 类库,不知哪里有?另外,对程序的兼容性有影响吗?