From 01c386b7dcd306e6ea2e57d9d27e3a16de0926ce Mon Sep 17 00:00:00 2001 From: tonyhu214 <45055121+tonyhu214@users.noreply.github.com> Date: Thu, 24 Aug 2023 13:52:59 +0800 Subject: [PATCH 01/15] fixed #2252 fix #2252 --- sql/engines/oracle.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/sql/engines/oracle.py b/sql/engines/oracle.py index 6f25bbe71b..35d6f1bc67 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.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): From 85a39b4dc6d3e60adf6f4983d422757e02aa3495 Mon Sep 17 00:00:00 2001 From: tonyhu214 <45055121+tonyhu214@users.noreply.github.com> Date: Fri, 25 Aug 2023 01:28:36 +0800 Subject: [PATCH 02/15] Update oracle.py --- sql/engines/oracle.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/engines/oracle.py b/sql/engines/oracle.py index 35d6f1bc67..072ae7db81 100644 --- a/sql/engines/oracle.py +++ b/sql/engines/oracle.py @@ -590,7 +590,7 @@ def explain_check(self, db_name=None, sql="", close_conn=False): conn = self.get_connection() cursor = conn.cursor() if db_name: - conn.conn.current_schema=db_name + conn.current_schema=db_name if re.match(r"^explain", sql, re.I): sql = sql else: From f2133fff3b6bb1594e454bfdd1ac8293295f41cc Mon Sep 17 00:00:00 2001 From: tonyhu214 <45055121+tonyhu214@users.noreply.github.com> Date: Fri, 25 Aug 2023 01:31:21 +0800 Subject: [PATCH 03/15] Update oracle.py --- sql/engines/oracle.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql/engines/oracle.py b/sql/engines/oracle.py index 072ae7db81..ad59e256c4 100644 --- a/sql/engines/oracle.py +++ b/sql/engines/oracle.py @@ -590,7 +590,7 @@ def explain_check(self, db_name=None, sql="", close_conn=False): conn = self.get_connection() cursor = conn.cursor() if db_name: - conn.current_schema=db_name + conn.current_schema = db_name if re.match(r"^explain", sql, re.I): sql = sql else: @@ -666,7 +666,7 @@ def query( conn = self.get_connection() cursor = conn.cursor() if db_name: - conn.current_schema=db_name + conn.current_schema = db_name sql = sql.rstrip(";") # 支持oralce查询SQL执行计划语句 if re.match(r"^explain", sql, re.I): From 06209265be2f8068f91e3f73473fc70f0f30cde7 Mon Sep 17 00:00:00 2001 From: tonyhu214 <45055121+tonyhu214@users.noreply.github.com> Date: Fri, 25 Aug 2023 01:45:29 +0800 Subject: [PATCH 04/15] Update oracle.py --- sql/engines/oracle.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sql/engines/oracle.py b/sql/engines/oracle.py index ad59e256c4..df5000c887 100644 --- a/sql/engines/oracle.py +++ b/sql/engines/oracle.py @@ -1089,6 +1089,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") From c5cb8f8f27d1d97daf9efe481047d8dacdaa236b Mon Sep 17 00:00:00 2001 From: tonyhu214 <45055121+tonyhu214@users.noreply.github.com> Date: Fri, 25 Aug 2023 01:47:53 +0800 Subject: [PATCH 05/15] Update sql_utils.py --- sql/utils/sql_utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sql/utils/sql_utils.py b/sql/utils/sql_utils.py index 85ae80bedc..0eb02bee9b 100644 --- a/sql/utils/sql_utils.py +++ b/sql/utils/sql_utils.py @@ -368,8 +368,7 @@ 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( SqlItem( From ff58abb1cbc46fdd090d121763e2bd17149607cf Mon Sep 17 00:00:00 2001 From: tonyhu214 <45055121+tonyhu214@users.noreply.github.com> Date: Fri, 25 Aug 2023 02:23:51 +0800 Subject: [PATCH 06/15] Update oracle.py fix #2262 --- sql/engines/oracle.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql/engines/oracle.py b/sql/engines/oracle.py index df5000c887..976bc3f083 100644 --- a/sql/engines/oracle.py +++ b/sql/engines/oracle.py @@ -863,7 +863,7 @@ 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["rows"] is not None and result_set["rows"] > 1000: result = ReviewResult( id=line, errlevel=1, @@ -892,7 +892,7 @@ def execute_check(self, db_name=None, sql="", close_conn=True): execute_time=0, ) else: - if result_set["rows"] > 1000: + if result_set["rows"] is not None and result_set["rows"] > 1000: result = ReviewResult( id=line, errlevel=1, From 989c6537d49c7d6941e359aa64270f784d351bcc Mon Sep 17 00:00:00 2001 From: tonyhu214 <45055121+tonyhu214@users.noreply.github.com> Date: Fri, 25 Aug 2023 02:32:35 +0800 Subject: [PATCH 07/15] Update oracle.py --- sql/engines/oracle.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sql/engines/oracle.py b/sql/engines/oracle.py index 976bc3f083..76125e1deb 100644 --- a/sql/engines/oracle.py +++ b/sql/engines/oracle.py @@ -863,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"] is not None and result_set["rows"] > 1000: + if ( + result_set["rows"] is not None + and result_set["rows"] > 1000 + ): result = ReviewResult( id=line, errlevel=1, @@ -892,7 +895,10 @@ def execute_check(self, db_name=None, sql="", close_conn=True): execute_time=0, ) else: - if result_set["rows"] is not None and result_set["rows"] > 1000: + if ( + result_set["rows"] is not None + and result_set["rows"] > 1000 + ): result = ReviewResult( id=line, errlevel=1, From f6b449f5eb98c5c8e1977e67722bf3d946336c73 Mon Sep 17 00:00:00 2001 From: tonyhu214 <45055121+tonyhu214@users.noreply.github.com> Date: Fri, 25 Aug 2023 02:37:46 +0800 Subject: [PATCH 08/15] Update oracle.py --- sql/engines/oracle.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/engines/oracle.py b/sql/engines/oracle.py index 76125e1deb..0e3a08d594 100644 --- a/sql/engines/oracle.py +++ b/sql/engines/oracle.py @@ -1095,7 +1095,7 @@ def execute_workflow(self, workflow, close_conn=True): try: conn = self.get_connection() cursor = conn.cursor() - conn.current_schema = workflow.db_name + 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") From dfb968eecbe34b1b746cae064a1eadc821a7be90 Mon Sep 17 00:00:00 2001 From: tonyhu214 <45055121+tonyhu214@users.noreply.github.com> Date: Fri, 25 Aug 2023 02:39:25 +0800 Subject: [PATCH 09/15] Update sql_utils.py --- sql/utils/sql_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sql/utils/sql_utils.py b/sql/utils/sql_utils.py index 0eb02bee9b..624f45a40d 100644 --- a/sql/utils/sql_utils.py +++ b/sql/utils/sql_utils.py @@ -368,6 +368,7 @@ def get_exec_sqlitem_list(reviewResult, db_name): :return: """ list = [] + for item in reviewResult: list.append( From cb1307d540cd488282b4dd25f23dbe64ca1c8f97 Mon Sep 17 00:00:00 2001 From: tonyhu214 <45055121+tonyhu214@users.noreply.github.com> Date: Fri, 25 Aug 2023 14:54:14 +0800 Subject: [PATCH 10/15] Update sql_utils.py --- sql/utils/sql_utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sql/utils/sql_utils.py b/sql/utils/sql_utils.py index 624f45a40d..0eb02bee9b 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 = [] - for item in reviewResult: list.append( From a9cf9580501cbc3abd5cb801c70adfa1189470ee Mon Sep 17 00:00:00 2001 From: tonyhu214 <45055121+tonyhu214@users.noreply.github.com> Date: Fri, 25 Aug 2023 14:55:24 +0800 Subject: [PATCH 11/15] Update sql_utils.py --- sql/utils/sql_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/utils/sql_utils.py b/sql/utils/sql_utils.py index 0eb02bee9b..d7eb0a19cd 100644 --- a/sql/utils/sql_utils.py +++ b/sql/utils/sql_utils.py @@ -368,7 +368,7 @@ def get_exec_sqlitem_list(reviewResult, db_name): :return: """ list = [] - + for item in reviewResult: list.append( SqlItem( From 9fc85055fede3be17b2375893ebb8849266207d4 Mon Sep 17 00:00:00 2001 From: tonyhu214 <45055121+tonyhu214@users.noreply.github.com> Date: Fri, 25 Aug 2023 16:32:36 +0800 Subject: [PATCH 12/15] Update oracle.py --- sql/engines/oracle.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql/engines/oracle.py b/sql/engines/oracle.py index 0e3a08d594..535716017d 100644 --- a/sql/engines/oracle.py +++ b/sql/engines/oracle.py @@ -864,7 +864,7 @@ def execute_check(self, db_name=None, sql="", close_conn=True): else: object_name_list.add(object_name) if ( - result_set["rows"] is not None + result_set["rows"] and result_set["rows"] > 1000 ): result = ReviewResult( @@ -896,7 +896,7 @@ def execute_check(self, db_name=None, sql="", close_conn=True): ) else: if ( - result_set["rows"] is not None + result_set["rows"] and result_set["rows"] > 1000 ): result = ReviewResult( From 91cf8133931008a3ea23586ac3534cb7cd1466f0 Mon Sep 17 00:00:00 2001 From: tonyhu214 <45055121+tonyhu214@users.noreply.github.com> Date: Fri, 25 Aug 2023 16:39:22 +0800 Subject: [PATCH 13/15] Update oracle.py From 696e8ec562afed14225fad8827caaeeb9ae2d7dd Mon Sep 17 00:00:00 2001 From: tonyhu214 <45055121+tonyhu214@users.noreply.github.com> Date: Mon, 28 Aug 2023 09:24:53 +0800 Subject: [PATCH 14/15] Update oracle.py --- sql/engines/oracle.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql/engines/oracle.py b/sql/engines/oracle.py index 535716017d..932dd4f592 100644 --- a/sql/engines/oracle.py +++ b/sql/engines/oracle.py @@ -864,7 +864,7 @@ def execute_check(self, db_name=None, sql="", close_conn=True): else: object_name_list.add(object_name) if ( - result_set["rows"] + result_set.get("rows",None) and result_set["rows"] > 1000 ): result = ReviewResult( @@ -896,7 +896,7 @@ def execute_check(self, db_name=None, sql="", close_conn=True): ) else: if ( - result_set["rows"] + result_set.get("rows",None) and result_set["rows"] > 1000 ): result = ReviewResult( From 181276e3a5aa14f451a8d7e84ade8c0fd241e7ae Mon Sep 17 00:00:00 2001 From: tonyhu214 <45055121+tonyhu214@users.noreply.github.com> Date: Mon, 28 Aug 2023 09:26:58 +0800 Subject: [PATCH 15/15] Update oracle.py --- sql/engines/oracle.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql/engines/oracle.py b/sql/engines/oracle.py index 932dd4f592..96c2bd29d5 100644 --- a/sql/engines/oracle.py +++ b/sql/engines/oracle.py @@ -864,7 +864,7 @@ def execute_check(self, db_name=None, sql="", close_conn=True): else: object_name_list.add(object_name) if ( - result_set.get("rows",None) + result_set.get("rows", None) and result_set["rows"] > 1000 ): result = ReviewResult( @@ -896,7 +896,7 @@ def execute_check(self, db_name=None, sql="", close_conn=True): ) else: if ( - result_set.get("rows",None) + result_set.get("rows", None) and result_set["rows"] > 1000 ): result = ReviewResult(