How to validate SQL query with unbalanced quotes

81 views Asked by At

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:

  1. "select * from city where name='x and type=y;" -> Wrong query
  2. "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)
0

There are 0 answers