【发布时间】:2013-02-27 12:42:49
【问题描述】:
您好,我正在尝试在 ios 中创建一个 sqlite 数据库。 我使用带有所需参数的 sqlite3_open 方法,但我总是收到错误 14 (SQLITE_CANTOPEN 14 /* Unable to open the database file */)。
即使是最简单的声明也不起作用
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");
}
有什么想法吗?
谢谢。
【问题讨论】:
-
在这种情况下可能没有帮助,但一般来说,当您收到错误的返回码时,请执行
NSLog(@"SQLite errmsg = %s", sqlite3_errmsg());,以获取文本错误消息。