我在捕获损坏的.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;
}
我建议您尝试直接使用 FMDB 或 SQLite 库来打开 MBTiles 以首先测试事物。两者都应该有调用,让你在将它们传递给更高级别的库之前确定事情是否成功。