Skip to content

Commit ab6e1dc

Browse files
committed
fix: check sql only contain read operation #814
1 parent 184e76e commit ab6e1dc

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

backend/apps/db/db.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,10 +577,11 @@ def exec_sql(ds: CoreDatasource | AssistantOutDsSchema, sql: str, origin_column=
577577
raise Exception(str(ex))
578578

579579

580-
def check_sql_read(sql: str, dialect=None):
580+
def check_sql_read(sql: str, ds: CoreDatasource | AssistantOutDsSchema):
581581
try:
582-
ansi_escape = re.compile(r'\x1b\[[0-9;]*m')
583-
sql = ansi_escape.sub('', sql)
582+
dialect = None
583+
if ds.type == "mysql" or ds.type == "doris" or ds.type == "starrocks":
584+
dialect = 'mysql'
584585

585586
statements = sqlglot.parse(sql, dialect=dialect)
586587

0 commit comments

Comments
 (0)