下载并在iOS中使用SQLite文件(Download and use sqlite file in

2019-08-08 06:02发布

我已经成功地使用了.sqlite文件当我把它保存在我的项目文件夹中。 现在我试图做同样的事情,除了从网上拉文件,而不是在本地存储的。 在此基础上的代码有什么建议? 我越来越从代码底部的错误消息“有准备的语句问题”。

    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");
    }

Answer 1:

你的Dropbox URL将无法正常工作,您需要使用: https://www.dropbox.com/s/zpcieluo2qv43vy/builds.sqlite?dl=1

或者你只是下载一个网页...



文章来源: Download and use sqlite file in iOS