首页 > 解决方案 > 在 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开发新手...

标签: iosobjective-cxcodesqlite

解决方案


推荐阅读