0

I have a use case where I need to check the format of the sql query before sending to the the database for execution.

If sql query is not in correct format sqlparse should return the false status, if it is in correct format it should return true status.

I did not see any function in sqlparse docuementation for the same.

Example of my use case

This should return true:

select 
    count(users), 
    department 
from 
   usertable
group by department

This should return false:

select 
    count(users), 
    department,
    location 
from 
   usertable
group by department
2
  • 1
    I believe sqlparse is a non-validating parser. Perhaps something like pypi.org/project/sqlvalidator would be a better match Commented Apr 20, 2023 at 14:32
  • When I used that I get below error File "C:\Users\Asus\AppData\Local\Programs\Python\Python310\lib\site-packages\sqlvalidator\grammar\lexer.py", line 426, in parse next_token = next(tokens) StopIteration Input SQL select count(EVT_ATT_1),EVT_ATT_1 from DETECTED_EVENTS group by; Commented Apr 21, 2023 at 8:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.