From 61f493e010296736a2d784488f20db230450418e Mon Sep 17 00:00:00 2001 From: tonyhu214 <45055121+tonyhu214@users.noreply.github.com> Date: Mon, 28 Aug 2023 11:03:47 +0800 Subject: [PATCH] fix #2252 (#2266) * fixed #2252 fix #2252 * Update oracle.py * Update oracle.py * Update oracle.py * Update sql_utils.py * Update oracle.py fix #2262 * Update oracle.py * Update oracle.py * Update sql_utils.py * Update sql_utils.py * Update sql_utils.py * Update oracle.py * Update oracle.py * Update oracle.py * Update oracle.py --- sql/engines/oracle.py | 21 +++++++++++---------- sql/utils/sql_utils.py | 1 - 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/sql/engines/oracle.py b/sql/engines/oracle.py index 6f25bbe71b..96c2bd29d5 100644 --- a/sql/engines/oracle.py +++ b/sql/engines/oracle.py @@ -590,10 +590,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}, - ) + conn.current_schema = db_name if re.match(r"^explain", sql, re.I): sql = sql else: @@ -669,10 +666,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}, - ) + conn.current_schema = db_name sql = sql.rstrip(";") # 支持oralce查询SQL执行计划语句 if re.match(r"^explain", sql, re.I): @@ -869,7 +863,10 @@ def execute_check(self, db_name=None, sql="", close_conn=True): ) else: object_name_list.add(object_name) - if result_set["rows"] > 1000: + if ( + result_set.get("rows", None) + and result_set["rows"] > 1000 + ): result = ReviewResult( id=line, errlevel=1, @@ -898,7 +895,10 @@ def execute_check(self, db_name=None, sql="", close_conn=True): execute_time=0, ) else: - if result_set["rows"] > 1000: + if ( + result_set.get("rows", None) + and result_set["rows"] > 1000 + ): result = ReviewResult( id=line, errlevel=1, @@ -1095,6 +1095,7 @@ def execute_workflow(self, workflow, close_conn=True): try: conn = self.get_connection() cursor = conn.cursor() + conn.current_schema = workflow.db_name # 获取执行工单时间,用于备份SQL的日志挖掘起始时间 cursor.execute(f"alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss'") cursor.execute(f"select sysdate from dual") diff --git a/sql/utils/sql_utils.py b/sql/utils/sql_utils.py index 85ae80bedc..d7eb0a19cd 100644 --- a/sql/utils/sql_utils.py +++ b/sql/utils/sql_utils.py @@ -368,7 +368,6 @@ def get_exec_sqlitem_list(reviewResult, db_name): :return: """ list = [] - list.append(SqlItem(statement=f' ALTER SESSION SET CURRENT_SCHEMA = "{db_name}" ')) for item in reviewResult: list.append(