-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add support for named input parameters #561
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
Comments
https://dev.mysql.com/doc/internals/en/com-stmt-prepare.html Does COM_PREPARE_STMT supports named placeholder? |
Is there a way of using the SQL package's named param support and converting them back to ordered params in the MySQL package so that the it works with any existing MySQL/MariaDB protocol (as the ordered params work well today)? I.e. emulate it rather than having to prepare a statement. Similar to how I believe PHP's PDO library works. |
It can be. But it's far from current implementation. We should be careful about it. |
Thanks @methane is it somewhat different to the named params implemented in libraries like sqlx? https://github.com/jmoiron/sqlx // Named queries can use structs, so if you have an existing struct (i.e. person := &Person{}) that you have populated, you can pass it in as &person
tx.NamedExec("INSERT INTO person (first_name, last_name, email) VALUES (:first_name, :last_name, :email)", &Person{"Jane", "Citizen", "[email protected]"}) |
@tomponline I meant I must take time to research a lot, including difference between sqlx and database/sql. But at least, when DB.Prepare() is called, we can't know NamedValue will be passed to Stmt.Query or not. It can be difference. So we should do much survey, design, discussion, implementation, test about it. |
My advice is don't wait So I recommend you to not use database/sql directly if you want such user-friendly features. (I'm not against to implement it. But my priority is performance and stability.) |
It actually works for the most part, I don't know if you guys got to adding support for it but it just sort of works. It's just an edge case we ran into that seems to work in PHP but not go
Please can we have @count too? Edit: maybe it doesn't, might have just been my testing code it worked on (which uses mock) |
I'm not sure if and how we should implement this. Is anyone interested to research a bit how other MySQL drivers (for other languages) support this? For example in PHP's PDO supports it and maybe also the official Java Connector (I'm not sure if it supports it). |
I don't want to add it.
I strongly prefer later, because:
Is there any reason to add named parameter to this project? |
or the database/sql provides emulation for all drivers that don't support it natively; |
No. I use sqlx. Adding common emulation layer doesn't solve |
friendly ping mysql: driver does not support the use of Named Parameters |
@elvizlai Please read the thread before firing ping. |
…list Add dependency on jmoiron/sqlx for named parameters support (and to simplify result extraction into structs). See for details: go-sql-driver/mysql#561 (comment) See also: - http://go-database-sql.org - https://github.com/jmoiron/sqlx - http://jmoiron.github.io/sqlx/ Part of #9
Could you please tell me when this feature will be released? I haven't seen any fix for this issue in version 1.7. Which version will address this problem specifically? |
@zhiyunliu Read #561 (comment) No plan to add it. But you can use named query now. |
Can you provide an example of code? Or where is the demo code? I get an error message "mysql: driver does not support the use of Named Parameters" when using sql.named. |
The support for named input parameters has been already added in
database/sql
with this commit, butgo-sql-driver/mysql
is not up to date with this feature yet.Could we please have the support for this feature in
go-sql-driver/mysql
as well in a near future?Here is the issue with a full discussion for this topic in
database/sql
, that may be helpful.Thanks
The text was updated successfully, but these errors were encountered: