Skip to content

Commit

Permalink
V 0.2.7: Merge pull request #22 from ValentinHerrmann/fix-unequality-…
Browse files Browse the repository at this point in the history
…check
  • Loading branch information
ValentinHerrmann authored Feb 5, 2025
2 parents 50bb69a + 6ce879e commit 5020c1e
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ res = checkEquality()

### Changelog


##### V 0.2.7
- Normalize String unequality: ...<>..., ...!=..., ...NOT LIKE... --> NOT...LIKE...

##### V 0.2.6
- Fixed bug in checkKeywords: if keyword was present in one query and not in the other, the comparison was not performed correctly.

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name='sql_testing_tools',
version='0.2.6',
version='0.2.7',
packages=find_packages(),
install_requires=[
'sqlparse>=0.5.1',
Expand Down
5 changes: 5 additions & 0 deletions sql_testing_tools/TokenProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ def _condition(token, alias_map, baseDict: dict):
left = _identifier(left, alias_map, baseDict)
right = _identifier(right, alias_map, baseDict)

if operator.value in ("!=", "<>"):
return f"NOT {left} LIKE {right}"
if operator.value in ("NOT LIKE"):
return f"NOT {left} LIKE {right}"

if flipAllowed and left.lower() >= right.lower():
left, right = right, left
if operator.value == ">":
Expand Down
8 changes: 8 additions & 0 deletions sql_testing_tools/tests/NormalizeQuery_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,11 @@ def test_a22_GroupIsolated(self):

if res == "":
self.fail("Different grouping not recognized")

def test_a23_not_equal(self):
nr = '23'
self.helperEqual(nr)

def test_a24_not_equal(self):
nr = '24'
self.helperEqual(nr)
3 changes: 3 additions & 0 deletions sql_testing_tools/tests/v1/a23.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT name, einwohner_m, einwohner_w
FROM Gemeinde
WHERE name != 'München'
3 changes: 3 additions & 0 deletions sql_testing_tools/tests/v1/a24.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT name, einwohner_m, einwohner_w
FROM Gemeinde
WHERE name <> 'München'
3 changes: 3 additions & 0 deletions sql_testing_tools/tests/v2/a23.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT name, einwohner_m, einwohner_w
FROM Gemeinde
WHERE NOT name LIKE 'München'
3 changes: 3 additions & 0 deletions sql_testing_tools/tests/v2/a24.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT name, einwohner_m, einwohner_w
FROM Gemeinde
WHERE name NOT LIKE 'München'

0 comments on commit 5020c1e

Please sign in to comment.