sql-error-categorizer 0.1.0__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.
Files changed (72) hide show
  1. sql_error_categorizer-0.1.0/.gitignore +177 -0
  2. sql_error_categorizer-0.1.0/.readthedocs.yaml +35 -0
  3. sql_error_categorizer-0.1.0/LICENSE +21 -0
  4. sql_error_categorizer-0.1.0/Makefile +57 -0
  5. sql_error_categorizer-0.1.0/PKG-INFO +149 -0
  6. sql_error_categorizer-0.1.0/README.md +130 -0
  7. sql_error_categorizer-0.1.0/docs/Makefile +20 -0
  8. sql_error_categorizer-0.1.0/docs/conf.py +38 -0
  9. sql_error_categorizer-0.1.0/docs/index.rst +175 -0
  10. sql_error_categorizer-0.1.0/docs/make.bat +35 -0
  11. sql_error_categorizer-0.1.0/docs/requirements.txt +1 -0
  12. sql_error_categorizer-0.1.0/pyproject.toml +29 -0
  13. sql_error_categorizer-0.1.0/q_cte.sql +22 -0
  14. sql_error_categorizer-0.1.0/q_q.sql +10 -0
  15. sql_error_categorizer-0.1.0/q_s.sql +1 -0
  16. sql_error_categorizer-0.1.0/requirements.txt +16 -0
  17. sql_error_categorizer-0.1.0/src/sql_error_categorizer/__init__.py +56 -0
  18. sql_error_categorizer-0.1.0/src/sql_error_categorizer/catalog/__init__.py +73 -0
  19. sql_error_categorizer-0.1.0/src/sql_error_categorizer/catalog/catalog.py +328 -0
  20. sql_error_categorizer-0.1.0/src/sql_error_categorizer/catalog/queries.py +60 -0
  21. sql_error_categorizer-0.1.0/src/sql_error_categorizer/detectors/__init__.py +88 -0
  22. sql_error_categorizer-0.1.0/src/sql_error_categorizer/detectors/base.py +39 -0
  23. sql_error_categorizer-0.1.0/src/sql_error_categorizer/detectors/complications.py +393 -0
  24. sql_error_categorizer-0.1.0/src/sql_error_categorizer/detectors/logical.py +708 -0
  25. sql_error_categorizer-0.1.0/src/sql_error_categorizer/detectors/semantic.py +493 -0
  26. sql_error_categorizer-0.1.0/src/sql_error_categorizer/detectors/syntax.py +1278 -0
  27. sql_error_categorizer-0.1.0/src/sql_error_categorizer/query/__init__.py +4 -0
  28. sql_error_categorizer-0.1.0/src/sql_error_categorizer/query/extractors.py +134 -0
  29. sql_error_categorizer-0.1.0/src/sql_error_categorizer/query/query.py +98 -0
  30. sql_error_categorizer-0.1.0/src/sql_error_categorizer/query/set_operations/__init__.py +150 -0
  31. sql_error_categorizer-0.1.0/src/sql_error_categorizer/query/set_operations/binary_set_operation.py +89 -0
  32. sql_error_categorizer-0.1.0/src/sql_error_categorizer/query/set_operations/select.py +361 -0
  33. sql_error_categorizer-0.1.0/src/sql_error_categorizer/query/set_operations/set_operation.py +45 -0
  34. sql_error_categorizer-0.1.0/src/sql_error_categorizer/query/smt.py +206 -0
  35. sql_error_categorizer-0.1.0/src/sql_error_categorizer/query/tokenized_sql.py +68 -0
  36. sql_error_categorizer-0.1.0/src/sql_error_categorizer/query/typechecking.py +242 -0
  37. sql_error_categorizer-0.1.0/src/sql_error_categorizer/query/util.py +27 -0
  38. sql_error_categorizer-0.1.0/src/sql_error_categorizer/sql_errors.py +112 -0
  39. sql_error_categorizer-0.1.0/src/sql_error_categorizer/util.py +101 -0
  40. sql_error_categorizer-0.1.0/test_detector.py +28 -0
  41. sql_error_categorizer-0.1.0/tests/__init__.py +45 -0
  42. sql_error_categorizer-0.1.0/tests/datasets/cat_miedema.json +362 -0
  43. sql_error_categorizer-0.1.0/tests/detectors/1_syn/test_02_ambiguous_column.py +43 -0
  44. sql_error_categorizer-0.1.0/tests/detectors/1_syn/test_04_undefined_column.py +33 -0
  45. sql_error_categorizer-0.1.0/tests/detectors/1_syn/test_05_undefined_function.py +54 -0
  46. sql_error_categorizer-0.1.0/tests/detectors/1_syn/test_06_undefined_functions.py +73 -0
  47. sql_error_categorizer-0.1.0/tests/detectors/1_syn/test_07_undefined_tables.py +61 -0
  48. sql_error_categorizer-0.1.0/tests/detectors/1_syn/test_08_invalid_schema_names.py +19 -0
  49. sql_error_categorizer-0.1.0/tests/detectors/1_syn/test_09_misspellings.py +109 -0
  50. sql_error_categorizer-0.1.0/tests/detectors/1_syn/test_14_aggregate_function_outside_select_or_having.py +65 -0
  51. sql_error_categorizer-0.1.0/tests/detectors/1_syn/test_15_nested_aggregate_functions.py +61 -0
  52. sql_error_categorizer-0.1.0/tests/detectors/1_syn/test_16_extraneous_omitted_grouping_column.py +55 -0
  53. sql_error_categorizer-0.1.0/tests/detectors/1_syn/test_17_having_without_group_by.py +81 -0
  54. sql_error_categorizer-0.1.0/tests/detectors/1_syn/test_19_using_where_twice.py +60 -0
  55. sql_error_categorizer-0.1.0/tests/detectors/1_syn/test_20_missing_from.py +77 -0
  56. sql_error_categorizer-0.1.0/tests/detectors/1_syn/test_21_comparison_with_null.py +44 -0
  57. sql_error_categorizer-0.1.0/tests/detectors/1_syn/test_22_38_additional_omitted_semicolons.py +56 -0
  58. sql_error_categorizer-0.1.0/tests/detectors/1_syn/test_24_duplicate_clause.py +61 -0
  59. sql_error_categorizer-0.1.0/tests/detectors/1_syn/test_26_too_many_columns_in_subquery.py +71 -0
  60. sql_error_categorizer-0.1.0/tests/detectors/1_syn/test_30_keywords_order.py +37 -0
  61. sql_error_categorizer-0.1.0/tests/detectors/1_syn/test_34_curly_square_or_unmatched_brackets.py +60 -0
  62. sql_error_categorizer-0.1.0/tests/detectors/1_syn/test_37_nonstandard_operators.py +29 -0
  63. sql_error_categorizer-0.1.0/tests/detectors/2_sem/test_40_tautological_inconsistent_expressions.py +136 -0
  64. sql_error_categorizer-0.1.0/tests/detectors/2_sem/test_41_distinct_sum_avg.py +77 -0
  65. sql_error_categorizer-0.1.0/tests/detectors/2_sem/test_43_wildcards_without_like.py +104 -0
  66. sql_error_categorizer-0.1.0/tests/detectors/2_sem/test_44_incorrect_wildcards.py +144 -0
  67. sql_error_categorizer-0.1.0/tests/detectors/4_com/test_88_like_no_wildcards.py +32 -0
  68. sql_error_categorizer-0.1.0/tests/query/conftest.py +15 -0
  69. sql_error_categorizer-0.1.0/tests/query/test_extractors.py +54 -0
  70. sql_error_categorizer-0.1.0/tests/query/test_query.py +28 -0
  71. sql_error_categorizer-0.1.0/tests/query/test_typechecking.py +38 -0
  72. sql_error_categorizer-0.1.0/tests/test_query.py +173 -0
