fix: handle None in catalog contstructor (#18)

This commit is contained in:
Ted Conbeer 2025-03-17 12:27:36 -06:00 committed by GitHub
commit 80babe642f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 5 deletions

View file

@ -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)).

View file

@ -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(