sql-testing-tools 0.2.8__py3-none-any.whl → 0.2.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sql_testing_tools/Helper.py +2 -2
- sql_testing_tools/TokenProcessing.py +36 -16
- {sql_testing_tools-0.2.8.dist-info → sql_testing_tools-0.2.9.dist-info}/METADATA +7 -3
- sql_testing_tools-0.2.9.dist-info/RECORD +8 -0
- sql_testing_tools-0.2.8.dist-info/RECORD +0 -8
- {sql_testing_tools-0.2.8.dist-info → sql_testing_tools-0.2.9.dist-info}/WHEEL +0 -0
- {sql_testing_tools-0.2.8.dist-info → sql_testing_tools-0.2.9.dist-info}/top_level.txt +0 -0
sql_testing_tools/Helper.py
CHANGED
|
@@ -166,7 +166,7 @@ def checkKeywords(startWord:str, endWords:list):
|
|
|
166
166
|
end = len(sql)
|
|
167
167
|
|
|
168
168
|
submission = str.strip(sql[start:end])
|
|
169
|
-
print("'"+submission+"'")
|
|
169
|
+
#print("'"+submission+"'")
|
|
170
170
|
|
|
171
171
|
start = str.find(sol, startWord)
|
|
172
172
|
end = -1
|
|
@@ -179,7 +179,7 @@ def checkKeywords(startWord:str, endWords:list):
|
|
|
179
179
|
end = len(sol)
|
|
180
180
|
|
|
181
181
|
solution = str.strip(sol[start:end])
|
|
182
|
-
print("'"+solution+"'")
|
|
182
|
+
#print("'"+solution+"'")
|
|
183
183
|
|
|
184
184
|
if submission == solution:
|
|
185
185
|
return ""
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import sqlparse
|
|
2
|
-
from sqlparse.sql import Identifier, IdentifierList, Where, Comparison, Function, Parenthesis
|
|
2
|
+
from sqlparse.sql import Identifier, IdentifierList, Where, Comparison, Function, Parenthesis, Token
|
|
3
3
|
from sqlparse.tokens import Keyword, DML, Name, Wildcard, Whitespace, Newline
|
|
4
4
|
|
|
5
|
-
|
|
6
5
|
try:
|
|
7
6
|
import Helper as He
|
|
8
7
|
except ImportError:
|
|
@@ -115,6 +114,25 @@ def _orderby(orderby_, alias_map, baseDict: dict):
|
|
|
115
114
|
# orderby_tokens.sort()
|
|
116
115
|
return ",".join(orderby_tokens)
|
|
117
116
|
|
|
117
|
+
def replace_not_with_parenthesis(where_tokens):
|
|
118
|
+
new_tokens = []
|
|
119
|
+
i = 0
|
|
120
|
+
while i < len(where_tokens):
|
|
121
|
+
if where_tokens[i].ttype is Keyword and where_tokens[i].value.upper() == "NOT":
|
|
122
|
+
if i + 1 < len(where_tokens):
|
|
123
|
+
not_token = where_tokens[i]
|
|
124
|
+
next_token = where_tokens[i + 1]
|
|
125
|
+
parenthesis = Parenthesis([not_token, Token(Whitespace, ' '), next_token])
|
|
126
|
+
new_tokens.append(parenthesis)
|
|
127
|
+
i += 2 # Skip the next token as it is already added inside the parenthesis
|
|
128
|
+
else:
|
|
129
|
+
new_tokens.append(where_tokens[i])
|
|
130
|
+
i += 1
|
|
131
|
+
else:
|
|
132
|
+
new_tokens.append(where_tokens[i])
|
|
133
|
+
i += 1
|
|
134
|
+
return new_tokens
|
|
135
|
+
|
|
118
136
|
def _condition(token, alias_map, baseDict: dict):
|
|
119
137
|
left, operator, right = [t for t in token.tokens if not t.is_whitespace]
|
|
120
138
|
|
|
@@ -143,11 +161,11 @@ def _condition(token, alias_map, baseDict: dict):
|
|
|
143
161
|
left = _identifier(left, alias_map, baseDict)
|
|
144
162
|
right = _identifier(right, alias_map, baseDict)
|
|
145
163
|
|
|
146
|
-
if operator.value in ("!=", "<>"):
|
|
147
|
-
return f"NOT {left.lower()} LIKE {right}"
|
|
148
|
-
if operator.value
|
|
149
|
-
return f"NOT {left.lower()} LIKE {right}"
|
|
150
|
-
if operator.value
|
|
164
|
+
if operator.value.strip() in ("!=", "<>"):
|
|
165
|
+
return f"(NOT {left.lower()} LIKE {right})"
|
|
166
|
+
if operator.value.lower().strip() == "not like":
|
|
167
|
+
return f"(NOT {left.lower()} LIKE {right})"
|
|
168
|
+
if operator.value.strip() == "=" and "%" not in right and "_" not in right:
|
|
151
169
|
return f"{left.lower()} LIKE {right}"
|
|
152
170
|
|
|
153
171
|
|
|
@@ -163,7 +181,7 @@ def _condition(token, alias_map, baseDict: dict):
|
|
|
163
181
|
elif operator.value == "<=":
|
|
164
182
|
operator = ">="
|
|
165
183
|
|
|
166
|
-
return f"{left if leftLiteral else left.lower()} {operator} {right if rightLiteral else right.lower()}"
|
|
184
|
+
return f"{left if leftLiteral else left.lower()} {operator.value.upper()} {right if rightLiteral else right.lower()}"
|
|
167
185
|
|
|
168
186
|
def is_value(token):
|
|
169
187
|
return token.ttype in (sqlparse.tokens.Token.Literal.Number.Integer,
|
|
@@ -253,11 +271,14 @@ def _where(where, alias_map, baseDict: dict):
|
|
|
253
271
|
|
|
254
272
|
isParanthesis = isinstance(where, Parenthesis)
|
|
255
273
|
|
|
256
|
-
where_tokens = [token for token in where.tokens if (token.ttype is not Whitespace and token.ttype is not Newline)and token.value != "WHERE"]
|
|
274
|
+
where_tokens = [token for token in where.tokens if (token.ttype is not Whitespace and token.ttype is not Newline) and token.value != "WHERE"]
|
|
275
|
+
where_tokens = replace_not_with_parenthesis(where_tokens)
|
|
276
|
+
|
|
277
|
+
# No parentheses in where_string!
|
|
257
278
|
where_string = " ".join([str(token) for token in where_tokens])
|
|
258
279
|
|
|
259
280
|
and_count = where_string.upper().count(" AND ")
|
|
260
|
-
or_count
|
|
281
|
+
or_count = where_string.upper().count(" OR ")
|
|
261
282
|
|
|
262
283
|
# No AND / OR
|
|
263
284
|
if and_count + or_count == 0:
|
|
@@ -332,6 +353,8 @@ def _where_addBracketsAroundAND(where, alias_map, baseDict: dict):
|
|
|
332
353
|
def _where_simpleCondition(where_tokens, alias_map, baseDict: dict):
|
|
333
354
|
cond = []
|
|
334
355
|
for tok in where_tokens:
|
|
356
|
+
if tok.ttype == Keyword and tok.value.upper() == "NOT":
|
|
357
|
+
cond.append("NOT ")
|
|
335
358
|
if isinstance(tok, Comparison):
|
|
336
359
|
cond.append(_condition(tok, alias_map, baseDict))
|
|
337
360
|
elif isinstance(tok, Parenthesis):
|
|
@@ -346,13 +369,10 @@ def _where_sameStrengthKeywords(where_tokens, alias_map, baseDict: dict, keyword
|
|
|
346
369
|
cond = []
|
|
347
370
|
for tok in where_tokens:
|
|
348
371
|
if isinstance(tok, Comparison):
|
|
349
|
-
cond.append(
|
|
372
|
+
cond.append(_where_simpleCondition([tok], alias_map, baseDict))
|
|
350
373
|
elif isinstance(tok, Parenthesis):
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
cond.append(_condition(_tok, alias_map, baseDict))
|
|
354
|
-
elif isinstance(_tok, Parenthesis):
|
|
355
|
-
tok = _tok
|
|
374
|
+
isNot = tok.tokens[0].ttype == Keyword and tok.tokens[0].value.upper() == "NOT"
|
|
375
|
+
cond.append(("(" if isNot else "") + _where(tok, alias_map, baseDict) + (")" if isNot else ""))
|
|
356
376
|
cond.sort()
|
|
357
377
|
return keyword.join(cond)
|
|
358
378
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: sql_testing_tools
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.9
|
|
4
4
|
Description-Content-Type: text/markdown
|
|
5
5
|
Requires-Dist: sqlparse>=0.5.1
|
|
6
6
|
Requires-Dist: requests>=2.32.3
|
|
@@ -136,8 +136,12 @@ res = checkEquality()
|
|
|
136
136
|
|
|
137
137
|
### Changelog
|
|
138
138
|
|
|
139
|
-
##### V 0.2.
|
|
140
|
-
-
|
|
139
|
+
##### V 0.2.9
|
|
140
|
+
- added NOT support
|
|
141
|
+
- improved Parentheses handling
|
|
142
|
+
|
|
143
|
+
##### V 0.2.8
|
|
144
|
+
- ignore case in '=' string comparison and convert to LIKE (if no '%', '_' in String)
|
|
141
145
|
|
|
142
146
|
##### V 0.2.7
|
|
143
147
|
- Normalize String unequality: ...<>..., ...!=..., ...NOT LIKE... --> NOT...LIKE...
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
sql_testing_tools/BaseAccess.py,sha256=VcudaUKwhIF00UxZSYTQAN-6bK6K4Q1zrsSM6VoPF6o,6297
|
|
2
|
+
sql_testing_tools/Helper.py,sha256=C8yfKFNsAWvfGXc4jkeocVvLgtr9XCcOox8sb-yoMZw,8280
|
|
3
|
+
sql_testing_tools/TokenProcessing.py,sha256=mfhDeB-8osAv8qnVoYFw01O112x3OKBaOIGrptuKR9E,14878
|
|
4
|
+
sql_testing_tools/__init__.py,sha256=eihMp9aizQd5Lnegu0y57WcyCinmy4Jvp66e0fiMPU4,49
|
|
5
|
+
sql_testing_tools-0.2.9.dist-info/METADATA,sha256=9YGnTqOlaTJRRWoW3EUG0x3GFt4XwuC3x7yn62hRubU,7285
|
|
6
|
+
sql_testing_tools-0.2.9.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
7
|
+
sql_testing_tools-0.2.9.dist-info/top_level.txt,sha256=qwEkmfJ_lYhIwcLXgfU75m0_JavVbOg96fN2zSatN3E,18
|
|
8
|
+
sql_testing_tools-0.2.9.dist-info/RECORD,,
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
sql_testing_tools/BaseAccess.py,sha256=VcudaUKwhIF00UxZSYTQAN-6bK6K4Q1zrsSM6VoPF6o,6297
|
|
2
|
-
sql_testing_tools/Helper.py,sha256=ZJ5aT-hvRT7LPaaayupk_OyCpChQCwmIX0ip7YAS1Pc,8278
|
|
3
|
-
sql_testing_tools/TokenProcessing.py,sha256=7MwVkWHr0pv50gqt6bbakyzbMXyLss9o-INrkc1BCTc,13899
|
|
4
|
-
sql_testing_tools/__init__.py,sha256=eihMp9aizQd5Lnegu0y57WcyCinmy4Jvp66e0fiMPU4,49
|
|
5
|
-
sql_testing_tools-0.2.8.dist-info/METADATA,sha256=5PutOU07FGx-zXAQDhpPmcnvIrK7cLd_iVbpu44YVHQ,7143
|
|
6
|
-
sql_testing_tools-0.2.8.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
7
|
-
sql_testing_tools-0.2.8.dist-info/top_level.txt,sha256=qwEkmfJ_lYhIwcLXgfU75m0_JavVbOg96fN2zSatN3E,18
|
|
8
|
-
sql_testing_tools-0.2.8.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|