@@ -0,0 +1,177 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+
110
+ # pdm
111
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112
+ #pdm.lock
113
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114
+ # in version control.
115
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116
+ .pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121
+ __pypackages__/
122
+
123
+ # Celery stuff
124
+ celerybeat-schedule
125
+ celerybeat.pid
126
+
127
+ # SageMath parsed files
128
+ *.sage.py
129
+
130
+ # Environments
131
+ .env
132
+ .venv
133
+ env/
134
+ venv/
135
+ ENV/
136
+ env.bak/
137
+ venv.bak/
138
+
139
+ # Spyder project settings
140
+ .spyderproject
141
+ .spyproject
142
+
143
+ # Rope project settings
144
+ .ropeproject
145
+
146
+ # mkdocs documentation
147
+ /site
148
+
149
+ # mypy
150
+ .mypy_cache/
151
+ .dmypy.json
152
+ dmypy.json
153
+
154
+ # Pyre type checker
155
+ .pyre/
156
+
157
+ # pytype static type analyzer
158
+ .pytype/
159
+
160
+ # Cython debug symbols
161
+ cython_debug/
162
+
163
+ # PyCharm
164
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
165
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
167
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
168
+ #.idea/
169
+
170
+ # Ruff stuff:
171
+ .ruff_cache/
172
+
173
+ # PyPI configuration file
174
+ .pypirc
175
+
176
+ # VS Code
177
+ .vscode/
@@ -0,0 +1,35 @@
1
+ # Read the Docs configuration file for Sphinx projects
2
+ # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
3
+
4
+ # Required
5
+ version: 2
6
+
7
+ # Set the OS, Python version and other tools you might need
8
+ build:
9
+ os: ubuntu-22.04
10
+ tools:
11
+ python: "3.11"
12
+ # You can also specify other tool versions:
13
+ # nodejs: "20"
14
+ # rust: "1.70"
15
+ # golang: "1.20"
16
+
17
+ # Build documentation in the "docs/" directory with Sphinx
18
+ sphinx:
19
+ configuration: docs/conf.py
20
+ # You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs
21
+ # builder: "dirhtml"
22
+ # Fail on all warnings to avoid broken references
23
+ # fail_on_warning: true
24
+
25
+ # Optionally build your docs in additional formats such as PDF and ePub
26
+ # formats:
27
+ # - pdf
28
+ # - epub
29
+
30
+ # Optional but recommended, declare the Python requirements required
31
+ # to build your documentation
32
+ # See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
33
+ python:
34
+ install:
35
+ - requirements: docs/requirements.txt
@@ -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.
@@ -0,0 +1,57 @@
1
+ ########## Makefile start ##########
2
+ # Type: PyPi
3
+ # Author: Davide Ponzini
4
+
5
+ NAME=sql_error_categorizer
6
+ VENV=./venv
7
+ REQUIREMENTS=requirements.txt
8
+
9
+ ifeq ($(OS),Windows_NT)
10
+ VENV_BIN=$(VENV)/Scripts
11
+ else
12
+ VENV_BIN=$(VENV)/bin
13
+ endif
14
+
15
+ .PHONY: install build uninstall documentation test upload download clean
16
+
17
+ $(VENV):
18
+ python -m venv --clear $(VENV)
19
+ touch -a $(REQUIREMENTS)
20
+ $(VENV_BIN)/python -m pip install --upgrade -r $(REQUIREMENTS)
21
+
22
+ $(VENV)_upgrade: $(VENV)
23
+ $(VENV_BIN)/python -m pip install --upgrade -r $(REQUIREMENTS)
24
+
25
+
26
+ install: uninstall build
27
+ $(VENV_BIN)/python -m pip install ./dist/*.whl
28
+
29
+ build: $(VENV)
30
+ rm -rf dist/
31
+ $(VENV_BIN)/python -m build
32
+
33
+ uninstall: $(VENV)
34
+ $(VENV_BIN)/python -m pip uninstall -y $(NAME)
35
+
36
+ documentation:
37
+ make html -C docs/
38
+
39
+ test: install
40
+ $(VENV_BIN)/python -m pytest
41
+
42
+ coverage: install
43
+ $(VENV_BIN)/python -m pytest --cov=$(NAME) --cov-report=html:tests/htmlcov
44
+ open tests/htmlcov/index.html
45
+
46
+ upload: test documentation
47
+ $(VENV_BIN)/python -m pip install --upgrade twine
48
+ $(VENV_BIN)/python -m twine upload --verbose dist/*
49
+
50
+ download: uninstall
51
+ $(VENV_BIN)/python -m pip install $(NAME)
52
+
53
+ clean:
54
+ find . -type d -name '__pycache__' -print0 | xargs -0 rm -r || true
55
+ rm -rf dist docs/_build .pytest_cache .coverage tests/htmlcov
56
+
57
+ ########## Makefile end ##########
@@ -0,0 +1,149 @@
1
+ Metadata-Version: 2.4
2
+ Name: sql_error_categorizer
3
+ Version: 0.1.0
4
+ Summary: This project analyses SQL statements and labels possible errors or complications.
5
+ Project-URL: Repository, https://github.com/DavidePonzini/sql_error_categorizer
6
+ Project-URL: Documentation, https://sql_error_categorizer.readthedocs.io/en/latest/index.html
7
+ Project-URL: Bug Tracker, https://github.com/DavidePonzini/sql_error_categorizer/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: pyyaml
16
+ Requires-Dist: sqlglot
17
+ Requires-Dist: sqlparse
18
+ Description-Content-Type: text/markdown
19
+
20
+ # Introduction
21
+ This project analyses SQL statements and labels possible errors or complications.
22
+
23
+ # Credits
24
+ Special thanks to Davide Miggiano for implementing most of the categorizers.
25
+
26
+ # Limitations
27
+ - Fully identified schema names are not supported when specifying column names (e.g. `SELECT schema.table.column [...]`)
28
+
29
+ # SQL Errors TODO List
30
+ ## Syntax Errors
31
+ | ID | Category | Name | Description | Base Query | Subquery | CTE |
32
+ | :---: | :-------: | :------------------------------------ | --------------------------------------------------------------------- | :--------: | :------: | :-: |
33
+ | 1 | SYN-1 | Ambiguous database object | Omitting correlation names | ✓ | | |
34
+ | 2 | SYN-1 | Ambiguous database object | Ambiguous column | ✓ | | |
35
+ | 3 | SYN-1 | Ambiguous database object | Ambiguous function | | | |
36
+ | 4 | SYN-2 | Undefined database object | Undefined column | ✓ | ✓ | ✓ |
37
+ | 5 | SYN-2 | Undefined database object | Undefined function | ✓ | ✓ | ✓ |
38
+ | 6 | SYN-2 | Undefined database object | Undefined parameter | ✓ | ✓ | ✓ |
39
+ | 7 | SYN-2 | Undefined database object | Undefined object | ✓ | ✓ | ✓ |
40
+ | 8 | SYN-2 | Undefined database object | Invalid schema name | ✓ | | |
41
+ | 9 | SYN-2 | Undefined database object | Misspellings | ✓ | | |
42
+ | 10 | SYN-2 | Undefined database object | Synonyms | | | |
43
+ | 11 | SYN-2 | Undefined database object | Omitting quotes around character data | ✓ | ✓ | ✓ |
44
+ | 12 | SYN-3 | Data type mismatch | Failure to specify column name twice | | | |
45
+ | 13 | SYN-3 | Data type mismatch | Data type mismatch | ✓ | | |
46
+ | 14 | SYN-4 | Illegal aggregate function placement | Using aggregate function outside SELECT or HAVING | ✓ | ✓ | ✓ |
47
+ | 15 | SYN-4 | Illegal aggregate function placement | Grouping error: aggregate functions cannot be nested | ✓ | ✓ | ✓ |
48
+ | 16 | SYN-5 | Illegal or insufficient grouping | Grouping error: extraneous or omitted grouping column | ✓ | ✓ | ✓ |
49
+ | 17 | SYN-5 | Illegal or insufficient grouping | Strange HAVING: HAVING without GROUP BY | ✓ | ✓ | ✓ |
50
+ | 18 | SYN-6 | Common syntax error | Confusing function with function | | | |
51
+ | 19 | SYN-6 | Common syntax error | Using WHERE twice | ✓ | ✓ | ✓ |
52
+ | 20 | SYN-6 | Common syntax error | Omitting the FROM clause | ✓ | ✓ | ✓ |
53
+ | 21 | SYN-6 | Common syntax error | Comparison with NULL | ✓ | ✓ | ✓ |
54
+ | 22 | SYN-6 | Common syntax error | Omitting the semicolon | ✓ | ✓ | ✓ |
55
+ | 23 | SYN-6 | Common syntax error | Date time field overflow | | | |
56
+ | 24 | SYN-6 | Common syntax error | Duplicate clause | | | |
57
+ | 25 | SYN-6 | Common syntax error | Using an undefined correlation name | | | |
58
+ | 26 | SYN-6 | Common syntax error | Too many columns in subquery | | | |
59
+ | 27 | SYN-6 | Common syntax error | Confusing table names with column names | | | |
60
+ | 28 | SYN-6 | Common syntax error | Restriction in SELECT clause (e.g., SELECT fee > 10) | ✓ | ✓ | ✓ |
61
+ | 29 | SYN-6 | Common syntax error | Projection in WHERE clause (e.g., WHERE firstname, surname) | ✓ | ✓ | ✓ |
62
+ | 30 | SYN-6 | Common syntax error | Confusing the order of keywords (e.g., FROM customer SELECT fee) | ✓ | | |
63
+ | 31 | SYN-6 | Common syntax error | Confusing the logic of keywords (e.g., grouping instead of ordering) | | | |
64
+ | 32 | SYN-6 | Common syntax error | Confusing the syntax of keywords (e.g., LIKE (‘A’, ‘B’)) | ✓ | ✓ | ✓ |
65
+ | 33 | SYN-6 | Common syntax error | Omitting commas | ✓ | ✓ | ✓ |
66
+ | 34 | SYN-6 | Common syntax error | Curly, square or unmatched brackets | ✓ | ✓ | ✓ |
67
+ | 35 | SYN-6 | Common syntax error | IS where not applicable | | | |
68
+ | 36 | SYN-6 | Common syntax error | Nonstandard keywords or standard keywords in wrong context | | | |
69
+ | 37 | SYN-6 | Common syntax error | Nonstandard operators (e.g., &&, \|\| or ==) | ✓ | ✓ | ✓ |
70
+ | 38 | SYN-6 | Common syntax error | Additional semicolon | ✓ | ✓ | ✓ |
71
+
72
+ ## Semantic Errors
73
+ | ID | Category | Name | Description | Base Query | Subquery | CTE |
74
+ | :---: | :-------: | :------------------------------------ | --------------------------------------------------------------------- | :--------: | :------: | :-: |
75
+ | 39 | SEM-1 | Inconsistent expression | AND instead of OR (empty result table) | ✓ | | |
76
+ | 40 | SEM-1 | Inconsistent expression | Implied, tautological or inconsistent expression | | | |
77
+ | 41 | SEM-1 | Inconsistent expression | DISTINCT in SUM or AVG | ✓ | ✓ | ✓ |
78
+ | 42 | SEM-1 | Inconsistent expression | DISTINCT that might remove important duplicates | | | |
79
+ | 43 | SEM-1 | Inconsistent expression | Wildcards without LIKE | ✓ | ✓ | ✓ |
80
+ | 44 | SEM-1 | Inconsistent expression | Incorrect wildcard: using _ instead of % or using, e.g., * | ✓ | ✓ | ✓ |
81
+ | 45 | SEM-1 | Inconsistent expression | Mixing a > 0 with IS NOT NULL or empty string with NULL | ✓ | ✓ | ✓ |
82
+ | 46 | SEM-2 | Inconsistent join | NULL in IN/ANY/ALL subquery | | | |
83
+ | 47 | SEM-2 | Inconsistent join | Join on incorrect column (matches impossible) | | | |
84
+ | 48 | SEM-3 | Missing join | Omitting a join | | | |
85
+ | 49 | SEM-4 | Duplicate rows | Many duplicates | | | |
86
+ | 50 | SEM-5 | Redundant column output | Constant column output | ✓ | | |
87
+ | 51 | SEM-5 | Redundant column output | Duplicate column output | ✓ | | |
88
+
89
+ ## Logical Errors
90
+ | ID | Category | Name | Description | Base Query | Subquery | CTE |
91
+ | :---: | :-------: | :------------------------------------ | --------------------------------------------------------------------- | :--------: | :------: | :-: |
92
+ | 52 | LOG-1 | Operator error | OR instead of AND | ✓ | ✓ | ✓ |
93
+ | 53 | LOG-1 | Operator error | Extraneous NOT operator | | | |
94
+ | 54 | LOG-1 | Operator error | Missing NOT operator | | | |
95
+ | 55 | LOG-1 | Operator error | Substituting existence negation with <> | | | |
96
+ | 56 | LOG-1 | Operator error | Putting NOT in front of incorrect IN/EXISTS | | | |
97
+ | 57 | LOG-1 | Operator error | Incorrect comparison operator or incorrect value compared | ✓ | ✓ | ✓ |
98
+ | 58 | LOG-2 | Join error | Join on incorrect table | | | |
99
+ | 59 | LOG-2 | Join error | Join when join needs to be omitted | | | |
100
+ | 60 | LOG-2 | Join error | Join on incorrect column (matches possible) | | | |
101
+ | 61 | LOG-2 | Join error | Join with incorrect comparison operator | | | |
102
+ | 62 | LOG-2 | Join error | Missing join | | | |
103
+ | 63 | LOG-3 | Nesting error | Improper nesting of expressions | | | |
104
+ | 64 | LOG-3 | Nesting error | Improper nesting of subqueries | | | |
105
+ | 65 | LOG-4 | Expression error | Extraneous quotes | | | |
106
+ | 66 | LOG-4 | Expression error | Missing expression | ✓ | ✓ | ✓ |
107
+ | 67 | LOG-4 | Expression error | Expression on incorrect column | ✓ | ✓ | ✓ |
108
+ | 68 | LOG-4 | Expression error | Extraneous expression | ✓ | ✓ | ✓ |
109
+ | 69 | LOG-4 | Expression error | Expression in incorrect clause | | | |
110
+ | 70 | LOG-5 | Projection error | Extraneous column in SELECT | ✓ | ✓ | ✓ |
111
+ | 71 | LOG-5 | Projection error | Missing column from SELECT | ✓ | ✓ | ✓ |
112
+ | 72 | LOG-5 | Projection error | Missing DISTINCT from SELECT | | | |
113
+ | 73 | LOG-5 | Projection error | Missing AS from SELECT | | | |
114
+ | 74 | LOG-5 | Projection error | Missing column from ORDER BY clause | ✓ | | |
115
+ | 75 | LOG-5 | Projection error | Incorrect column in ORDER BY clause | ✓ | | |
116
+ | 76 | LOG-5 | Projection error | Extraneous ORDER BY clause | ✓ | | |
117
+ | 77 | LOG-5 | Projection error | Incorrect ordering of rows | ✓ | | |
118
+ | 78 | LOG-6 | Function error | DISTINCT as function parameter where not applicable | | | |
119
+ | 79 | LOG-6 | Function error | Missing DISTINCT from function parameter | | | |
120
+ | 80 | LOG-6 | Function error | Incorrect function | | | |
121
+ | 81 | LOG-6 | Function error | Incorrect column as function parameter | | | |
122
+
123
+ # Complications
124
+ | ID | Category | Name | Description | Base Query | Subquery | CTE |
125
+ | :---: | :-------: | :------------------------------------ | --------------------------------------------------------------------- | :--------: | :------: | :-: |
126
+ | 82 | COM | Complication | Unnecessary complication | | | |
127
+ | 83 | COM | Complication | Unnecessary DISTINCT in SELECT clause | ✓ | ✓ | ✓ |
128
+ | 84 | COM | Complication | Unnecessary join | ✓ | | |
129
+ | 85 | COM | Complication | Unused correlation name | | | |
130
+ | 86 | COM | Complication | Correlation names are always identical | | | |
131
+ | 87 | COM | Complication | Unnecessarily general comparison operator | | | |
132
+ | 88 | COM | Complication | LIKE without wildcards | ✓ | ✓ | ✓ |
133
+ | 89 | COM | Complication | Unnecessarily complicated SELECT in EXISTS subquery | | | |
134
+ | 90 | COM | Complication | IN/EXISTS can be replaced by comparison | | | |
135
+ | 91 | COM | Complication | Unnecessary aggregate function | | | |
136
+ | 92 | COM | Complication | Unnecessary DISTINCT in aggregate function | | | |
137
+ | 93 | COM | Complication | Unnecessary argument of COUNT | | | |
138
+ | 94 | COM | Complication | Unnecessary GROUP BY in EXISTS subquery | | | |
139
+ | 95 | COM | Complication | GROUP BY with singleton groups | | | |
140
+ | 96 | COM | Complication | GROUP BY with only a single group | | | |
141
+ | 97 | COM | Complication | GROUP BY can be replaced with DISTINCT | | | |
142
+ | 98 | COM | Complication | UNION can be replaced by OR | | | |
143
+ | 99 | COM | Complication | Unnecessary column in ORDER BY clause | ✓ | | |
144
+ | 100 | COM | Complication | ORDER BY in subquery | | | |
145
+ | 101 | COM | Complication | Inefficient HAVING | | | |
146
+ | 102 | COM | Complication | Inefficient UNION | | | |
147
+ | 103 | COM | Complication | Condition in the subquery can be moved up | | | |
148
+ | 104 | COM | Complication | Condition on left table in LEFT OUTER JOIN | | | |
149
+ | 105 | COM | Complication | OUTER JOIN can be replaced by INNER JOIN | | | |
@@ -0,0 +1,130 @@
1
+ # Introduction
2
+ This project analyses SQL statements and labels possible errors or complications.
3
+
4
+ # Credits
5
+ Special thanks to Davide Miggiano for implementing most of the categorizers.
6
+
7
+ # Limitations
8
+ - Fully identified schema names are not supported when specifying column names (e.g. `SELECT schema.table.column [...]`)
9
+
10
+ # SQL Errors TODO List
11
+ ## Syntax Errors
12
+ | ID | Category | Name | Description | Base Query | Subquery | CTE |
13
+ | :---: | :-------: | :------------------------------------ | --------------------------------------------------------------------- | :--------: | :------: | :-: |
14
+ | 1 | SYN-1 | Ambiguous database object | Omitting correlation names | ✓ | | |
15
+ | 2 | SYN-1 | Ambiguous database object | Ambiguous column | ✓ | | |
16
+ | 3 | SYN-1 | Ambiguous database object | Ambiguous function | | | |
17
+ | 4 | SYN-2 | Undefined database object | Undefined column | ✓ | ✓ | ✓ |
18
+ | 5 | SYN-2 | Undefined database object | Undefined function | ✓ | ✓ | ✓ |
19
+ | 6 | SYN-2 | Undefined database object | Undefined parameter | ✓ | ✓ | ✓ |
20
+ | 7 | SYN-2 | Undefined database object | Undefined object | ✓ | ✓ | ✓ |
21
+ | 8 | SYN-2 | Undefined database object | Invalid schema name | ✓ | | |
22
+ | 9 | SYN-2 | Undefined database object | Misspellings | ✓ | | |
23
+ | 10 | SYN-2 | Undefined database object | Synonyms | | | |
24
+ | 11 | SYN-2 | Undefined database object | Omitting quotes around character data | ✓ | ✓ | ✓ |
25
+ | 12 | SYN-3 | Data type mismatch | Failure to specify column name twice | | | |
26
+ | 13 | SYN-3 | Data type mismatch | Data type mismatch | ✓ | | |
27
+ | 14 | SYN-4 | Illegal aggregate function placement | Using aggregate function outside SELECT or HAVING | ✓ | ✓ | ✓ |
28
+ | 15 | SYN-4 | Illegal aggregate function placement | Grouping error: aggregate functions cannot be nested | ✓ | ✓ | ✓ |
29
+ | 16 | SYN-5 | Illegal or insufficient grouping | Grouping error: extraneous or omitted grouping column | ✓ | ✓ | ✓ |
30
+ | 17 | SYN-5 | Illegal or insufficient grouping | Strange HAVING: HAVING without GROUP BY | ✓ | ✓ | ✓ |
31
+ | 18 | SYN-6 | Common syntax error | Confusing function with function | | | |
32
+ | 19 | SYN-6 | Common syntax error | Using WHERE twice | ✓ | ✓ | ✓ |
33
+ | 20 | SYN-6 | Common syntax error | Omitting the FROM clause | ✓ | ✓ | ✓ |
34
+ | 21 | SYN-6 | Common syntax error | Comparison with NULL | ✓ | ✓ | ✓ |
35
+ | 22 | SYN-6 | Common syntax error | Omitting the semicolon | ✓ | ✓ | ✓ |
36
+ | 23 | SYN-6 | Common syntax error | Date time field overflow | | | |
37
+ | 24 | SYN-6 | Common syntax error | Duplicate clause | | | |
38
+ | 25 | SYN-6 | Common syntax error | Using an undefined correlation name | | | |
39
+ | 26 | SYN-6 | Common syntax error | Too many columns in subquery | | | |
40
+ | 27 | SYN-6 | Common syntax error | Confusing table names with column names | | | |
41
+ | 28 | SYN-6 | Common syntax error | Restriction in SELECT clause (e.g., SELECT fee > 10) | ✓ | ✓ | ✓ |
42
+ | 29 | SYN-6 | Common syntax error | Projection in WHERE clause (e.g., WHERE firstname, surname) | ✓ | ✓ | ✓ |
43
+ | 30 | SYN-6 | Common syntax error | Confusing the order of keywords (e.g., FROM customer SELECT fee) | ✓ | | |
44
+ | 31 | SYN-6 | Common syntax error | Confusing the logic of keywords (e.g., grouping instead of ordering) | | | |
45
+ | 32 | SYN-6 | Common syntax error | Confusing the syntax of keywords (e.g., LIKE (‘A’, ‘B’)) | ✓ | ✓ | ✓ |
46
+ | 33 | SYN-6 | Common syntax error | Omitting commas | ✓ | ✓ | ✓ |
47
+ | 34 | SYN-6 | Common syntax error | Curly, square or unmatched brackets | ✓ | ✓ | ✓ |
48
+ | 35 | SYN-6 | Common syntax error | IS where not applicable | | | |
49
+ | 36 | SYN-6 | Common syntax error | Nonstandard keywords or standard keywords in wrong context | | | |
50
+ | 37 | SYN-6 | Common syntax error | Nonstandard operators (e.g., &&, \|\| or ==) | ✓ | ✓ | ✓ |
51
+ | 38 | SYN-6 | Common syntax error | Additional semicolon | ✓ | ✓ | ✓ |
52
+
53
+ ## Semantic Errors
54
+ | ID | Category | Name | Description | Base Query | Subquery | CTE |
55
+ | :---: | :-------: | :------------------------------------ | --------------------------------------------------------------------- | :--------: | :------: | :-: |
56
+ | 39 | SEM-1 | Inconsistent expression | AND instead of OR (empty result table) | ✓ | | |
57
+ | 40 | SEM-1 | Inconsistent expression | Implied, tautological or inconsistent expression | | | |
58
+ | 41 | SEM-1 | Inconsistent expression | DISTINCT in SUM or AVG | ✓ | ✓ | ✓ |
59
+ | 42 | SEM-1 | Inconsistent expression | DISTINCT that might remove important duplicates | | | |
60
+ | 43 | SEM-1 | Inconsistent expression | Wildcards without LIKE | ✓ | ✓ | ✓ |
61
+ | 44 | SEM-1 | Inconsistent expression | Incorrect wildcard: using _ instead of % or using, e.g., * | ✓ | ✓ | ✓ |
62
+ | 45 | SEM-1 | Inconsistent expression | Mixing a > 0 with IS NOT NULL or empty string with NULL | ✓ | ✓ | ✓ |
63
+ | 46 | SEM-2 | Inconsistent join | NULL in IN/ANY/ALL subquery | | | |
64
+ | 47 | SEM-2 | Inconsistent join | Join on incorrect column (matches impossible) | | | |
65
+ | 48 | SEM-3 | Missing join | Omitting a join | | | |
66
+ | 49 | SEM-4 | Duplicate rows | Many duplicates | | | |
67
+ | 50 | SEM-5 | Redundant column output | Constant column output | ✓ | | |
68
+ | 51 | SEM-5 | Redundant column output | Duplicate column output | ✓ | | |
69
+
70
+ ## Logical Errors
71
+ | ID | Category | Name | Description | Base Query | Subquery | CTE |
72
+ | :---: | :-------: | :------------------------------------ | --------------------------------------------------------------------- | :--------: | :------: | :-: |
73
+ | 52 | LOG-1 | Operator error | OR instead of AND | ✓ | ✓ | ✓ |
74
+ | 53 | LOG-1 | Operator error | Extraneous NOT operator | | | |
75
+ | 54 | LOG-1 | Operator error | Missing NOT operator | | | |
76
+ | 55 | LOG-1 | Operator error | Substituting existence negation with <> | | | |
77
+ | 56 | LOG-1 | Operator error | Putting NOT in front of incorrect IN/EXISTS | | | |
78
+ | 57 | LOG-1 | Operator error | Incorrect comparison operator or incorrect value compared | ✓ | ✓ | ✓ |
79
+ | 58 | LOG-2 | Join error | Join on incorrect table | | | |
80
+ | 59 | LOG-2 | Join error | Join when join needs to be omitted | | | |
81
+ | 60 | LOG-2 | Join error | Join on incorrect column (matches possible) | | | |
82
+ | 61 | LOG-2 | Join error | Join with incorrect comparison operator | | | |
83
+ | 62 | LOG-2 | Join error | Missing join | | | |
84
+ | 63 | LOG-3 | Nesting error | Improper nesting of expressions | | | |
85
+ | 64 | LOG-3 | Nesting error | Improper nesting of subqueries | | | |
86
+ | 65 | LOG-4 | Expression error | Extraneous quotes | | | |
87
+ | 66 | LOG-4 | Expression error | Missing expression | ✓ | ✓ | ✓ |
88
+ | 67 | LOG-4 | Expression error | Expression on incorrect column | ✓ | ✓ | ✓ |
89
+ | 68 | LOG-4 | Expression error | Extraneous expression | ✓ | ✓ | ✓ |
90
+ | 69 | LOG-4 | Expression error | Expression in incorrect clause | | | |
91
+ | 70 | LOG-5 | Projection error | Extraneous column in SELECT | ✓ | ✓ | ✓ |
92
+ | 71 | LOG-5 | Projection error | Missing column from SELECT | ✓ | ✓ | ✓ |
93
+ | 72 | LOG-5 | Projection error | Missing DISTINCT from SELECT | | | |
94
+ | 73 | LOG-5 | Projection error | Missing AS from SELECT | | | |
95
+ | 74 | LOG-5 | Projection error | Missing column from ORDER BY clause | ✓ | | |
96
+ | 75 | LOG-5 | Projection error | Incorrect column in ORDER BY clause | ✓ | | |
97
+ | 76 | LOG-5 | Projection error | Extraneous ORDER BY clause | ✓ | | |
98
+ | 77 | LOG-5 | Projection error | Incorrect ordering of rows | ✓ | | |
99
+ | 78 | LOG-6 | Function error | DISTINCT as function parameter where not applicable | | | |
100
+ | 79 | LOG-6 | Function error | Missing DISTINCT from function parameter | | | |
101
+ | 80 | LOG-6 | Function error | Incorrect function | | | |
102
+ | 81 | LOG-6 | Function error | Incorrect column as function parameter | | | |
103
+
104
+ # Complications
105
+ | ID | Category | Name | Description | Base Query | Subquery | CTE |
106
+ | :---: | :-------: | :------------------------------------ | --------------------------------------------------------------------- | :--------: | :------: | :-: |
107
+ | 82 | COM | Complication | Unnecessary complication | | | |
108
+ | 83 | COM | Complication | Unnecessary DISTINCT in SELECT clause | ✓ | ✓ | ✓ |
109
+ | 84 | COM | Complication | Unnecessary join | ✓ | | |
110
+ | 85 | COM | Complication | Unused correlation name | | | |
111
+ | 86 | COM | Complication | Correlation names are always identical | | | |
112
+ | 87 | COM | Complication | Unnecessarily general comparison operator | | | |
113
+ | 88 | COM | Complication | LIKE without wildcards | ✓ | ✓ | ✓ |
114
+ | 89 | COM | Complication | Unnecessarily complicated SELECT in EXISTS subquery | | | |
115
+ | 90 | COM | Complication | IN/EXISTS can be replaced by comparison | | | |
116
+ | 91 | COM | Complication | Unnecessary aggregate function | | | |
117
+ | 92 | COM | Complication | Unnecessary DISTINCT in aggregate function | | | |
118
+ | 93 | COM | Complication | Unnecessary argument of COUNT | | | |
119
+ | 94 | COM | Complication | Unnecessary GROUP BY in EXISTS subquery | | | |
120
+ | 95 | COM | Complication | GROUP BY with singleton groups | | | |
121
+ | 96 | COM | Complication | GROUP BY with only a single group | | | |
122
+ | 97 | COM | Complication | GROUP BY can be replaced with DISTINCT | | | |
123
+ | 98 | COM | Complication | UNION can be replaced by OR | | | |
124
+ | 99 | COM | Complication | Unnecessary column in ORDER BY clause | ✓ | | |
125
+ | 100 | COM | Complication | ORDER BY in subquery | | | |
126
+ | 101 | COM | Complication | Inefficient HAVING | | | |
127
+ | 102 | COM | Complication | Inefficient UNION | | | |
128
+ | 103 | COM | Complication | Condition in the subquery can be moved up | | | |
129
+ | 104 | COM | Complication | Condition on left table in LEFT OUTER JOIN | | | |
130
+ | 105 | COM | Complication | OUTER JOIN can be replaced by INNER JOIN | | | |
@@ -0,0 +1,20 @@
1
+ # Minimal makefile for Sphinx documentation
2
+ #
3
+
4
+ # You can set these variables from the command line, and also
5
+ # from the environment for the first two.
6
+ SPHINXOPTS ?=
7
+ SPHINXBUILD ?= sphinx-build
8
+ SOURCEDIR = .
9
+ BUILDDIR = _build
10
+
11
+ # Put it first so that "make" without argument is like "make help".
12
+ help:
13
+ @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14
+
15
+ .PHONY: help Makefile
16
+
17
+ # Catch-all target: route all unknown targets to Sphinx using the new
18
+ # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19
+ %: Makefile
20
+ @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)