进行数据库操作的时候,有时候会报错
SQLite Step Failed: attempt to write a readonly database
NSString *path = [self getFullDatabasePathFromFileName:@"AppData.db"];
_database = [[FMDatabase alloc] initWithPath:path];
if ([_database open]) {
[self creatTable];
}else{
DLog(@"open database:%@",[_database lastErrorMessage]);
}
- (NSString *)getFullDatabasePathFromFileName:(NSString *)name{
NSString *path = NSHomeDirectory();
NSString *docPath = [path stringByAppendingPathComponent:@"Documents"];
NSFileManager *fm = [NSFileManager defaultManager];
if ([fm fileExistsAtPath:docPath]) {
return [docPath stringByAppendingFormat:@"/%@",name];
}else{
DLog(@"Documents不存在");
return nil;
}
}