Skip to content

Commit f914bea

Browse files
authored
fix: database quoting (#299)
1 parent 4dbde81 commit f914bea

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

dcs_core/core/datasource/sql_datasource.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,14 @@ def qualified_table_name(self, table_name: str) -> str:
137137
return f"[{self.schema_name}].[{table_name}]"
138138
return f"[{table_name}]"
139139

140+
def quote_database(self, database: str) -> str:
141+
"""
142+
Quote the database name
143+
:param database: name of the database
144+
:return: quoted database name
145+
"""
146+
return f'"{database}"'
147+
140148
def quote_column(self, column: str) -> str:
141149
"""
142150
Quote the column name

dcs_core/integrations/databases/mssql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def query_get_table_columns(
150150
:return: RawColumnInfo object containing column information
151151
"""
152152
schema = schema or self.schema_name
153-
database = self.database
153+
database = self.quote_database(self.database)
154154
query = f"SELECT column_name, data_type, datetime_precision, numeric_precision, numeric_scale, collation_name, character_maximum_length FROM {database}.information_schema.columns WHERE table_name = '{table}' AND table_schema = '{schema}'"
155155

156156
rows = self.fetchall(query)

dcs_core/integrations/databases/postgres.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ def query_get_table_names(
8282
"""
8383

8484
schema = schema or self.schema_name
85-
database = self.database
85+
database = self.quote_database(self.database)
8686
query = (
87-
f'SELECT table_name FROM "{database}".information_schema.tables '
87+
f'SELECT table_name FROM {database}.information_schema.tables '
8888
f"WHERE table_schema = '{schema}' AND table_type = 'BASE TABLE'"
8989
)
9090
result = self.fetchall(query)
@@ -103,7 +103,8 @@ def query_get_table_columns(
103103
schema = schema or self.schema_name
104104
info_schema_path = ["information_schema", "columns"]
105105
if self.database:
106-
info_schema_path.insert(0, self.database)
106+
database = self.quote_database(self.database)
107+
info_schema_path.insert(0, database)
107108
query = (
108109
f"SELECT column_name, data_type, datetime_precision, "
109110
f"CASE WHEN data_type = 'numeric' "

0 commit comments

Comments
 (0)