Skip to content

fix: database quoting #299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions dcs_core/core/datasource/sql_datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ def qualified_table_name(self, table_name: str) -> str:
return f"[{self.schema_name}].[{table_name}]"
return f"[{table_name}]"

def quote_database(self, database: str) -> str:
"""
Quote the database name
:param database: name of the database
:return: quoted database name
"""
return f'"{database}"'

def quote_column(self, column: str) -> str:
"""
Quote the column name
Expand Down
2 changes: 1 addition & 1 deletion dcs_core/integrations/databases/mssql.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def query_get_table_columns(
:return: RawColumnInfo object containing column information
"""
schema = schema or self.schema_name
database = self.database
database = self.quote_database(self.database)
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}'"

rows = self.fetchall(query)
Expand Down
7 changes: 4 additions & 3 deletions dcs_core/integrations/databases/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ def query_get_table_names(
"""

schema = schema or self.schema_name
database = self.database
database = self.quote_database(self.database)
query = (
f'SELECT table_name FROM "{database}".information_schema.tables '
f'SELECT table_name FROM {database}.information_schema.tables '
f"WHERE table_schema = '{schema}' AND table_type = 'BASE TABLE'"
)
result = self.fetchall(query)
Expand All @@ -103,7 +103,8 @@ def query_get_table_columns(
schema = schema or self.schema_name
info_schema_path = ["information_schema", "columns"]
if self.database:
info_schema_path.insert(0, self.database)
database = self.quote_database(self.database)
info_schema_path.insert(0, database)
query = (
f"SELECT column_name, data_type, datetime_precision, "
f"CASE WHEN data_type = 'numeric' "
Expand Down
Loading