Skip to content

Commit

Permalink
删除 oracle engine 中 filter_sql 实现 (#2797)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: 胡红伟 <huhw53743@hundsun.com>
  • Loading branch information
hhw007 and 胡红伟 authored Sep 11, 2024
1 parent 083e841 commit 54bb3dc
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 46 deletions.
10 changes: 0 additions & 10 deletions sql/engines/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,16 +643,6 @@ def query_check(self, db_name=None, sql=""):
result["msg"] = keyword_warning
return result

def filter_sql(self, sql="", limit_num=0):
sql_lower = sql.lower()
# 对查询sql增加limit限制
if re.match(r"^select|^with", sql_lower) and not (
re.match(r"^select\s+sql_audit.", sql_lower)
and sql_lower.find(" sql_audit where rownum <= ") != -1
):
sql = f"select sql_audit.* from ({sql.rstrip(';')}) sql_audit where rownum <= {limit_num}"
return sql.strip()

def query(
self,
db_name=None,
Expand Down
36 changes: 0 additions & 36 deletions sql/engines/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1238,42 +1238,6 @@ def test_query_check_IndexError(self):
},
)

def test_filter_sql_with_delimiter(self):
sql = "select * from xx;"
new_engine = OracleEngine(instance=self.ins)
check_result = new_engine.filter_sql(sql=sql, limit_num=100)
self.assertEqual(
check_result,
"select sql_audit.* from (select * from xx) sql_audit where rownum <= 100",
)

def test_filter_sql_with_delimiter_and_where(self):
sql = "select * from xx where id>1;"
new_engine = OracleEngine(instance=self.ins)
check_result = new_engine.filter_sql(sql=sql, limit_num=100)
self.assertEqual(
check_result,
"select sql_audit.* from (select * from xx where id>1) sql_audit where rownum <= 100",
)

def test_filter_sql_without_delimiter(self):
sql = "select * from xx;"
new_engine = OracleEngine(instance=self.ins)
check_result = new_engine.filter_sql(sql=sql, limit_num=100)
self.assertEqual(
check_result,
"select sql_audit.* from (select * from xx) sql_audit where rownum <= 100",
)

def test_filter_sql_with_limit(self):
sql = "select * from xx limit 10;"
new_engine = OracleEngine(instance=self.ins)
check_result = new_engine.filter_sql(sql=sql, limit_num=1)
self.assertEqual(
check_result,
"select sql_audit.* from (select * from xx limit 10) sql_audit where rownum <= 1",
)

def test_query_masking(self):
query_result = ResultSet()
new_engine = OracleEngine(instance=self.ins)
Expand Down

0 comments on commit 54bb3dc

Please sign in to comment.