You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Another common character to indicate parameters in prepared queries is colon (WHERE name = :1).
Perhaps this could be implemented by adding functions that recognize the query parameters (similar to is_identifier_start/is_identifier_part) to Dialect, and additional variants to Token and Value? @andygrove what do you think?
@andygrove Yes, I use sql in two steps (prepare + run)
Similar to the library (implemented as a compiler plugin) rust-postgres-macros
it is necessary to parse the sql at the compilation stage in order to exclude a non-valid sql at runtime.
For database queries I use rust-postgres which uses $1 as a parameter of a prepared request.
It may be possible to add the same: :1.
Perhaps you should separate the implementation from parse_sql and add the function parse_sql_prepare?
Thanks for the pull request (#55). Reading through it gave me another idea: you could implement a dialect (in your own crate) that accepts '$' in its is_identifier_start: this would lead to $1 getting parsed as ASTNode::SQLIdentifier. There's some difference in parser's treatment of identifiers vs literals, but I can't think of a case where it would matter. Would this work for you?
Activity
nickolay commentedon Apr 20, 2019
I'm guessing you want this for a library that will let the user execute SQL in two steps (prepare + run)?
A quick search indicates that the dollar sign:
moneyliteral in MSSQLAnother common character to indicate parameters in prepared queries is colon (
WHERE name = :1).Perhaps this could be implemented by adding functions that recognize the query parameters (similar to
is_identifier_start/is_identifier_part) toDialect, and additional variants toTokenandValue? @andygrove what do you think?Jekshmek commentedon Apr 24, 2019
@andygrove Yes, I use sql in two steps (prepare + run)
Similar to the library (implemented as a compiler plugin) rust-postgres-macros
it is necessary to parse the sql at the compilation stage in order to exclude a non-valid sql at runtime.
For database queries I use rust-postgres which uses
$1as a parameter of a prepared request.It may be possible to add the same:
:1.Perhaps you should separate the implementation from
parse_sqland add the functionparse_sql_prepare?nickolay commentedon Apr 26, 2019
Thanks for the pull request (#55). Reading through it gave me another idea: you could implement a dialect (in your own crate) that accepts
'$'in itsis_identifier_start: this would lead to$1getting parsed asASTNode::SQLIdentifier. There's some difference in parser's treatment of identifiers vs literals, but I can't think of a case where it would matter. Would this work for you?Jekshmek commentedon Apr 29, 2019
@andygrove Thanks, this solution is right for me.