From d2285ab4e907b2063f6d26f905faf16b8411125a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E6=9D=BE=E6=B6=9B?= <48005230+songtao12@users.noreply.github.com> Date: Tue, 28 Feb 2023 15:29:28 +0800 Subject: [PATCH 1/9] =?UTF-8?q?fix:=20=E6=94=AF=E6=8C=81=E4=BD=BF=E7=94=A8?= =?UTF-8?q?create=20or=20replace=E5=88=9B=E5=BB=BA=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E3=80=81=E5=AD=98=E5=82=A8=E8=BF=87=E7=A8=8B=E3=80=81=E8=A7=86?= =?UTF-8?q?=E5=9B=BE=E4=BB=A5=E5=8F=8A=E5=8C=85=E7=AD=89=E8=AF=AD=E5=8F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原来代码只支持使用create创建函数、存储过程、视图以及包,使用create or replace创建时获取不到对象名导致报错,实际运维中上线SQL大多使用create or replace方式,修改后同时支持使用create 和 create or replace两个方式。 --- sql/engines/oracle.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/sql/engines/oracle.py b/sql/engines/oracle.py index 7830adca90..a8e3f88cf7 100644 --- a/sql/engines/oracle.py +++ b/sql/engines/oracle.py @@ -457,25 +457,25 @@ def get_sql_first_object_name(sql=""): object_name = re.match( r"^alter\s+table\s(.+?)\s", sql, re.M | re.IGNORECASE ).group(1) - elif re.match(r"^create\s+function\s", sql, re.M | re.IGNORECASE): + elif re.match(r"^create\s+[or\s]+[replace\s]+function\s", sql, re.M | re.IGNORECASE): object_name = re.match( - r"^create\s+function\s(.+?)(\s|\()", sql, re.M | re.IGNORECASE + r"^create\s+[or\s]+[replace\s]+function\s(.+?)(\s|\()", sql, re.M | re.IGNORECASE ).group(1) - elif re.match(r"^create\s+view\s", sql, re.M | re.IGNORECASE): + elif re.match(r"^create\s+[or\s]+[replace\s]+view\s", sql, re.M | re.IGNORECASE): object_name = re.match( - r"^create\s+view\s(.+?)\s", sql, re.M | re.IGNORECASE + r"^create\s+[or\s]+[replace\s]+view\s(.+?)\s", sql, re.M | re.IGNORECASE ).group(1) - elif re.match(r"^create\s+procedure\s", sql, re.M | re.IGNORECASE): + elif re.match(r"^create\s+[or\s]+[replace\s]+procedure\s", sql, re.M | re.IGNORECASE): object_name = re.match( - r"^create\s+procedure\s(.+?)\s", sql, re.M | re.IGNORECASE + r"^create\s+[or\s]+[replace\s]+procedure\s(.+?)\s", sql, re.M | re.IGNORECASE ).group(1) - elif re.match(r"^create\s+package\s+body", sql, re.M | re.IGNORECASE): + elif re.match(r"^create\s+[or\s]+[replace\s]+package\s+body", sql, re.M | re.IGNORECASE): object_name = re.match( - r"^create\s+package\s+body\s(.+?)\s", sql, re.M | re.IGNORECASE + r"^create\s+[or\s]+[replace\s]+package\s+body\s(.+?)\s", sql, re.M | re.IGNORECASE ).group(1) - elif re.match(r"^create\s+package\s", sql, re.M | re.IGNORECASE): + elif re.match(r"^create\s+[or\s]+[replace\s]+package\s", sql, re.M | re.IGNORECASE): object_name = re.match( - r"^create\s+package\s(.+?)\s", sql, re.M | re.IGNORECASE + r"^create\s+[or\s]+[replace\s]+package\s(.+?)\s", sql, re.M | re.IGNORECASE ).group(1) else: return object_name.strip() From dba64248a53117dc097fcbe09dc6991361e6b002 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E6=9D=BE=E6=B6=9B?= <48005230+songtao12@users.noreply.github.com> Date: Fri, 3 Mar 2023 15:50:38 +0800 Subject: [PATCH 2/9] Update oracle.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix-支持Oracle创建存储过程、函数、包等,使用create or replace方式 --- sql/engines/oracle.py | 70 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 59 insertions(+), 11 deletions(-) diff --git a/sql/engines/oracle.py b/sql/engines/oracle.py index a8e3f88cf7..36278ffc6e 100644 --- a/sql/engines/oracle.py +++ b/sql/engines/oracle.py @@ -457,25 +457,61 @@ def get_sql_first_object_name(sql=""): object_name = re.match( r"^alter\s+table\s(.+?)\s", sql, re.M | re.IGNORECASE ).group(1) - elif re.match(r"^create\s+[or\s]+[replace\s]+function\s", sql, re.M | re.IGNORECASE): + elif re.match(r"^create\s+function\s", sql, re.M | re.IGNORECASE): object_name = re.match( - r"^create\s+[or\s]+[replace\s]+function\s(.+?)(\s|\()", sql, re.M | re.IGNORECASE + r"^create\s+function\s(.+?)(\s|\()", sql, re.M | re.IGNORECASE ).group(1) - elif re.match(r"^create\s+[or\s]+[replace\s]+view\s", sql, re.M | re.IGNORECASE): + elif re.match(r"^create\s+view\s", sql, re.M | re.IGNORECASE): object_name = re.match( - r"^create\s+[or\s]+[replace\s]+view\s(.+?)\s", sql, re.M | re.IGNORECASE + r"^create\s+view\s(.+?)\s", sql, re.M | re.IGNORECASE ).group(1) - elif re.match(r"^create\s+[or\s]+[replace\s]+procedure\s", sql, re.M | re.IGNORECASE): + elif re.match(r"^create\s+procedure\s", sql, re.M | re.IGNORECASE): object_name = re.match( - r"^create\s+[or\s]+[replace\s]+procedure\s(.+?)\s", sql, re.M | re.IGNORECASE + r"^create\s+procedure\s(.+?)\s", sql, re.M | re.IGNORECASE ).group(1) - elif re.match(r"^create\s+[or\s]+[replace\s]+package\s+body", sql, re.M | re.IGNORECASE): + elif re.match(r"^create\s+package\s+body", sql, re.M | re.IGNORECASE): object_name = re.match( - r"^create\s+[or\s]+[replace\s]+package\s+body\s(.+?)\s", sql, re.M | re.IGNORECASE + r"^create\s+package\s+body\s(.+?)\s", sql, re.M | re.IGNORECASE ).group(1) - elif re.match(r"^create\s+[or\s]+[replace\s]+package\s", sql, re.M | re.IGNORECASE): + elif re.match(r"^create\s+package\s", sql, re.M | re.IGNORECASE): object_name = re.match( - r"^create\s+[or\s]+[replace\s]+package\s(.+?)\s", sql, re.M | re.IGNORECASE + r"^create\s+package\s(.+?)\s", sql, re.M | re.IGNORECASE + ).group(1) + elif re.match(r"^create\s+type\s+body", sql, re.M | re.IGNORECASE): + object_name = re.match( + r"^create\s+type\s+body\s(.+?)\s", sql, re.M | re.IGNORECASE + ).group(1) + elif re.match(r"^create\s+type\s", sql, re.M | re.IGNORECASE): + object_name = re.match( + r"^create\s+type\s(.+?)\s", sql, re.M | re.IGNORECASE + ).group(1) + elif re.match(r"^create\s+or\s+replace\s+function\s", sql, re.M | re.IGNORECASE): + object_name = re.match( + r"^create\s+or\s+replace\s+function\s(.+?)(\s|\()", sql, re.M | re.IGNORECASE + ).group(1) + elif re.match(r"^create\s+or\s+replace\s+view\s", sql, re.M | re.IGNORECASE): + object_name = re.match( + r"^create\s+or\s+replace\s+view\s(.+?)(\s|\()", sql, re.M | re.IGNORECASE + ).group(1) + elif re.match(r"^create\s+or\s+replace\s+procedure\s", sql, re.M | re.IGNORECASE): + object_name = re.match( + r"^create\s+or\s+replace\s+procedure\s(.+?)(\s|\()", sql, re.M | re.IGNORECASE + ).group(1) + elif re.match(r"^create\s+or\s+replace\s+package\s+body", sql, re.M | re.IGNORECASE): + object_name = re.match( + r"^create\s+or\s+replace\s+package\s+body\s(.+?)\s", sql, re.M | re.IGNORECASE + ).group(1) + elif re.match(r"^create\s+or\s+replace\s+package\s", sql, re.M | re.IGNORECASE): + object_name = re.match( + r"^create\s+or\s+replace\s+package\s(.+?)(\s|\()", sql, re.M | re.IGNORECASE + ).group(1) + elif re.match(r"^create\s+or\s+replace\s+type\s+body", sql, re.M | re.IGNORECASE): + object_name = re.match( + r"^create\s+or\s+replace\s+type\s+body\s(.+?)\s", sql, re.M | re.IGNORECASE + ).group(1) + elif re.match(r"^create\s+or\s+replace\s+type\s", sql, re.M | re.IGNORECASE): + object_name = re.match( + r"^create\s+or\s+replace\s+type\s(.+?)(\s|\()", sql, re.M | re.IGNORECASE ).group(1) else: return object_name.strip() @@ -966,7 +1002,19 @@ def execute_check(self, db_name=None, sql="", close_conn=True): object_name = object_name.upper() object_name = f"""{schema_name}.{object_name}""" - if ( + if re.match(r"^create\sor\sreplace", sql_lower) and (self.object_name_check(db_name=db_name, + object_name=object_name) or object_name in object_name_list): + result = ReviewResult(id=line, errlevel=1, + stagestatus=f"""{object_name}对象已经存在,请确认是否替换!""", + errormessage=f"""{object_name}对象已经存在,请确认是否替换!""", + sql=sqlitem.statement, + stmt_type=sqlitem.stmt_type, + object_owner=sqlitem.object_owner, + object_type=sqlitem.object_type, + object_name=sqlitem.object_name, + affected_rows=0, + execute_time=0, ) + elif ( self.object_name_check( db_name=db_name, object_name=object_name ) From f5431091b7b180911e59a5e8c6b00c0eb9fcd53c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E6=9D=BE=E6=B6=9B?= <48005230+songtao12@users.noreply.github.com> Date: Wed, 8 Mar 2023 13:59:20 +0800 Subject: [PATCH 3/9] Update oracle.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化使用正则提取SQL语句中 object name 部分的代码逻辑 --- sql/engines/oracle.py | 80 ++++--------------------------------------- 1 file changed, 6 insertions(+), 74 deletions(-) diff --git a/sql/engines/oracle.py b/sql/engines/oracle.py index 36278ffc6e..84aee28ab7 100644 --- a/sql/engines/oracle.py +++ b/sql/engines/oracle.py @@ -437,82 +437,14 @@ def object_name_check(self, db_name=None, object_name=""): def get_sql_first_object_name(sql=""): """获取sql文本中的object_name""" object_name = "" - if re.match(r"^create\s+table\s", sql, re.M | re.IGNORECASE): + if re.match(r"^(create|alter)\s+(table|index|unique\sindex|sequence)\s", sql, re.M | re.IGNORECASE): object_name = re.match( - r"^create\s+table\s(.+?)(\s|\()", sql, re.M | re.IGNORECASE - ).group(1) - elif re.match(r"^create\s+index\s", sql, re.M | re.IGNORECASE): - object_name = re.match( - r"^create\s+index\s(.+?)\s", sql, re.M | re.IGNORECASE - ).group(1) - elif re.match(r"^create\s+unique\s+index\s", sql, re.M | re.IGNORECASE): - object_name = re.match( - r"^create\s+unique\s+index\s(.+?)\s", sql, re.M | re.IGNORECASE - ).group(1) - elif re.match(r"^create\s+sequence\s", sql, re.M | re.IGNORECASE): - object_name = re.match( - r"^create\s+sequence\s(.+?)(\s|$)", sql, re.M | re.IGNORECASE - ).group(1) - elif re.match(r"^alter\s+table\s", sql, re.M | re.IGNORECASE): - object_name = re.match( - r"^alter\s+table\s(.+?)\s", sql, re.M | re.IGNORECASE - ).group(1) - elif re.match(r"^create\s+function\s", sql, re.M | re.IGNORECASE): + r"^(create|alter)\s+(table|index|unique\sindex|sequence)\s+(.+?)(\s|\()", sql, re.M | re.IGNORECASE + ).group(3) + elif re.match(r"^create\s+(or\s+replace\s+)?(function|view|procedure|trigger|package\sbody|package|type\sbody|type)\s", sql, re.M | re.IGNORECASE): object_name = re.match( - r"^create\s+function\s(.+?)(\s|\()", sql, re.M | re.IGNORECASE - ).group(1) - elif re.match(r"^create\s+view\s", sql, re.M | re.IGNORECASE): - object_name = re.match( - r"^create\s+view\s(.+?)\s", sql, re.M | re.IGNORECASE - ).group(1) - elif re.match(r"^create\s+procedure\s", sql, re.M | re.IGNORECASE): - object_name = re.match( - r"^create\s+procedure\s(.+?)\s", sql, re.M | re.IGNORECASE - ).group(1) - elif re.match(r"^create\s+package\s+body", sql, re.M | re.IGNORECASE): - object_name = re.match( - r"^create\s+package\s+body\s(.+?)\s", sql, re.M | re.IGNORECASE - ).group(1) - elif re.match(r"^create\s+package\s", sql, re.M | re.IGNORECASE): - object_name = re.match( - r"^create\s+package\s(.+?)\s", sql, re.M | re.IGNORECASE - ).group(1) - elif re.match(r"^create\s+type\s+body", sql, re.M | re.IGNORECASE): - object_name = re.match( - r"^create\s+type\s+body\s(.+?)\s", sql, re.M | re.IGNORECASE - ).group(1) - elif re.match(r"^create\s+type\s", sql, re.M | re.IGNORECASE): - object_name = re.match( - r"^create\s+type\s(.+?)\s", sql, re.M | re.IGNORECASE - ).group(1) - elif re.match(r"^create\s+or\s+replace\s+function\s", sql, re.M | re.IGNORECASE): - object_name = re.match( - r"^create\s+or\s+replace\s+function\s(.+?)(\s|\()", sql, re.M | re.IGNORECASE - ).group(1) - elif re.match(r"^create\s+or\s+replace\s+view\s", sql, re.M | re.IGNORECASE): - object_name = re.match( - r"^create\s+or\s+replace\s+view\s(.+?)(\s|\()", sql, re.M | re.IGNORECASE - ).group(1) - elif re.match(r"^create\s+or\s+replace\s+procedure\s", sql, re.M | re.IGNORECASE): - object_name = re.match( - r"^create\s+or\s+replace\s+procedure\s(.+?)(\s|\()", sql, re.M | re.IGNORECASE - ).group(1) - elif re.match(r"^create\s+or\s+replace\s+package\s+body", sql, re.M | re.IGNORECASE): - object_name = re.match( - r"^create\s+or\s+replace\s+package\s+body\s(.+?)\s", sql, re.M | re.IGNORECASE - ).group(1) - elif re.match(r"^create\s+or\s+replace\s+package\s", sql, re.M | re.IGNORECASE): - object_name = re.match( - r"^create\s+or\s+replace\s+package\s(.+?)(\s|\()", sql, re.M | re.IGNORECASE - ).group(1) - elif re.match(r"^create\s+or\s+replace\s+type\s+body", sql, re.M | re.IGNORECASE): - object_name = re.match( - r"^create\s+or\s+replace\s+type\s+body\s(.+?)\s", sql, re.M | re.IGNORECASE - ).group(1) - elif re.match(r"^create\s+or\s+replace\s+type\s", sql, re.M | re.IGNORECASE): - object_name = re.match( - r"^create\s+or\s+replace\s+type\s(.+?)(\s|\()", sql, re.M | re.IGNORECASE - ).group(1) + r"^create\s+(or\s+replace\s+)?(function|view|procedure|trigger|package\sbody|package|type\sbody|type)\s+(.+?)(\s|\()", sql, re.M | re.IGNORECASE + ).group(3) else: return object_name.strip() return object_name.strip() From f57042b3630bfafd3a2f1ee86df1f854fe334e02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E6=9D=BE=E6=B6=9B?= <48005230+songtao12@users.noreply.github.com> Date: Wed, 8 Mar 2023 18:35:46 -0800 Subject: [PATCH 4/9] Update oracle.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化获取object name部分代码 --- sql/engines/oracle.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/sql/engines/oracle.py b/sql/engines/oracle.py index 84aee28ab7..29e4bdb929 100644 --- a/sql/engines/oracle.py +++ b/sql/engines/oracle.py @@ -437,17 +437,25 @@ def object_name_check(self, db_name=None, object_name=""): def get_sql_first_object_name(sql=""): """获取sql文本中的object_name""" object_name = "" - if re.match(r"^(create|alter)\s+(table|index|unique\sindex|sequence)\s", sql, re.M | re.IGNORECASE): + # 匹配表、索引、序列 + pattern=r"^(create|alter)\s+(table|index|unique\sindex|sequence)\s" + groups = re.match(pattern, sql, re.M | re.IGNORECASE) + + if groups: object_name = re.match( r"^(create|alter)\s+(table|index|unique\sindex|sequence)\s+(.+?)(\s|\()", sql, re.M | re.IGNORECASE - ).group(3) - elif re.match(r"^create\s+(or\s+replace\s+)?(function|view|procedure|trigger|package\sbody|package|type\sbody|type)\s", sql, re.M | re.IGNORECASE): + ).group(3).strip() + return object_name + + # 匹配创建或者替换SQL块 + pattern=r"^create\s+(or\s+replace\s+)?(function|view|procedure|trigger|package\sbody|package|type\sbody|type)\s" + groups = re.match(pattern, sql, re.M | re.IGNORECASE) + + if groups: object_name = re.match( r"^create\s+(or\s+replace\s+)?(function|view|procedure|trigger|package\sbody|package|type\sbody|type)\s+(.+?)(\s|\()", sql, re.M | re.IGNORECASE - ).group(3) - else: - return object_name.strip() - return object_name.strip() + ).group(3).strip() + return object_name @staticmethod def check_create_index_table(sql="", object_name_list=None, db_name=""): From 68b96531d336f7ea0f9cd3a0d92ccc62e330bfd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E6=9D=BE=E6=B6=9B?= <48005230+songtao12@users.noreply.github.com> Date: Thu, 9 Mar 2023 22:50:28 -0800 Subject: [PATCH 5/9] Update oracle.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化代码 --- sql/engines/oracle.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sql/engines/oracle.py b/sql/engines/oracle.py index 29e4bdb929..958d5da040 100644 --- a/sql/engines/oracle.py +++ b/sql/engines/oracle.py @@ -453,10 +453,11 @@ def get_sql_first_object_name(sql=""): if groups: object_name = re.match( - r"^create\s+(or\s+replace\s+)?(function|view|procedure|trigger|package\sbody|package|type\sbody|type)\s+(.+?)(\s|\()", sql, re.M | re.IGNORECASE + r"^create\s+(or\s+replace\s+)?(function|view|procedure|trigger|package\sbody|package|type\sbody|type)\s+(.+?)(\s|\()", + sql, re.M | re.IGNORECASE ).group(3).strip() return object_name - + return object_name @staticmethod def check_create_index_table(sql="", object_name_list=None, db_name=""): schema_name = '"' + db_name + '"' From ad83507745e2c1599c5a21f046dd3629c617d624 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E6=9D=BE=E6=B6=9B?= <48005230+songtao12@users.noreply.github.com> Date: Thu, 9 Mar 2023 23:32:36 -0800 Subject: [PATCH 6/9] Update oracle.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复lint报错(代码规范) --- sql/engines/oracle.py | 65 ++++++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 23 deletions(-) diff --git a/sql/engines/oracle.py b/sql/engines/oracle.py index 958d5da040..fb0f494d49 100644 --- a/sql/engines/oracle.py +++ b/sql/engines/oracle.py @@ -438,26 +438,38 @@ def get_sql_first_object_name(sql=""): """获取sql文本中的object_name""" object_name = "" # 匹配表、索引、序列 - pattern=r"^(create|alter)\s+(table|index|unique\sindex|sequence)\s" - groups = re.match(pattern, sql, re.M | re.IGNORECASE) + pattern = r"^(create|alter)\s+(table|index|unique\sindex|sequence)\s" + groups = re.match(pattern, sql, re.M | re.IGNORECASE) if groups: - object_name = re.match( - r"^(create|alter)\s+(table|index|unique\sindex|sequence)\s+(.+?)(\s|\()", sql, re.M | re.IGNORECASE - ).group(3).strip() + object_name = ( + re.match( + r"^(create|alter)\s+(table|index|unique\sindex|sequence)\s+(.+?)(\s|\()", + sql, + re.M | re.IGNORECASE, + ) + .group(3) + .strip() + ) return object_name # 匹配创建或者替换SQL块 - pattern=r"^create\s+(or\s+replace\s+)?(function|view|procedure|trigger|package\sbody|package|type\sbody|type)\s" - groups = re.match(pattern, sql, re.M | re.IGNORECASE) + pattern = r"^create\s+(or\s+replace\s+)?(function|view|procedure|trigger|package\sbody|package|type\sbody|type)\s" + groups = re.match(pattern, sql, re.M | re.IGNORECASE) if groups: - object_name = re.match( - r"^create\s+(or\s+replace\s+)?(function|view|procedure|trigger|package\sbody|package|type\sbody|type)\s+(.+?)(\s|\()", - sql, re.M | re.IGNORECASE - ).group(3).strip() + object_name = ( + re.match( + r"^create\s+(or\s+replace\s+)?(function|view|procedure|trigger|package\sbody|package|type\sbody|type)\s+(.+?)(\s|\()", + sql, + re.M | re.IGNORECASE, + ) + .group(3) + .strip() + ) return object_name return object_name + @staticmethod def check_create_index_table(sql="", object_name_list=None, db_name=""): schema_name = '"' + db_name + '"' @@ -943,18 +955,25 @@ def execute_check(self, db_name=None, sql="", close_conn=True): object_name = object_name.upper() object_name = f"""{schema_name}.{object_name}""" - if re.match(r"^create\sor\sreplace", sql_lower) and (self.object_name_check(db_name=db_name, - object_name=object_name) or object_name in object_name_list): - result = ReviewResult(id=line, errlevel=1, - stagestatus=f"""{object_name}对象已经存在,请确认是否替换!""", - errormessage=f"""{object_name}对象已经存在,请确认是否替换!""", - sql=sqlitem.statement, - stmt_type=sqlitem.stmt_type, - object_owner=sqlitem.object_owner, - object_type=sqlitem.object_type, - object_name=sqlitem.object_name, - affected_rows=0, - execute_time=0, ) + if re.match(r"^create\sor\sreplace", sql_lower) and ( + self.object_name_check( + db_name=db_name, object_name=object_name + ) + or object_name in object_name_list + ): + result = ReviewResult( + id=line, + errlevel=1, + stagestatus=f"""{object_name}对象已经存在,请确认是否替换!""", + errormessage=f"""{object_name}对象已经存在,请确认是否替换!""", + sql=sqlitem.statement, + stmt_type=sqlitem.stmt_type, + object_owner=sqlitem.object_owner, + object_type=sqlitem.object_type, + object_name=sqlitem.object_name, + affected_rows=0, + execute_time=0, + ) elif ( self.object_name_check( db_name=db_name, object_name=object_name From 8fabb37b4b8fb35514f4f327814b8a4b0ea73b39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E6=9D=BE=E6=B6=9B?= <48005230+songtao12@users.noreply.github.com> Date: Thu, 9 Mar 2023 23:40:50 -0800 Subject: [PATCH 7/9] Update oracle.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 处理lint报错(代码规范) --- 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 fb0f494d49..ca761a8d53 100644 --- a/sql/engines/oracle.py +++ b/sql/engines/oracle.py @@ -469,7 +469,7 @@ def get_sql_first_object_name(sql=""): ) return object_name return object_name - + @staticmethod def check_create_index_table(sql="", object_name_list=None, db_name=""): schema_name = '"' + db_name + '"' From ac2d23542327863a80811a677c200dee866dc4c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E6=9D=BE=E6=B6=9B?= <48005230+songtao12@users.noreply.github.com> Date: Thu, 9 Mar 2023 23:58:46 -0800 Subject: [PATCH 8/9] Update oracle.py --- sql/engines/oracle.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/sql/engines/oracle.py b/sql/engines/oracle.py index ca761a8d53..e0b0a2db23 100644 --- a/sql/engines/oracle.py +++ b/sql/engines/oracle.py @@ -442,15 +442,14 @@ def get_sql_first_object_name(sql=""): groups = re.match(pattern, sql, re.M | re.IGNORECASE) if groups: - object_name = ( + object_name = re.match( r"^(create|alter)\s+(table|index|unique\sindex|sequence)\s+(.+?)(\s|\()", sql, re.M | re.IGNORECASE, - ) - .group(3) - .strip() - ) + ).group(3).strip() + return object_name + else: return object_name # 匹配创建或者替换SQL块 @@ -458,17 +457,15 @@ def get_sql_first_object_name(sql=""): groups = re.match(pattern, sql, re.M | re.IGNORECASE) if groups: - object_name = ( + object_name = re.match( r"^create\s+(or\s+replace\s+)?(function|view|procedure|trigger|package\sbody|package|type\sbody|type)\s+(.+?)(\s|\()", sql, re.M | re.IGNORECASE, - ) - .group(3) - .strip() - ) + ).group(3).strip() + return object_name + else: return object_name - return object_name @staticmethod def check_create_index_table(sql="", object_name_list=None, db_name=""): From a42d005cb5407543d90fb7f6b967ba6ef66f8ce0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E6=9D=BE=E6=B6=9B?= <48005230+songtao12@users.noreply.github.com> Date: Fri, 10 Mar 2023 00:41:06 -0800 Subject: [PATCH 9/9] Update oracle.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 调整代码规范 --- sql/engines/oracle.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/sql/engines/oracle.py b/sql/engines/oracle.py index e0b0a2db23..ca761a8d53 100644 --- a/sql/engines/oracle.py +++ b/sql/engines/oracle.py @@ -442,14 +442,15 @@ def get_sql_first_object_name(sql=""): groups = re.match(pattern, sql, re.M | re.IGNORECASE) if groups: - object_name = + object_name = ( re.match( r"^(create|alter)\s+(table|index|unique\sindex|sequence)\s+(.+?)(\s|\()", sql, re.M | re.IGNORECASE, - ).group(3).strip() - return object_name - else: + ) + .group(3) + .strip() + ) return object_name # 匹配创建或者替换SQL块 @@ -457,15 +458,17 @@ def get_sql_first_object_name(sql=""): groups = re.match(pattern, sql, re.M | re.IGNORECASE) if groups: - object_name = + object_name = ( re.match( r"^create\s+(or\s+replace\s+)?(function|view|procedure|trigger|package\sbody|package|type\sbody|type)\s+(.+?)(\s|\()", sql, re.M | re.IGNORECASE, - ).group(3).strip() - return object_name - else: + ) + .group(3) + .strip() + ) return object_name + return object_name @staticmethod def check_create_index_table(sql="", object_name_list=None, db_name=""):