SQLite Step Failed: attempt to write a readonly database

前端之家收集整理的这篇文章主要介绍了SQLite Step Failed: attempt to write a readonly database前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

进行数据库操作的时候,有时候会报错

SQLite Step Failed: attempt to write a readonly database

也就是说你不能对你的bundle进行任何操作了,解决办法是把你的数据库建在Documents下

NSString *path = [self getFullDatabasePathFromFileName:@"AppData.db"];

_database = [[FMDatabase alloc] initWithPath:path];

if ([_database open]) {

[self creatTable];

}else{

DLog(@"open database:%@",[_database lastErrorMessage]);

}


#pragma mark - 获取数据库文件的全路径

- (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;

}

}

原文链接:https://www.f2er.com/sqlite/198910.html

猜你在找的Sqlite相关文章