For a tiny database that I am building, I would like to add support for a very small subset of SQL. I am thinking about using the JqlParser library (instead of writing my own parser).
I was thinking about using the visitor pattern as described in the documentation. By default, if I just use the provided example which has visitors for Select, PlainSelect, Column, and EqualsTo, and the input is an insert statement or has group by, having, etc., the non-supported things are just getting ignored.
Is it possible to identify and reject SQL queries (e.g., throw an Exception) that use statements/features for which I didn't implement a visitor adapter? Or is there an alternative way of using the library that is better suited?
As you may have noticed, you often have a visitor interface, such as
ExpressionVisitoras well as an adapter class, such asExpressionVisitorAdapterthat implements that interface, and provide a default implementation for each method; and most of them are empty. You could write your own adapter class that would implement each method by throwing an exception instead of doing nothing. That way if you don't override some method, you will get an exception whenever it's called.