我在捕获损坏的 .mbtiles 文件的异常时遇到问题,这需要 MapBox。如果文件损坏,初始化 MapBox 视图时:
self.mapView = [[RMMapView alloc] initWithFrame:self.frame andTilesource:self.tilesStandard];
我收到错误:调用 sqlite3_step 时出现未知错误(11:数据库磁盘映像格式错误)rs
我能做些什么来捕捉这个错误?
更新:我通过直接使用 SQLite 库打开 MBTiles 来测试它解决了这个问题,正如建议的incanus:
- (BOOL)isReadableDatabase:(sqlite3 *)database {
BOOL result = YES;
sqlite3_stmt* statement;
char * errmsg;
NSString *query = @"SELECT name FROM sqlite_master WHERE type=\'table\'";
if ( sqlite3_prepare_v2(database, query.UTF8String, -1, &statement, NULL) == SQLITE_OK ) {
while(sqlite3_step(statement) == SQLITE_ROW ) {
NSString *tableName = [NSString stringWithCString:(const char *)sqlite3_column_text(statement, 0) encoding:NSUTF8StringEncoding];
NSString *query_table = format(@"SELECT * FROM %@", tableName);
if (sqlite3_exec(database, query_table.UTF8String, NULL, NULL, &errmsg) != SQLITE_OK) {
DLog(@"The map is corrupted with sql error: %s", sqlite3_errmsg(database))
sqlite3_close(database);
result = NO;
break;
}
}
}
sqlite3_clear_bindings(statement);
sqlite3_finalize(statement);
return result;
}