diff --git a/CHANGELOG.md b/CHANGELOG.md index 24739f8..876c4dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +- Fixes a crash caused by ODBC drivers that return non-standard data from a call to `cursor.tables()` ([tconbeer/harlequin#780](https://github.com/tconbeer/harlequin/issues/780) - thank you [@khalid-talakshi](https://github.com/khalid-talakshi)!). + ## [0.3.0] - 2025-02-25 - The Data Catalog now displays all databases on the connected server, not just the currently-connected database ([tconbeer/harlequin#415](https://github.com/tconbeer/harlequin/discussions/415)). diff --git a/src/harlequin_odbc/adapter.py b/src/harlequin_odbc/adapter.py index 61cc922..04feff0 100644 --- a/src/harlequin_odbc/adapter.py +++ b/src/harlequin_odbc/adapter.py @@ -148,12 +148,19 @@ class HarlequinOdbcConnection(HarlequinConnection): cur = self.aux_conn.cursor() catalog: dict[str, dict[str, list[tuple[str, str]]]] = {} for db_name, schema_name, rel_name, rel_type, *_ in cur.tables(catalog="%"): + if db_name is None: + continue if db_name not in catalog: - catalog[db_name] = {schema_name: [(rel_name, rel_type)]} - elif schema_name not in catalog[db_name]: - catalog[db_name][schema_name] = [(rel_name, rel_type)] - else: - catalog[db_name][schema_name].append((rel_name, rel_type)) + catalog[db_name] = dict() + + if schema_name is None: + continue + if schema_name not in catalog[db_name]: + catalog[db_name][schema_name] = list() + + if rel_name is not None: + catalog[db_name][schema_name].append((rel_name, rel_type or "")) + return catalog def _list_columns_in_relation(