-
Notifications
You must be signed in to change notification settings - Fork 162
Support for named and indexed parameters #170
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
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.
@zauguin The implementation looks good to me.
I'm just wondering why would anyone prefer the named parameters instead of ?
given our current api interface ?
@aminroosta The motivation are prepared statements where the parameters are not bound immediately after creating the statement. The caller can create a work-around by using the This also gives more flexibility to the implementation of the callee. Also the SQLite documentation says about This becomes even more useful in combination with #169. |
@zauguin You make a really good point, I also agree :-) Let's talk about the interface, I will propose to use template character packs db << "INSERT INTO t VALUES(:firstname, :lastname, :birthday);"
<< named_parameter<":birthday">("2000-01-01")
<< named_parameter<":firstname">("John")
<< named_parameter<":lastname">("Doe"); I have not thought about the details of implementation but given we have class template argument deduction it should be possible to implement in C++17. What do you think? |
@aminroosta Literal strings are not valid non-type template arguments, so AFAICT syntax like We could create a function with two regular parameters:
|
@zauguin Thanks for the proposal link, yea makes sense. Between the two syntaxes |
Let's use the function then, this also allows non-literals. Then I would use |
This is a UDL based attempt to support binding named parameters: For example
I am not really happ with the name
_sqlparam
. Does somebody have a better idea?Another question is how to handle mixed positional and named parameters: Currently
_sqlparam
paameters are ignored in the normal order, so for examplewould bind both parameters,
1
and2
, to:abc
so the result would be2, NULL
.This is not perfect but I do not know about a better way and using both named and
?
parameters together is advised against in the SQLite manual anyway, so fixing this might not be the top priority.