feat: Ask to add database version information

This commit is contained in:
junjun
2025-09-01 15:37:25 +08:00
parent 86c85d6b0f
commit 06a29a9e23
+7 -5
View File
@@ -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):