| import math |
|
|
| def compare_result(cursor, sample_query, sample_result, query_output): |
| |
| if query_output[0:8] == "SQLite:\n": |
| query = query_output[8:] |
| elif query_output[0:8] == "SQLite: ": |
| query = query_output[8:] |
| elif query_output[0:7] == "SQLite:": |
| query = query_output[7:] |
| elif query_output[0:5] == "SQL:\n": |
| query = query_output[5:] |
| elif query_output[0:5] == "SQL: ": |
| query = query_output[5:] |
| elif query_output[0:4] == "SQL:": |
| query = query_output[4:] |
| else: |
| query = query_output |
|
|
| |
| for i in range(len(query)): |
| if query[i] == ";": |
| query = query[:i+1] |
| break |
| |
| |
| try: |
| |
| cursor.execute(query) |
| rows = cursor.fetchall() |
|
|
| |
| query = query.replace(" ", "").replace("\n", "").replace("\t", "") |
| sample_query = sample_query.replace(" ", "").replace("\n", "").replace("\t", "") |
| query_match = (query == sample_query) |
|
|
| |
| if query_match: |
| return True, True, True |
|
|
| |
| if "|" in sample_result or "(" in sample_result: |
| |
| |
| if "(" in sample_result: |
| sample_result = sample_result.replace("(", "").replace(")", "") |
| result_list = sample_result.split(",") |
| else: |
| result_list = sample_result.split("|") |
|
|
| |
| for i in range(len(result_list)): |
| result_list[i] = str(result_list[i]).strip() |
| |
| |
| result = False |
| for row in rows: |
| for r in row: |
| for res in result_list: |
| try: |
| if math.isclose(float(r), float(res), abs_tol=0.5): |
| return True, query_match, True |
| except: |
| if str(r) in res or res in str(r): |
| return True, query_match, True |
| |
| |
| if len(rows) == 1: |
| for r in rows[0]: |
| if r == str(len(result_list)): |
| return True, query_match, True |
| |
| return True, query_match, result |
| |
| else: |
| |
| result = False |
| |
| for row in rows: |
| for r in row: |
| |
| if str(r) in str(sample_result): |
| try: |
| if math.isclose(float(r), float(sample_result), abs_tol=0.5): |
| return True, query_match, True |
| except: |
| return True, query_match, True |
| |
| try: |
| if math.isclose(float(r), float(sample_result), abs_tol=0.5): |
| return True, query_match, True |
| except: |
| pass |
|
|
| |
| try: |
| if len(rows) > 1 and len(rows) == int(sample_result): |
| return True, query_match, True |
| if len(rows[0]) > 1 and rows[0][1] is not None and len(rows[0]) == int(sample_result): |
| return True, query_match, True |
| except: |
| pass |
|
|
| |
| return True, query_match, result |
| except: |
| return False, False, False |