-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Added count(*) support to sql parser. Fixed warnings in sql parser. #7490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
lib/pure/parsesql.nim
Outdated
| proc repr*(node: SqlNode): string = | ||
| result = $node.kind | ||
| if node.kind in LiteralNodes: | ||
| result &= " \"" & node.strVal & "\"" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is not how to quote things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like how this repr works anyways. I'll just remove the whole function for now.
lib/pure/parsesql.nim
Outdated
| for i, son in node.sons: | ||
| if i > 0: | ||
| result &= ", " | ||
| result &= repr(son) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is expensive, change repr to take result: var string parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right its not ideal. Do other reprs take result: var string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, usually the $ operator is overloaded and it uses a helper proc that uses the var string in the recursions. In fact, overloading of repr is simply not done in the stdlib (except for macros.nim and it's a mistake there too).
|
I have another problem related to this code I don't know how to fix. I want to use this code in JavaScript (client side SQL validation) but it uses |
Yeah, go for it. I'll help you out on IRC. |
|
How I solved this in the |
lib/pure/parsesql.nim
Outdated
| result = newNode(nkIdent, p.tok.literal) | ||
| getTok(p) | ||
| of tkIdentifier: | ||
| if p.tok.literal.toLowerAscii() in SqlFunctions: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Er, that is not how the SQL is supposed to work. We don't know the SQL functions there can be hundreds per SQL dialect. Why special case these few? It also makes the parser slower, tkIdentifier is likely on the critical path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the functions list, but I had to pass Quoted Identifiers from tokens to nodes as there needs to be a way to say quote foo as "count" and also have the unquoted count(*).
lib/pure/parsesql.nim
Outdated
| nkPrefix, | ||
| nkInfix, | ||
| nkCall, | ||
| nkFunction, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nkFunction is a misguided concept.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
238500f to
70a7161
Compare
|
@dom96 It looks like you just use the native json parser for javascript and then build nim nodes out out it's output? |
nkQuotedIdentnode type.toUpperAsciiandtoLowerAscii.