From 3eb8e0e20d7270bb69bc11ffea67f7a5860ea17c Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Sat, 7 Jun 2025 23:32:46 +0530 Subject: [PATCH 1/2] fix: sybase schema --- dcs_core/integrations/databases/sybase.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/dcs_core/integrations/databases/sybase.py b/dcs_core/integrations/databases/sybase.py index 29890def..14238850 100644 --- a/dcs_core/integrations/databases/sybase.py +++ b/dcs_core/integrations/databases/sybase.py @@ -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 " @@ -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 " @@ -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 " @@ -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 " From e33d6f06e55d061b20cf625ac8056c86c795efa9 Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Sat, 7 Jun 2025 23:37:13 +0530 Subject: [PATCH 2/2] fix: mssql table schema query --- dcs_core/integrations/databases/mssql.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dcs_core/integrations/databases/mssql.py b/dcs_core/integrations/databases/mssql.py index c3dc58b4..ef488e8e 100644 --- a/dcs_core/integrations/databases/mssql.py +++ b/dcs_core/integrations/databases/mssql.py @@ -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(