Skip to content
Merged
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
7 changes: 5 additions & 2 deletions dcs_core/integrations/databases/mssql.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,11 @@ def query_get_table_columns(
"""
schema = schema or self.schema_name
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}'"

query = (
"SELECT column_name, data_type, ISNULL(datetime_precision, 0) AS datetime_precision, ISNULL(numeric_precision, 0) AS numeric_precision, ISNULL(numeric_scale, 0) AS numeric_scale, collation_name, ISNULL(character_maximum_length, 0) AS character_maximum_length "
f"FROM {database}.information_schema.columns"
f"WHERE table_name = '{table}' AND table_schema = '{schema}'"
)
rows = self.fetchall(query)
if not rows:
raise RuntimeError(
Expand Down
13 changes: 8 additions & 5 deletions dcs_core/integrations/databases/sybase.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ def query_get_table_columns(
if self.sybase_driver_type.is_iq:
query = (
f"SELECT c.column_name, d.domain_name AS data_type, "
f"CASE WHEN d.domain_name IN ('DECIMAL', 'NUMERIC') THEN c.scale ELSE NULL END AS numeric_scale, "
f"CASE WHEN d.domain_name IN ('DECIMAL', 'NUMERIC') THEN c.width ELSE NULL END AS numeric_precision, "
f"CASE WHEN d.domain_name IN ('DATE', 'TIME', 'TIMESTAMP') THEN c.scale ELSE NULL END AS datetime_precision, "
f"CASE WHEN t.name IN ('float') THEN 15 WHEN t.name IN ('real') THEN 7 ELSE c.prec END AS numeric_precision, "
f"CASE WHEN t.name IN ('float', 'real') THEN NULL ELSE c.scale END AS numeric_scale, "
f"NULL AS collation_name, c.width AS character_maximum_length "
f"FROM {database}.SYS.SYSTABLE t "
f"JOIN {database}.SYS.SYSCOLUMN c ON t.table_id = c.table_id "
Expand All @@ -266,8 +266,9 @@ def query_get_table_columns(
elif self.sybase_driver_type.is_ase:
query = (
f"SELECT c.name AS column_name, t.name AS data_type, "
f"c.prec AS numeric_precision, c.scale AS numeric_scale, "
f"CASE WHEN c.type IN (61, 111) THEN c.prec ELSE NULL END AS datetime_precision, "
f"CASE WHEN t.name IN ('float') THEN 15 WHEN t.name IN ('real') THEN 7 ELSE c.prec END AS numeric_precision, "
f"CASE WHEN t.name IN ('float', 'real') THEN NULL ELSE c.scale END AS numeric_scale, "
f"NULL AS collation_name, c.length AS character_maximum_length "
f"FROM {database}..sysobjects o "
f"JOIN {database}..syscolumns c ON o.id = c.id "
Expand All @@ -280,8 +281,9 @@ def query_get_table_columns(
try:
ase_query = (
f"SELECT c.name AS column_name, t.name AS data_type, "
f"c.prec AS numeric_precision, c.scale AS numeric_scale, "
f"CASE WHEN c.type IN (61, 111) THEN c.prec ELSE NULL END AS datetime_precision, "
f"CASE WHEN t.name IN ('float') THEN 15 WHEN t.name IN ('real') THEN 7 ELSE c.prec END AS numeric_precision, "
f"CASE WHEN t.name IN ('float', 'real') THEN NULL ELSE c.scale END AS numeric_scale, "
f"NULL AS collation_name, c.length AS character_maximum_length "
f"FROM {database}..sysobjects o "
f"JOIN {database}..syscolumns c ON o.id = c.id "
Expand All @@ -295,8 +297,9 @@ def query_get_table_columns(
except Exception as _:
iq_query = (
f"SELECT c.name AS column_name, t.name AS data_type, "
f"c.prec AS numeric_precision, c.scale AS numeric_scale, "
f"CASE WHEN c.type IN (61, 111) THEN c.prec ELSE NULL END AS datetime_precision, "
f"CASE WHEN t.name IN ('float') THEN 15 WHEN t.name IN ('real') THEN 7 ELSE c.prec END AS numeric_precision, "
f"CASE WHEN t.name IN ('float', 'real') THEN NULL ELSE c.scale END AS numeric_scale, "
f"NULL AS collation_name, c.length AS character_maximum_length "
f"FROM {database}.dbo.sysobjects o "
f"JOIN {database}.dbo.syscolumns c ON o.id = c.id "
Expand Down
Loading