Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug 2177 2168 #2183

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions sql/engines/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,10 +593,7 @@ def explain_check(self, db_name=None, sql="", close_conn=False):
conn = self.get_connection()
cursor = conn.cursor()
if db_name:
cursor.execute(
f" ALTER SESSION SET CURRENT_SCHEMA = :db_name ",
{"db_name": db_name},
)
cursor.execute(f' ALTER SESSION SET CURRENT_SCHEMA = "{db_name}" ')
if re.match(r"^explain", sql, re.I):
sql = sql
else:
Expand All @@ -609,7 +606,7 @@ def explain_check(self, db_name=None, sql="", close_conn=False):
)
rows = cursor.fetchone()
conn.rollback()
if not rows:
if not rows or not isinstance(rows, list) or not rows[0]:
result["rows"] = 0
else:
result["rows"] = rows[0]
Expand Down Expand Up @@ -672,10 +669,7 @@ def query(
conn = self.get_connection()
cursor = conn.cursor()
if db_name:
cursor.execute(
f" ALTER SESSION SET CURRENT_SCHEMA = :db_name ",
{"db_name": db_name},
)
cursor.execute(f' ALTER SESSION SET CURRENT_SCHEMA = "{db_name}" ')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里是为了防止注入, 请回滚

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果低版本的不支持, 还请麻烦提供其他防止sql注入的手段

sql = sql.rstrip(";")
# 支持oralce查询SQL执行计划语句
if re.match(r"^explain", sql, re.I):
Expand Down
Loading