From 06a29a9e238cb4497ab5b0cdc289c44135659ead Mon Sep 17 00:00:00 2001 From: junjun Date: Mon, 1 Sep 2025 15:37:25 +0800 Subject: [PATCH] feat: Ask to add database version information --- backend/apps/db/db.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/backend/apps/db/db.py b/backend/apps/db/db.py index a23294ff..a86dc838 100644 --- a/backend/apps/db/db.py +++ b/backend/apps/db/db.py @@ -156,6 +156,7 @@ def check_connection(trans: Trans, ds: CoreDatasource, is_raise: bool = False): def get_version(ds: CoreDatasource | AssistantOutDsSchema): + version = '' conf = None if isinstance(ds, CoreDatasource): conf = DatasourceConf( @@ -176,26 +177,27 @@ def get_version(ds: CoreDatasource | AssistantOutDsSchema): with get_session(ds) as session: with session.execute(text(sql)) as result: res = result.fetchall() - return res[0][0] + version = res[0][0] else: if ds.type == 'dm': with dmPython.connect(user=conf.username, password=conf.password, server=conf.host, port=conf.port) as conn, conn.cursor() as cursor: cursor.execute(sql, timeout=10) res = cursor.fetchall() - return res[0][0] + version = res[0][0] elif ds.type == 'doris': with pymysql.connect(user=conf.username, passwd=conf.password, host=conf.host, port=conf.port, db=conf.database, connect_timeout=10, read_timeout=10) as conn, conn.cursor() as cursor: cursor.execute(sql) res = cursor.fetchall() - return res[0][0] + version = res[0][0] elif ds.type == 'redshift': - return '' + version = '' except Exception as e: print(e) - return '' + version = '' + return version.decode() if isinstance(version, bytes) else version def get_schema(ds: CoreDatasource):