无法更新物理设备上的sqlite表。
我在网上搜索,我更新了权限(chmod 777
),将sqlite复制到文档文件夹。但它仍然无法正常工作。
我尝试拨打sqlite3_open
或sqlite3_open_v2
,但两者都有相同的错误。下面是我的一些编码片段。非常感谢。
- (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)