diff --git a/README.md b/README.md index 35276f4..6a0d754 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/setup.py b/setup.py index fc8a8f2..71c1edd 100644 --- a/setup.py +++ b/setup.py @@ -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', diff --git a/sql_testing_tools/TokenProcessing.py b/sql_testing_tools/TokenProcessing.py index b77c61a..3703291 100644 --- a/sql_testing_tools/TokenProcessing.py +++ b/sql_testing_tools/TokenProcessing.py @@ -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 == ">": diff --git a/sql_testing_tools/tests/NormalizeQuery_test.py b/sql_testing_tools/tests/NormalizeQuery_test.py index 625ce1a..b695d9b 100644 --- a/sql_testing_tools/tests/NormalizeQuery_test.py +++ b/sql_testing_tools/tests/NormalizeQuery_test.py @@ -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) diff --git a/sql_testing_tools/tests/v1/a23.sql b/sql_testing_tools/tests/v1/a23.sql new file mode 100644 index 0000000..6a1ae69 --- /dev/null +++ b/sql_testing_tools/tests/v1/a23.sql @@ -0,0 +1,3 @@ +SELECT name, einwohner_m, einwohner_w +FROM Gemeinde +WHERE name != 'München' diff --git a/sql_testing_tools/tests/v1/a24.sql b/sql_testing_tools/tests/v1/a24.sql new file mode 100644 index 0000000..b22b73a --- /dev/null +++ b/sql_testing_tools/tests/v1/a24.sql @@ -0,0 +1,3 @@ +SELECT name, einwohner_m, einwohner_w +FROM Gemeinde +WHERE name <> 'München' diff --git a/sql_testing_tools/tests/v2/a23.sql b/sql_testing_tools/tests/v2/a23.sql new file mode 100644 index 0000000..70f9b5a --- /dev/null +++ b/sql_testing_tools/tests/v2/a23.sql @@ -0,0 +1,3 @@ +SELECT name, einwohner_m, einwohner_w +FROM Gemeinde +WHERE NOT name LIKE 'München' diff --git a/sql_testing_tools/tests/v2/a24.sql b/sql_testing_tools/tests/v2/a24.sql new file mode 100644 index 0000000..9545111 --- /dev/null +++ b/sql_testing_tools/tests/v2/a24.sql @@ -0,0 +1,3 @@ +SELECT name, einwohner_m, einwohner_w +FROM Gemeinde +WHERE name NOT LIKE 'München'