diff --git a/工具v3/database_tools_2.py b/工具v3/database_tools_2.py index 80a25f92..91f1b003 100644 --- a/工具v3/database_tools_2.py +++ b/工具v3/database_tools_2.py @@ -973,7 +973,10 @@ def MatchConditioninMariaDB(condition_list): "genre": ('problems','genre'), "ans": ('problems','ans'), "solution": ('problems','solution'), - "remark": ('remarks','remark_content') + "remark": ('remarks','remark_content'), + "same": ('same','ID','SAME_ID'), + "related": ('related','ID','RELATED_ID'), + "usages": ('usages','date','classname','diff') } mydb = connect(hostname = "wwylss.synology.me", port = "13306", username="root", pwd="Wwy@0018705", db = "tikutest") mycursor = mydb.cursor() @@ -982,9 +985,27 @@ def MatchConditioninMariaDB(condition_list): for field,reverse,regexp in condition_list: if not field in ["same","related","usages"]: table,column = corr_dict[field] - sql = f"SELECT ID FROM {table} WHERE {'NOT' if reverse else ''} {column} REGEXP '{regexp};" + sql = f"SELECT ID FROM {table} WHERE {column} REGEXP '{regexp}';" mycursor.execute(sql) newmatch = set([u[0] for u in mycursor.fetchall()]) + elif field in ["same","related"]: + table,col0,col1 = corr_dict[field] + sql1 = f"SELECT {col1} FROM {table} WHERE {col0} REGEXP '{regexp}';" + mycursor.execute(sql1) + newmatch = set([u[0] for u in mycursor.fetchall()]) + sql2 = f"SELECT {col0} FROM {table} WHERE {col1} REGEXP '{regexp}';" + mycursor.execute(sql2) + newmatch = newmatch | set([u[0] for u in mycursor.fetchall()]) + elif field == "usages": + table,cols = corr_dict[field][0],corr_dict[field][1:] + newmatch = set([]) + for i in range(len(cols)): + sql = f"SELECT ID FROM {table} WHERE {cols[i]} REGEXP '{regexp}';" + mycursor.execute(sql) + newmatch = newmatch | set([u[0] for u in mycursor.fetchall()]) + if reverse: + match = match - newmatch + else: match = match & newmatch mydb.close() return match