您好,我正在尝试在 ios 中创建一个 sqlite 数据库。 我将方法 sqlite3_open 与所需的参数一起使用,但我总是收到错误 14 (SQLITE_CANTOPEN 14/* 无法打开数据库文件 */)。
即使是最简单的声明也不起作用
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSString *dbPath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"data.sqlite3"];
BOOL success = [fileMgr fileExistsAtPath:dbPath];
sqlite3 *db;
if(!success)
{
NSLog(@"Cannot locate database file '%@'.", dbPath);
}
if(!(sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK))
{
NSLog(@"An error has occured.");
}
else{
NSLog(@"Ok");
}
知道发生了什么事吗?
谢谢。
最佳答案
您无法在应用程序包中获得对 sqlite 数据库的写入权限。相反,将 bundle 中的数据库复制到"file"系统中的适当位置(考虑到 iCloud 问题),然后在那里打开它。让您的应用首先在文件系统中查找数据库,只有当它不存在时才复制它。
关于iphone - 无法在 ios 上打开 sqlite 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15112441/