sqlchecker 0.3.1__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.
- sqlchecker/__init__.py +58 -0
- sqlchecker/detectors/__init__.py +103 -0
- sqlchecker/detectors/base.py +44 -0
- sqlchecker/detectors/complications.py +375 -0
- sqlchecker/detectors/logical.py +732 -0
- sqlchecker/detectors/semantic.py +289 -0
- sqlchecker/detectors/syntax.py +1140 -0
- sqlchecker-0.3.1.dist-info/METADATA +153 -0
- sqlchecker-0.3.1.dist-info/RECORD +11 -0
- sqlchecker-0.3.1.dist-info/WHEEL +4 -0
- sqlchecker-0.3.1.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sqlchecker
|
|
3
|
+
Version: 0.3.1
|
|
4
|
+
Summary: This project analyses SQL statements and labels possible errors or complications.
|
|
5
|
+
Project-URL: Repository, https://github.com/DavidePonzini/sqlchecker
|
|
6
|
+
Project-URL: Documentation, https://sqlchecker.readthedocs.io/en/latest/index.html
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/DavidePonzini/sqlchecker/issues
|
|
8
|
+
Author-email: Davide Ponzini <davide.ponzini95@gmail.com>
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Requires-Python: >=3.11
|
|
14
|
+
Requires-Dist: psycopg2
|
|
15
|
+
Requires-Dist: python-dateutil
|
|
16
|
+
Requires-Dist: pyyaml
|
|
17
|
+
Requires-Dist: sqlerrors>=2.0.0
|
|
18
|
+
Requires-Dist: sqlglot
|
|
19
|
+
Requires-Dist: sqlparse
|
|
20
|
+
Requires-Dist: sqlscope>=1.0.16
|
|
21
|
+
Requires-Dist: z3-solver
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# Introduction
|
|
25
|
+
This project analyses SQL statements and labels possible errors or complications.
|
|
26
|
+
|
|
27
|
+
# Credits
|
|
28
|
+
Special thanks to Davide Miggiano and Flavio Venturini for their valuable contributions to the development of this project.
|
|
29
|
+
|
|
30
|
+
# Limitations
|
|
31
|
+
- Fully identified schema names are not supported when specifying column names (e.g. `SELECT schema.table.column [...]`)
|
|
32
|
+
|
|
33
|
+
# SQL Errors TODO List
|
|
34
|
+
## Syntax Errors
|
|
35
|
+
| ID | Category | Name | Description | Base Query | Subquery | CTE |
|
|
36
|
+
| :---: | :-------: | :------------------------------------ | --------------------------------------------------------------------- | :--------: | :------: | :-: |
|
|
37
|
+
| 1 | SYN-1 | Ambiguous database object | Omitting correlation names | ✓ | | |
|
|
38
|
+
| 2 | SYN-1 | Ambiguous database object | Ambiguous column | ✓ | | |
|
|
39
|
+
| 3 | SYN-1 | Ambiguous database object | Ambiguous function | | | |
|
|
40
|
+
| 4 | SYN-2 | Undefined database object | Undefined column | ✓ | ✓ | ✓ |
|
|
41
|
+
| 5 | SYN-2 | Undefined database object | Undefined function | ✓ | ✓ | ✓ |
|
|
42
|
+
| 6 | SYN-2 | Undefined database object | Undefined parameter | ✓ | ✓ | ✓ |
|
|
43
|
+
| 7 | SYN-2 | Undefined database object | Undefined object | ✓ | ✓ | ✓ |
|
|
44
|
+
| 8 | SYN-2 | Undefined database object | Invalid schema name | ✓ | | |
|
|
45
|
+
| 9 | SYN-2 | Undefined database object | Misspellings | ✓ | | |
|
|
46
|
+
| 10 | SYN-2 | Undefined database object | Synonyms | | | |
|
|
47
|
+
| 11 | SYN-2 | Undefined database object | Omitting quotes around character data | ✓ | ✓ | ✓ |
|
|
48
|
+
| 12 | SYN-3 | Data type mismatch | Failure to specify column name twice | | | |
|
|
49
|
+
| 13 | SYN-3 | Data type mismatch | Data type mismatch | ✓ | | |
|
|
50
|
+
| 14 | SYN-4 | Illegal aggregate function placement | Using aggregate function outside SELECT or HAVING | ✓ | ✓ | ✓ |
|
|
51
|
+
| 15 | SYN-4 | Illegal aggregate function placement | Grouping error: aggregate functions cannot be nested | ✓ | ✓ | ✓ |
|
|
52
|
+
| 16 | SYN-5 | Illegal or insufficient grouping | Grouping error: extraneous or omitted grouping column | ✓ | ✓ | ✓ |
|
|
53
|
+
| 17 | SYN-5 | Illegal or insufficient grouping | Strange HAVING: HAVING without GROUP BY | ✓ | ✓ | ✓ |
|
|
54
|
+
| 18 | SYN-6 | Common syntax error | Confusing function with function | | | |
|
|
55
|
+
| 19 | SYN-6 | Common syntax error | Using WHERE twice | ✓ | ✓ | ✓ |
|
|
56
|
+
| 20 | SYN-6 | Common syntax error | Omitting the FROM clause | ✓ | ✓ | ✓ |
|
|
57
|
+
| 21 | SYN-6 | Common syntax error | Comparison with NULL | ✓ | ✓ | ✓ |
|
|
58
|
+
| 22 | SYN-6 | Common syntax error | Omitting the semicolon | ✓ | ✓ | ✓ |
|
|
59
|
+
| 23 | SYN-6 | Common syntax error | Date time field overflow | | | |
|
|
60
|
+
| 24 | SYN-6 | Common syntax error | Duplicate clause | | | |
|
|
61
|
+
| 25 | SYN-6 | Common syntax error | Using an undefined correlation name | | | |
|
|
62
|
+
| 26 | SYN-6 | Common syntax error | Too many columns in subquery | | | |
|
|
63
|
+
| 27 | SYN-6 | Common syntax error | Confusing table names with column names | | | |
|
|
64
|
+
| 28 | SYN-6 | Common syntax error | Restriction in SELECT clause (e.g., SELECT fee > 10) | ✓ | ✓ | ✓ |
|
|
65
|
+
| 29 | SYN-6 | Common syntax error | Projection in WHERE clause (e.g., WHERE firstname, surname) | ✓ | ✓ | ✓ |
|
|
66
|
+
| 30 | SYN-6 | Common syntax error | Confusing the order of keywords (e.g., FROM customer SELECT fee) | ✓ | | |
|
|
67
|
+
| 31 | SYN-6 | Common syntax error | Confusing the logic of keywords (e.g., grouping instead of ordering) | | | |
|
|
68
|
+
| 32 | SYN-6 | Common syntax error | Confusing the syntax of keywords (e.g., LIKE (‘A’, ‘B’)) | ✓ | ✓ | ✓ |
|
|
69
|
+
| 33 | SYN-6 | Common syntax error | Omitting commas | ✓ | ✓ | ✓ |
|
|
70
|
+
| 34 | SYN-6 | Common syntax error | Curly, square or unmatched brackets | ✓ | ✓ | ✓ |
|
|
71
|
+
| 35 | SYN-6 | Common syntax error | IS where not applicable | | | |
|
|
72
|
+
| 36 | SYN-6 | Common syntax error | Nonstandard keywords or standard keywords in wrong context | | | |
|
|
73
|
+
| 37 | SYN-6 | Common syntax error | Nonstandard operators (e.g., &&, \|\| or ==) | ✓ | ✓ | ✓ |
|
|
74
|
+
| 38 | SYN-6 | Common syntax error | Additional semicolon | ✓ | ✓ | ✓ |
|
|
75
|
+
|
|
76
|
+
## Semantic Errors
|
|
77
|
+
| ID | Category | Name | Description | Base Query | Subquery | CTE |
|
|
78
|
+
| :---: | :-------: | :------------------------------------ | --------------------------------------------------------------------- | :--------: | :------: | :-: |
|
|
79
|
+
| 39 | SEM-1 | Inconsistent expression | AND instead of OR (empty result table) | ✓ | | |
|
|
80
|
+
| 40 | SEM-1 | Inconsistent expression | Implied, tautological or inconsistent expression | | | |
|
|
81
|
+
| 41 | SEM-1 | Inconsistent expression | DISTINCT in SUM or AVG | ✓ | ✓ | ✓ |
|
|
82
|
+
| 42 | SEM-1 | Inconsistent expression | DISTINCT that might remove important duplicates | | | |
|
|
83
|
+
| 43 | SEM-1 | Inconsistent expression | Wildcards without LIKE | ✓ | ✓ | ✓ |
|
|
84
|
+
| 44 | SEM-1 | Inconsistent expression | Incorrect wildcard: using _ instead of % or using, e.g., * | ✓ | ✓ | ✓ |
|
|
85
|
+
| 45 | SEM-1 | Inconsistent expression | Mixing a > 0 with IS NOT NULL or empty string with NULL | ✓ | ✓ | ✓ |
|
|
86
|
+
| 46 | SEM-2 | Inconsistent join | NULL in IN/ANY/ALL subquery | | | |
|
|
87
|
+
| 47 | SEM-2 | Inconsistent join | Join on incorrect column (matches impossible) | | | |
|
|
88
|
+
| 48 | SEM-3 | Missing join | Omitting a join | | | |
|
|
89
|
+
| 49 | SEM-4 | Duplicate rows | Many duplicates | | | |
|
|
90
|
+
| 50 | SEM-5 | Redundant column output | Constant column output | ✓ | | |
|
|
91
|
+
| 51 | SEM-5 | Redundant column output | Duplicate column output | ✓ | | |
|
|
92
|
+
|
|
93
|
+
## Logical Errors
|
|
94
|
+
| ID | Category | Name | Description | Base Query | Subquery | CTE |
|
|
95
|
+
| :---: | :-------: | :------------------------------------ | --------------------------------------------------------------------- | :--------: | :------: | :-: |
|
|
96
|
+
| 52 | LOG-1 | Operator error | OR instead of AND | ✓ | ✓ | ✓ |
|
|
97
|
+
| 53 | LOG-1 | Operator error | Extraneous NOT operator | | | |
|
|
98
|
+
| 54 | LOG-1 | Operator error | Missing NOT operator | | | |
|
|
99
|
+
| 55 | LOG-1 | Operator error | Substituting existence negation with <> | | | |
|
|
100
|
+
| 56 | LOG-1 | Operator error | Putting NOT in front of incorrect IN/EXISTS | | | |
|
|
101
|
+
| 57 | LOG-1 | Operator error | Incorrect comparison operator or incorrect value compared | ✓ | ✓ | ✓ |
|
|
102
|
+
| 58 | LOG-2 | Join error | Join on incorrect table | | | |
|
|
103
|
+
| 59 | LOG-2 | Join error | Join when join needs to be omitted | | | |
|
|
104
|
+
| 60 | LOG-2 | Join error | Join on incorrect column (matches possible) | | | |
|
|
105
|
+
| 61 | LOG-2 | Join error | Join with incorrect comparison operator | | | |
|
|
106
|
+
| 62 | LOG-2 | Join error | Missing join | | | |
|
|
107
|
+
| 63 | LOG-3 | Nesting error | Improper nesting of expressions | | | |
|
|
108
|
+
| 64 | LOG-3 | Nesting error | Improper nesting of subqueries | | | |
|
|
109
|
+
| 65 | LOG-4 | Expression error | Extraneous quotes | | | |
|
|
110
|
+
| 66 | LOG-4 | Expression error | Missing expression | ✓ | ✓ | ✓ |
|
|
111
|
+
| 67 | LOG-4 | Expression error | Expression on incorrect column | ✓ | ✓ | ✓ |
|
|
112
|
+
| 68 | LOG-4 | Expression error | Extraneous expression | ✓ | ✓ | ✓ |
|
|
113
|
+
| 69 | LOG-4 | Expression error | Expression in incorrect clause | | | |
|
|
114
|
+
| 70 | LOG-5 | Projection error | Extraneous column in SELECT | ✓ | ✓ | ✓ |
|
|
115
|
+
| 71 | LOG-5 | Projection error | Missing column from SELECT | ✓ | ✓ | ✓ |
|
|
116
|
+
| 72 | LOG-5 | Projection error | Missing DISTINCT from SELECT | | | |
|
|
117
|
+
| 73 | LOG-5 | Projection error | Missing AS from SELECT | | | |
|
|
118
|
+
| 74 | LOG-5 | Projection error | Missing column from ORDER BY clause | ✓ | | |
|
|
119
|
+
| 75 | LOG-5 | Projection error | Incorrect column in ORDER BY clause | ✓ | | |
|
|
120
|
+
| 76 | LOG-5 | Projection error | Extraneous ORDER BY clause | ✓ | | |
|
|
121
|
+
| 77 | LOG-5 | Projection error | Incorrect ordering of rows | ✓ | | |
|
|
122
|
+
| 78 | LOG-6 | Function error | DISTINCT as function parameter where not applicable | | | |
|
|
123
|
+
| 79 | LOG-6 | Function error | Missing DISTINCT from function parameter | | | |
|
|
124
|
+
| 80 | LOG-6 | Function error | Incorrect function | | | |
|
|
125
|
+
| 81 | LOG-6 | Function error | Incorrect column as function parameter | | | |
|
|
126
|
+
|
|
127
|
+
# Complications
|
|
128
|
+
| ID | Category | Name | Description | Base Query | Subquery | CTE |
|
|
129
|
+
| :---: | :-------: | :------------------------------------ | --------------------------------------------------------------------- | :--------: | :------: | :-: |
|
|
130
|
+
| 82 | COM | Complication | Unnecessary complication | | | |
|
|
131
|
+
| 83 | COM | Complication | Unnecessary DISTINCT in SELECT clause | ✓ | ✓ | ✓ |
|
|
132
|
+
| 84 | COM | Complication | Unnecessary join | ✓ | | |
|
|
133
|
+
| 85 | COM | Complication | Unused correlation name | | | |
|
|
134
|
+
| 86 | COM | Complication | Correlation names are always identical | | | |
|
|
135
|
+
| 87 | COM | Complication | Unnecessarily general comparison operator | | | |
|
|
136
|
+
| 88 | COM | Complication | LIKE without wildcards | ✓ | ✓ | ✓ |
|
|
137
|
+
| 89 | COM | Complication | Unnecessarily complicated SELECT in EXISTS subquery | | | |
|
|
138
|
+
| 90 | COM | Complication | IN/EXISTS can be replaced by comparison | | | |
|
|
139
|
+
| 91 | COM | Complication | Unnecessary aggregate function | | | |
|
|
140
|
+
| 92 | COM | Complication | Unnecessary DISTINCT in aggregate function | | | |
|
|
141
|
+
| 93 | COM | Complication | Unnecessary argument of COUNT | | | |
|
|
142
|
+
| 94 | COM | Complication | Unnecessary GROUP BY in EXISTS subquery | | | |
|
|
143
|
+
| 95 | COM | Complication | GROUP BY with singleton groups | | | |
|
|
144
|
+
| 96 | COM | Complication | GROUP BY with only a single group | | | |
|
|
145
|
+
| 97 | COM | Complication | GROUP BY can be replaced with DISTINCT | | | |
|
|
146
|
+
| 98 | COM | Complication | UNION can be replaced by OR | | | |
|
|
147
|
+
| 99 | COM | Complication | Unnecessary column in ORDER BY clause | ✓ | | |
|
|
148
|
+
| 100 | COM | Complication | ORDER BY in subquery | | | |
|
|
149
|
+
| 101 | COM | Complication | Inefficient HAVING | | | |
|
|
150
|
+
| 102 | COM | Complication | Inefficient UNION | | | |
|
|
151
|
+
| 103 | COM | Complication | Condition in the subquery can be moved up | | | |
|
|
152
|
+
| 104 | COM | Complication | Condition on left table in LEFT OUTER JOIN | | | |
|
|
153
|
+
| 105 | COM | Complication | OUTER JOIN can be replaced by INNER JOIN | | | |
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
sqlchecker/__init__.py,sha256=TQ0ubo5g5p2S1vGmKBUsxgUPk_3pwxHdhq5h5KfK2Ck,2416
|
|
2
|
+
sqlchecker/detectors/__init__.py,sha256=Ph2qu8nvrXcEXStp6fpgXcMESeXUS9UckX878sFym_g,3680
|
|
3
|
+
sqlchecker/detectors/base.py,sha256=jpbTlWkvZ5akKbiDeLu65sNt8LKaodEkD15vQQVthsg,1351
|
|
4
|
+
sqlchecker/detectors/complications.py,sha256=mWB7cMqlwUVqEeRg48isyx9LD0UibieXRBHAN2JP3Rw,15999
|
|
5
|
+
sqlchecker/detectors/logical.py,sha256=thoMNoUHjL9D-O0wtf6Bp2ihmKV3T703VZHFXcmPyCI,34197
|
|
6
|
+
sqlchecker/detectors/semantic.py,sha256=iuavPziTV5grlyLpPcn64fll6aJ5ck4uHVH4RkfWoTY,12222
|
|
7
|
+
sqlchecker/detectors/syntax.py,sha256=OwPP4saT_SCrvbzoWyvb_JrdmFDFJ2Mh6JO2mgvrD_E,48456
|
|
8
|
+
sqlchecker-0.3.1.dist-info/METADATA,sha256=I2JkozmhCaxlgQyoNFvfM2n4xTJ0VH1ytQDI07yQgvM,20119
|
|
9
|
+
sqlchecker-0.3.1.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
10
|
+
sqlchecker-0.3.1.dist-info/licenses/LICENSE,sha256=6uZykGj9Y_5PgqXoMMwaGqoZFXVBpzCmitv8Dek1XtQ,1091
|
|
11
|
+
sqlchecker-0.3.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) [2025] [Davide Ponzini, Davide Miggiano]
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|