Jeff Grimes
Jeff Grimes

Reputation: 2340

Download and use sqlite file in iOS

I have successfully used a .sqlite file when I store it in my project folder. I'm now trying to do the same thing, except pull the file from online instead of storing it locally. Any suggestions based on this code? I'm getting the error message "Problem with prepare statement" from the bottom of the code.

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

Upvotes: 0

Views: 1824

Answers (1)

Nick Hingston
Nick Hingston

Reputation: 8880

Your dropbox URL will not work, you need to use: https://www.dropbox.com/s/zpcieluo2qv43vy/builds.sqlite?dl=1

or you are just downloading a webpage...

Upvotes: 1

Related Questions