sql-testing-tools 0.2.0__tar.gz → 0.2.2__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: sql_testing_tools
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Description-Content-Type: text/markdown
5
5
  Requires-Dist: sqlparse>=0.5.1
6
6
  Requires-Dist: requests>=2.32.3
@@ -11,10 +11,20 @@ Dynamic: requires-dist
11
11
  A library that normalizes simple SQL queries and compares them first by equality of the normalized string and then using the cosette API.
12
12
 
13
13
 
14
+
14
15
  ### [Beta in Development!]
15
16
  [![Build and Test](https://github.com/ValentinHerrmann/sql_testing_tools/actions/workflows/python-build.yml/badge.svg)](https://github.com/ValentinHerrmann/sql_testing_tools/actions/workflows/python-build.yml)
16
17
  [![Build and Test](https://github.com/ValentinHerrmann/sql_testing_tools/actions/workflows/python-unittests.yml/badge.svg)](https://github.com/ValentinHerrmann/sql_testing_tools/actions/workflows/python-unittests.yml)
17
18
 
19
+ Submit bug reports and features requests at: https://github.com/ValentinHerrmann/sql_testing_tools
20
+
21
+ ### V 0.2.2
22
+ - Support LIKE
23
+ - Support '<=' and '>=' (geq and leq)
24
+
25
+ ### V 0.2.1
26
+ - Support LIMIT
27
+
18
28
  ### V 0.1.9 + 0.2.0
19
29
  - Support ORDER BY
20
30
 
@@ -22,10 +32,9 @@ A library that normalizes simple SQL queries and compares them first by equality
22
32
  - Fixed linebreak problems: Linebreaks are now converted into whitespaces before parsing where tokens
23
33
 
24
34
  ### V 0.1.6 + V 0.1.7
25
- - Fixed import error to ensure imports working in different environemnts
35
+ - Fixed import error to ensure imports working in different environments
26
36
 
27
37
  ### V 0.1.4 + V 0.1.5
28
- - V0.1.5 is just a reupload of V 0.1.4
29
38
  - Chained conditions (with AND,OR and Paranthesises) in WHERE statement
30
39
 
31
40
  ### V 0.1.3
@@ -33,3 +42,4 @@ A library that normalizes simple SQL queries and compares them first by equality
33
42
  - FROM: one or more table from DB; no queries as tables!
34
43
  - WHERE: single conditions; no Paranthesises!
35
44
  - GROUP BY one or more columns
45
+
@@ -1,10 +1,20 @@
1
1
  A library that normalizes simple SQL queries and compares them first by equality of the normalized string and then using the cosette API.
2
2
 
3
3
 
4
+
4
5
  ### [Beta in Development!]
5
6
  [![Build and Test](https://github.com/ValentinHerrmann/sql_testing_tools/actions/workflows/python-build.yml/badge.svg)](https://github.com/ValentinHerrmann/sql_testing_tools/actions/workflows/python-build.yml)
6
7
  [![Build and Test](https://github.com/ValentinHerrmann/sql_testing_tools/actions/workflows/python-unittests.yml/badge.svg)](https://github.com/ValentinHerrmann/sql_testing_tools/actions/workflows/python-unittests.yml)
7
8
 
9
+ Submit bug reports and features requests at: https://github.com/ValentinHerrmann/sql_testing_tools
10
+
11
+ ### V 0.2.2
12
+ - Support LIKE
13
+ - Support '<=' and '>=' (geq and leq)
14
+
15
+ ### V 0.2.1
16
+ - Support LIMIT
17
+
8
18
  ### V 0.1.9 + 0.2.0
9
19
  - Support ORDER BY
10
20
 
@@ -12,14 +22,14 @@ A library that normalizes simple SQL queries and compares them first by equality
12
22
  - Fixed linebreak problems: Linebreaks are now converted into whitespaces before parsing where tokens
13
23
 
14
24
  ### V 0.1.6 + V 0.1.7
15
- - Fixed import error to ensure imports working in different environemnts
25
+ - Fixed import error to ensure imports working in different environments
16
26
 
17
27
  ### V 0.1.4 + V 0.1.5
18
- - V0.1.5 is just a reupload of V 0.1.4
19
28
  - Chained conditions (with AND,OR and Paranthesises) in WHERE statement
20
29
 
21
30
  ### V 0.1.3
22
31
  - SELECT: columns with our without table prefix
23
32
  - FROM: one or more table from DB; no queries as tables!
24
33
  - WHERE: single conditions; no Paranthesises!
25
- - GROUP BY one or more columns
34
+ - GROUP BY one or more columns
35
+
@@ -6,7 +6,7 @@ with open("README.md", "r") as fh:
6
6
 
7
7
  setup(
8
8
  name='sql_testing_tools',
9
- version='0.2.0',
9
+ version='0.2.2',
10
10
  packages=find_packages(),
11
11
  install_requires=[
12
12
  'sqlparse>=0.5.1',
@@ -14,4 +14,4 @@ setup(
14
14
  ],
15
15
  long_description=description,
16
16
  long_description_content_type="text/markdown"
17
- )
17
+ )
@@ -41,7 +41,7 @@ def normalizeSQLQuery(query, baseDict):
41
41
 
42
42
  formatted_query = []
43
43
 
44
- # Second pass to process SELECT, WHERE, GROUP BY, and ORDER BY clauses
44
+ # Second pass to process SELECT, WHERE, GROUP BY, ORDER BY, and LIMIT clauses
45
45
  for token in parsed.tokens:
46
46
  if token.is_whitespace:
47
47
  continue
@@ -53,6 +53,8 @@ def normalizeSQLQuery(query, baseDict):
53
53
  formatted_query.append('GROUP BY')
54
54
  elif token.ttype is Keyword and token.value.upper() == 'ORDER BY':
55
55
  formatted_query.append('ORDER BY')
56
+ elif token.ttype is Keyword and token.value.upper() == 'LIMIT':
57
+ formatted_query.append('LIMIT')
56
58
  elif (isinstance(token, IdentifierList) or isinstance(token, Identifier)) and formatted_query and formatted_query[-1] == 'FROM':
57
59
  formatted_query.append(Tp._from(token, alias_map, baseDict))
58
60
  elif (isinstance(token, IdentifierList) or isinstance(token, Identifier)) and formatted_query and formatted_query[-1] == 'GROUP BY':
@@ -66,6 +68,8 @@ def normalizeSQLQuery(query, baseDict):
66
68
  if isinstance(token, Function):
67
69
  token = IdentifierList([token])
68
70
  formatted_query.append(Tp._select(token, alias_map, baseDict))
71
+ elif formatted_query and formatted_query[-1] == 'LIMIT':
72
+ formatted_query.append(Tp._limit(token))
69
73
  else:
70
74
  formatted_query.append(str(token))
71
75
 
@@ -120,6 +120,10 @@ def _condition(token, alias_map, baseDict: dict):
120
120
  operator.value = "<"
121
121
  elif operator.value == "<":
122
122
  operator.value = ">"
123
+ elif operator.value == ">=":
124
+ operator.value = "<="
125
+ elif operator.value == "<=":
126
+ operator.value = ">="
123
127
  leftLiteral = rightLiteral
124
128
  rightLiteral = True
125
129
  flipAllowed = False
@@ -133,6 +137,10 @@ def _condition(token, alias_map, baseDict: dict):
133
137
  operator = "<"
134
138
  elif operator.value == "<":
135
139
  operator = ">"
140
+ if operator.value == ">=":
141
+ operator = "<="
142
+ elif operator.value == "<=":
143
+ operator = ">="
136
144
 
137
145
  return f"{left if leftLiteral else left.lower()} {operator} {right if rightLiteral else right.lower()}"
138
146
 
@@ -341,29 +349,5 @@ def _where_twoConditionsOnTopLevel(where, alias_map, baseDict: dict, keyword, is
341
349
  return keyword.join(current_condition)
342
350
 
343
351
 
344
-
345
-
346
- # def _where_xx(where, alias_map, baseDict: dict):
347
- # where_tokens = []
348
- # for token in where.tokens:
349
-
350
- # if isinstance(token, Comparison):
351
- # left, operator, right = [t for t in token.tokens if not t.is_whitespace]
352
- # left = _identifier(left, alias_map, baseDict)
353
- # right = _identifier(right, alias_map, baseDict)
354
- # if left.lower() >= right.lower():
355
- # left, right = right, left
356
- # if operator.value == ">":
357
- # operator = "<"
358
- # elif operator.value == "<":
359
- # operator = ">"
360
-
361
- # where_tokens.append(f"{left.lower()} {operator} {right.lower()}")
362
- # elif token.ttype is Keyword:
363
- # where_tokens.append(token.value.upper())
364
- # elif token.is_whitespace or (token.ttype is Keyword and token.value.upper() == "WHERE"):
365
- # continue
366
- # else:
367
- # where_tokens.append(str(token))
368
- # return " ".join(where_tokens)
369
-
352
+ def _limit(limit):
353
+ return str(limit).strip()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: sql_testing_tools
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Description-Content-Type: text/markdown
5
5
  Requires-Dist: sqlparse>=0.5.1
6
6
  Requires-Dist: requests>=2.32.3
@@ -11,10 +11,20 @@ Dynamic: requires-dist
11
11
  A library that normalizes simple SQL queries and compares them first by equality of the normalized string and then using the cosette API.
12
12
 
13
13
 
14
+
14
15
  ### [Beta in Development!]
15
16
  [![Build and Test](https://github.com/ValentinHerrmann/sql_testing_tools/actions/workflows/python-build.yml/badge.svg)](https://github.com/ValentinHerrmann/sql_testing_tools/actions/workflows/python-build.yml)
16
17
  [![Build and Test](https://github.com/ValentinHerrmann/sql_testing_tools/actions/workflows/python-unittests.yml/badge.svg)](https://github.com/ValentinHerrmann/sql_testing_tools/actions/workflows/python-unittests.yml)
17
18
 
19
+ Submit bug reports and features requests at: https://github.com/ValentinHerrmann/sql_testing_tools
20
+
21
+ ### V 0.2.2
22
+ - Support LIKE
23
+ - Support '<=' and '>=' (geq and leq)
24
+
25
+ ### V 0.2.1
26
+ - Support LIMIT
27
+
18
28
  ### V 0.1.9 + 0.2.0
19
29
  - Support ORDER BY
20
30
 
@@ -22,10 +32,9 @@ A library that normalizes simple SQL queries and compares them first by equality
22
32
  - Fixed linebreak problems: Linebreaks are now converted into whitespaces before parsing where tokens
23
33
 
24
34
  ### V 0.1.6 + V 0.1.7
25
- - Fixed import error to ensure imports working in different environemnts
35
+ - Fixed import error to ensure imports working in different environments
26
36
 
27
37
  ### V 0.1.4 + V 0.1.5
28
- - V0.1.5 is just a reupload of V 0.1.4
29
38
  - Chained conditions (with AND,OR and Paranthesises) in WHERE statement
30
39
 
31
40
  ### V 0.1.3
@@ -33,3 +42,4 @@ A library that normalizes simple SQL queries and compares them first by equality
33
42
  - FROM: one or more table from DB; no queries as tables!
34
43
  - WHERE: single conditions; no Paranthesises!
35
44
  - GROUP BY one or more columns
45
+