我的代码中有以下声明:
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
但它似乎没有打开我的数据库.
有任何想法吗 ?
如果不了解您的问题,我们只能假设您的路径无效.
尝试使用此路径查看它是否有效
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); }