ios - 在 xCode 11 中接收 SQLite 错误代码 26?
问题描述
全部,
我继承了一个用objective-c 为iPad 编写的应用程序。应用程序构建正确,但我在首次加载时收到以下错误。
*file is not a database in "PRAGMA journal_mode=WAL;"
- DB Error: 26 "file is not a database"
- DB Query: PRAGMA journal_mode=WAL;
- DB Path: /Users/.../Library/Developer/CoreSimulator/Devices/335DABAF-9A41-4260-8293-A9EC42DC9CE3/data/Containers/Data/Application/89C9DEB8-73AB-45F0-BCF0-1774DA2BDBD0/Documents/database_dev_20170120.sqlite*
下面是初始化 sqlite 数据库的代码。将数据库置于 WAL 模式时会引发错误。
我验证了 sqlite 数据库存在于 iOS 模拟器的正确文件路径中。
- (id)init {
self = [super init];
if (self) {
NSString *path = [[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:[Configuration databaseFilename]] stringByAppendingPathExtension:@"sqlite"];
DLog(@"#DB - %@", path);
if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
NSError *error;
[[NSFileManager defaultManager] copyItemAtPath:[[NSBundle mainBundle] pathForResource:[Configuration databaseFilename] ofType:@"sqlite"] toPath:path error:&error];
NSAssert(error == nil, [error description]);
}
//exclude form iCloud backup
[[NSURL fileURLWithPath:path] setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:nil];
self.databaseQueue = [FMDatabaseQueue databaseQueueWithPath:path];
[self inDatabase:^(FMDatabase *db) {
FMResultSet *rs = [db executeQuery:@"PRAGMA journal_mode=WAL;"];
[rs close];
}];
}
return self;
}
如果我需要提供更多详细信息,请告诉我。我是iOS开发新手...
解决方案
推荐阅读
- visual-studio-2010 - Visual Studio 2019 软件包.config
- vb.net - 两个应用程序中的 VB .Net 不同的算术结果
- android - ionic cordova camera.getPicture 什么也不返回
- c++ - C ++切换所有内容,除了
- java - 在 GTK 中,打开新 shell 后将焦点返回到文本输入
- javascript - 以编程方式打开 Vuetify 中的每个扩展面板
- django - 在 Django 创建视图中传递主键
- python - 拖放棋子
- kubernetes - 使用 pod 的名称而不是主机和端口调用 pod
- visual-studio - 如何在 specflow 中设置 .feature 文件的执行顺序?