jehugaleahsa / SQLGeneration

Provides core classes for generating SQL at runtime.
The Unlicense
22 stars 10 forks source link

The parser is not able to handle CAST #22

Open victorsantoss opened 9 years ago

victorsantoss commented 9 years ago

Hello again,

Another simple query is not being properly handled by the parser.

Original Query Output query
SELECT CAST('1' AS FLOAT) SELECT CAST

As far as I verified "CAST" is being parsed as Column and not function.

victorsantoss commented 9 years ago

Just as a complement to this. The problem isn't only with cast, the same occurs with Count(*).

As far as I saw, if we use Count(1) a {SQLGeneration.Builders.Function} is gererated, besides that, when we use Count(*) a {SQLGeneration.Builders.Placeholder} is generated.

The same is what happens with Cast. It's being generated a {SQLGeneration.Builders.Placeholder} and not a {SQLGeneration.Builders.Function}.

Probably the problem is due to the "as" word inside the function. I mispelled that to "SELECT CAST('1' IS FLOAT)", what is a wrong SQL statement, but was handled corrected by the Parser as Function.

Still going deeper to see if I can do some improvements in order to solve or at least to help you out.

jehugaleahsa commented 9 years ago

Yeah. I was aware CAST would not work. The problem is two-fold. One, it does get confused by the AS keyword. Then it doesn't really know what to do with the type. I think it would make sense to simply add a separate grammar rule to handle cast. Pretty much explicitly look for word CAST, followed by parenthesis containing an expression, 'AS' and an identifier. I think, before, I was concerned with what that identifier would be for a type, concerned mostly that my command builder would think it was a column name or something else.