Skip to content

Commit 8a79ce7

Browse files
committed
fixes for qualifying names
1 parent f1b7b41 commit 8a79ce7

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

extensions/positron-python/python_files/posit/positron/connections.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ def _wrap_connection(self, obj: Any) -> Connection:
311311
if not self.object_is_supported(obj):
312312
type_name = type(obj).__name__
313313
raise UnsupportedConnectionError(f"Unsupported connection type {type_name}")
314-
315314
if safe_isinstance(obj, "sqlite3", "Connection"):
316315
return SQLite3Connection(obj)
317316
elif safe_isinstance(obj, "sqlalchemy", "Engine"):
@@ -324,7 +323,7 @@ def _wrap_connection(self, obj: Any) -> Connection:
324323
return SnowflakeConnection(obj)
325324
elif safe_isinstance(obj, "databricks.sql.client", "Connection"):
326325
return DatabricksConnection(obj)
327-
elif safe_isinstance(obj, "redshift_connector.core", "Connection"):
326+
elif safe_isinstance(obj, "redshift_connector", "Connection"):
328327
return RedshiftConnection(obj)
329328
else:
330329
type_name = type(obj).__name__
@@ -345,6 +344,7 @@ def object_is_supported(self, obj: Any) -> bool:
345344
)
346345
or safe_isinstance(obj, "snowflake.connector", "SnowflakeConnection")
347346
or safe_isinstance(obj, "databricks.sql.client", "Connection")
347+
or safe_isinstance(obj, "redshift_connector", "Connection")
348348
)
349349
except Exception as err:
350350
logger.error(f"Error checking supported {err}")
@@ -1472,8 +1472,15 @@ def preview_object(self, path: list[ObjectSchema], var_name: str | None = None):
14721472
sql = f"SELECT * FROM {identifier} LIMIT 1000;"
14731473

14741474
with self.conn.cursor() as cursor:
1475-
cursor.execute(sql)
1476-
frame = cursor.fetch_dataframe()
1475+
try:
1476+
cursor.execute(sql)
1477+
frame = cursor.fetch_dataframe()
1478+
except Exception as e:
1479+
# Rollback on error to avoid transaction issues
1480+
# for subsequent queries
1481+
self.conn.rollback()
1482+
raise e
1483+
14771484
var_name = var_name or "conn"
14781485
return frame, (
14791486
f"with {var_name}.cursor() as cursor:\n"
@@ -1498,8 +1505,8 @@ def _query(self, sql: str) -> list[dict[str, Any]]:
14981505
cursor.close()
14991506

15001507
def _qualify(self, identifier: str) -> str:
1501-
escaped = identifier.replace("`", "``")
1502-
return f"`{escaped}`"
1508+
escaped = identifier.replace('"', '""')
1509+
return f'"{escaped}"'
15031510

15041511
def _make_code(self) -> str:
15051512
return (

0 commit comments

Comments
 (0)