将 .sqlite 文件存储在我的项目文件夹中时,我已成功使用它。我现在正在尝试做同样的事情,除了从在线拉文件而不是在本地存储它。基于此代码的任何建议?我从代码底部收到错误消息“prepare statement 问题”。
NSData *fetchedData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"https://www.dropbox.com/s/zpcieluo2qv43vy/builds.sqlite?dl=1"]];
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *filePath = [documentsPath stringByAppendingPathComponent:@"builds.sqlite"];
[fetchedData writeToFile:filePath atomically:YES];
NSFileManager *fileMgr = [NSFileManager defaultManager];
BOOL success = [fileMgr fileExistsAtPath:filePath];
if (!success) {
NSLog(@"Cannot locate database file '%@'.", filePath);
}
if (!(sqlite3_open([filePath UTF8String], &db) == SQLITE_OK)) {
NSLog(@"An error has occured.");
}
const char *sql = "SELECT * FROM builds";
sqlite3_stmt *sqlStatement;
if (sqlite3_prepare(db, sql, -1, &sqlStatement, NULL) != SQLITE_OK) {
NSLog(@"Problem with prepare statement");
}