本文介绍了sqlite3_open - 无法打开数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码中有以下语句:
I have the following statement in my code:
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
但它似乎没有打开我的数据库。
but it doesn't seem to be opening my database.
任何想法?
推荐答案
在不了解您的问题的情况下,我们只能假设您的路径无效。
Without knowing anything else about your problem, one can only assume that your path is invalid.
尝试使用此路径查看是否有效
Try using this path to see if it works
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths lastObject];
NSString* databasePath = [documentsDirectory stringByAppendingPathComponent:@"mydb.sqlite"];
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
NSLog(@"Opened sqlite database at %@", databasePath);
//...stuff
} else {
NSLog(@"Failed to open database at %@ with error %s", databasePath, sqlite3_errmsg(database));
sqlite3_close (database);
}
这篇关于sqlite3_open - 无法打开数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!