We want to parse the mysql query in python project and detect wrong query based on unbalanced quotes or wrong quotes placement or column filtered values having wrong quotes
Example:
- "select * from city where name='x and type=y;" -> Wrong query
- "select * from city where name='x and type=y';" -> Wrong query
We tried using sqlparse and sqlglot and sqlvalidator
from sqlglot import exp, parse_one
try:
sqlglot.transpile("select * from city where name='x and type=y';")
except sqlglot.errors.ParseError as e:
print(e.errors)