@@ -85,12 +85,7 @@ class Db2EngineAdapter(
8585 def get_current_catalog (self ) -> t .Optional [str ]:
8686 """
8787 Db2 requires FROM SYSIBM.SYSDUMMY1 to read the CURRENT SERVER special register.
88- Returns the value uppercased to match the convention used by _default_catalog
89- (which comes from get_catalog() → database name as supplied in config, uppercased).
90- The set_catalog() decorator's REQUIRES_SET_CATALOG path compares
91- catalog_name != get_current_catalog() — normalising both to uppercase ensures
92- the comparison is consistent regardless of which dialect (db2 UPPERCASE vs
93- duckdb LOWERCASE) produced the catalog token in the model expression.
88+ Returns uppercase to match the Db2 dialect's identifier normalisation.
9489 """
9590 result = self .fetchone ("SELECT CURRENT SERVER FROM SYSIBM.SYSDUMMY1" )
9691 if result :
@@ -331,19 +326,7 @@ def _db2_type_to_sqlglot(self, db2_type: str, length: int, scale: int) -> exp.Da
331326
332327 @property
333328 def catalog_support (self ) -> CatalogSupport :
334- # REQUIRES_SET_CATALOG is used instead of SINGLE_CATALOG_ONLY because the
335- # SINGLE_CATALOG_ONLY path in set_catalog() (shared.py:346) does a raw ==
336- # comparison between catalog_name and _default_catalog. catalog_name comes
337- # from the model expression, whose case depends on the dialect that built it:
338- # db2 dialect → UPPERCASE, duckdb dialect → lowercase. Either case can appear
339- # at runtime and we cannot control which, so a raw == would fail for one case.
340- #
341- # The REQUIRES_SET_CATALOG path instead calls get_current_catalog() for the
342- # right-hand side. By returning uppercase from both get_catalog() (connection.py)
343- # and get_current_catalog(), and by making set_current_catalog() a no-op (Db2 has
344- # only one catalog — CONNECT TO cannot change it meaningfully), the mismatch is
345- # tolerated: lowercase "testdb" != "TESTDB" → set_current_catalog (no-op) → proceed.
346- return CatalogSupport .REQUIRES_SET_CATALOG
329+ return CatalogSupport .SINGLE_CATALOG_ONLY
347330
348331 def table_exists (self , table_name : TableName ) -> bool :
349332 """
@@ -851,18 +834,9 @@ def _df_to_source_queries(
851834 )
852835
853836 def set_current_catalog (self , catalog : str ) -> None :
854- """
855- No-op for Db2 — there is only one catalog (the database name) and CONNECT TO
856- cannot switch to a different one in the middle of a session. The set_catalog()
857- decorator calls this when catalog_name != get_current_catalog(), which happens
858- because model expressions built through a duckdb-dialect context carry lowercase
859- catalog names while get_current_catalog() returns uppercase. The mismatch is
860- case-only and harmless, so we log it and return without executing any SQL.
861- """
862- logger .debug (
863- "set_current_catalog called with %r — no-op for Db2 (single-catalog engine)" ,
864- catalog ,
865- )
837+ """Switches the active catalog using Db2's CONNECT TO statement."""
838+ self .execute (f"CONNECT TO { catalog } " )
839+ logger .debug ("Switched to catalog: %s" , catalog )
866840
867841 @cached_property
868842 def server_version (self ) -> t .Tuple [int , int ]:
0 commit comments