lundi 21 décembre 2015

iOS attempt to write a readonly database

It is failed to update the sqlite table on my physical device. I searched around the web, I have update the permission (chmod 777), copy the sqlite to the documents folder. But it is still not working. And I have try to call sqlite3_open or sqlite3_open_v2, but both have the same error. Below is my some coding snippet. Many Thanks.


- (void) copyDatabaseIfNeeded {

    //Using NSFileManager we can perform many file system operations.
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error;

    NSString *dbPath = [self getDBPath];
    BOOL success = [fileManager fileExistsAtPath:dbPath];

    if(!success) {
        NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"xx.sqlite"];
        success = [fileManager copyItemAtPath:defaultDBPath toPath:dbPath error:&error];   
        if (!success)
            NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
    }
}


Try1

sqlite3_open([url UTF8String], &database) == SQLITE_OK) 
sqlite3_exec(database, insertSql, NULL, NULL, &insertErrorMsg)==SQLITE_OK)

Try2

sqlite3_open_v2([url UTF8String], &database, SQLITE_OPEN_READWRITE, NULL);
sqlite3_exec(database, insertSql, NULL, NULL, &insertErrorMsg)==SQLITE_OK)

Aucun commentaire:

Enregistrer un commentaire