M
M
Mr_ic02018-01-07 23:43:13
SQL
Mr_ic0, 2018-01-07 23:43:13

How to implement filtering records based on SQL like text?

Good day!
The challenge was that
the API should support filtering using parentheses to determine the precedence of conditions and using any combination of available fields. Need to support AND, OR, EQUALS, NOT EQUALS, GREATER THAN, LOWER THAN operations.
Example: (date eq '2016-05-01') AND ((distance gt 20) OR (distance lt 10)).
That is, there are several different methods for obtaining data, all of them must support filtering of this kind, and for each type of returned data there is a set of fields for which filtering is available.
Are there any standard tools that can be useful for implementing such a thing?
Of course, you need to check the correctness of the query syntax and check that there are no SQL injections <- This can be done through query validation with regex.
Does anyone have any helpful thoughts? On .NET, ADO.NET, Entity Framework.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
eRKa, 2018-01-08
@kttotto

You need to write your own grammar and an analyzer for it, which will generate a normal sql query. We used antlr4cs

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question