-
-
Notifications
You must be signed in to change notification settings - Fork 234
Add support for prepared statements. #229
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
1f4ec38
to
0a0af60
Compare
@zachmu Looking for a quick pass and any thoughts here. Approach:
Currently think that testing strategy here is going to be:
Does that seem reasonable? |
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.
Looks like a good approach!
@@ -1786,7 +1786,7 @@ func convertVal(v *sqlparser.SQLVal) (sql.Expression, error) { | |||
} | |||
return expression.NewLiteral(val, sql.LongBlob), nil | |||
case sqlparser.ValArg: | |||
return expression.NewLiteral(string(v.Val), sql.LongText), nil | |||
return expression.NewBindVar(strings.TrimPrefix(string(v.Val), ":")), nil |
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.
Do named bindvars need to be distinct? If so, need an analyzer func to check that
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, they're also support for a different syntax, SELECT * FROM test WHERE id = :id
, and the identifier id
could be used multiple times in the query. IDs are auto-assigned by the tokenizer for the ?
syntax though, and those are distinct.
There's a problem though. The parser will parse a query that uses both ?
and :name
style variables and with the current approach it will run into a conflict if someone names one of their vars :v1
, for example. Longer-term we should distinguish between the two types of variables in the parser I think.
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.
Should have a few engine tests for the named var bindings in that case
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.
Including tests of using the same named binvar multiple places in the same query, and trying to execute with named bindvars that aren't in the original query (I can't remember seeing tests of the latter, definitely need engine tests of the former)
if err != nil { | ||
return nil, err | ||
} | ||
switch { |
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.
Seems like these would be better expressed as a switch on v.Type(), no?
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.
Yeah, maybe...I was using a few expressions like sqltypes.IsUnsigned(v.Type())
, so I went with this approach...could change it or split it into two groups...
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.
Generally looks good, got a couple requests for more tests and a very annoying request to not add a nil struct param to every QueryTest struct, sorry.
I don't think we need to support subqueries in v1.
@@ -1786,7 +1786,7 @@ func convertVal(v *sqlparser.SQLVal) (sql.Expression, error) { | |||
} | |||
return expression.NewLiteral(val, sql.LongBlob), nil | |||
case sqlparser.ValArg: | |||
return expression.NewLiteral(string(v.Val), sql.LongText), nil | |||
return expression.NewBindVar(strings.TrimPrefix(string(v.Val), ":")), nil |
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.
Should have a few engine tests for the named var bindings in that case
@@ -1786,7 +1786,7 @@ func convertVal(v *sqlparser.SQLVal) (sql.Expression, error) { | |||
} | |||
return expression.NewLiteral(val, sql.LongBlob), nil | |||
case sqlparser.ValArg: | |||
return expression.NewLiteral(string(v.Val), sql.LongText), nil | |||
return expression.NewBindVar(strings.TrimPrefix(string(v.Val), ":")), nil |
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.
Including tests of using the same named binvar multiple places in the same query, and trying to execute with named bindvars that aren't in the original query (I can't remember seeing tests of the latter, definitely need engine tests of the former)
…k across subqueries.
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.
Still don't see an engine test for applying the same named bindvar more than once in a query. Otherwise LGTM!
No description provided.