mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-08 01:06:59 +08:00
feat: Ask to add database version information
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user