mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-08 09:17:06 +08:00
fix(datasource): fix ClickHouse datasource get tables error
This commit is contained in:
@@ -254,7 +254,7 @@ def get_schema(ds: CoreDatasource):
|
||||
def get_tables(ds: CoreDatasource):
|
||||
conf = DatasourceConf(**json.loads(aes_decrypt(ds.configuration))) if ds.type != "excel" else get_engine_config()
|
||||
db = DB.get_db(ds.type)
|
||||
sql = get_table_sql(ds, conf)
|
||||
sql = get_table_sql(ds, conf, get_version(ds))
|
||||
if db.connect_type == ConnectType.sqlalchemy:
|
||||
with get_session(ds) as session:
|
||||
with session.execute(text(sql)) as result:
|
||||
|
||||
@@ -32,7 +32,7 @@ def get_version_sql(ds: CoreDatasource, conf: DatasourceConf):
|
||||
return ''
|
||||
|
||||
|
||||
def get_table_sql(ds: CoreDatasource, conf: DatasourceConf):
|
||||
def get_table_sql(ds: CoreDatasource, conf: DatasourceConf, db_version: str = ''):
|
||||
if ds.type == "mysql" or ds.type == "doris":
|
||||
return f"""
|
||||
SELECT
|
||||
@@ -95,13 +95,23 @@ def get_table_sql(ds: CoreDatasource, conf: DatasourceConf):
|
||||
ORDER BY t.TABLE_NAME
|
||||
"""
|
||||
elif ds.type == "ck":
|
||||
return f"""
|
||||
SELECT name, comment
|
||||
FROM system.tables
|
||||
WHERE database = '{conf.database}'
|
||||
AND engine NOT IN ('Dictionary')
|
||||
ORDER BY name
|
||||
"""
|
||||
version = int(db_version.split('.')[0])
|
||||
if version < 22:
|
||||
return f"""
|
||||
SELECT name, null as comment
|
||||
FROM system.tables
|
||||
WHERE database = '{conf.database}'
|
||||
AND engine NOT IN ('Dictionary')
|
||||
ORDER BY name
|
||||
"""
|
||||
else:
|
||||
return f"""
|
||||
SELECT name, comment
|
||||
FROM system.tables
|
||||
WHERE database = '{conf.database}'
|
||||
AND engine NOT IN ('Dictionary')
|
||||
ORDER BY name
|
||||
"""
|
||||
elif ds.type == 'dm':
|
||||
return f"""
|
||||
select table_name, comments
|
||||
|
||||
Reference in New Issue
Block a user