How to parse such a query to sql?.. or
Do you know any open source parsers which can parse it:
(((adsfa ≤ "value") AND (adsfa > "value")) OR (adsfa = "value"))
AND (adsfa ≤ "value") OR ((adsfa ≤ "value") AND (adsfa ≤ "value"))
AND (adsfa ≤ "value")
I’ve tried to build my own algorithm with string.Split(stringSeparators,StringSplitOptions.RemoveEmptyEntries)
algorithm is getting more and more complicated but i’m finding more combinations that it can’t parse.
- adsfa is column name
- ≤ is operator
- “value” is value
UPDATED: Thank you all, may be I’ll use one of the parsers in the next version.
I developed something like this myself using the Irony library. It’s still in alpha, but has been stable for me so far. Note though that I used it to parse expressions that were written by other programmers, not user input.
Here’s another idea – if you trust the source of the query, and just need to convert it to proper SQL, maybe a few simple
string.Replace()would be enough? It’s practically SQL already, just the operators are weird characters.