-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
database/sql/driver: support slices? #16235
Comments
CC @bradfitz |
Related to #13567 |
Which database(s) support this at at the wire level? Where you send SQL with a single placeholder and an array type of values comes later? |
Postgresql is the main one I'm aware of, as it has native array types. MS SQL server can also support custom types that can included table valued types. |
@kardianos Postgres and SQL Server (assuming the array is a custom table-valued type) would each treat that slice/array as a single scalar value. In the example given, |
CL https://golang.org/cl/38533 mentions this issue. |
Previously all arguments were passed through driver.IsValid. This checked arguments against a few fundamental go types and prevented others from being passed in as arguments. The new interface driver.NamedValueChecker may be implemented by both driver.Stmt and driver.Conn. This allows this new interface to completely supersede the driver.ColumnConverter interface as it can be used for checking arguments known to a prepared statement and arbitrary query arguments. The NamedValueChecker may be skipped with driver.ErrSkip after all special cases are exhausted to use the default argument converter. In addition if driver.ErrRemoveArgument is returned the argument will not be passed to the query at all, useful for passing in driver specific per-query options. Add a canonical Out argument wrapper to be passed to OUTPUT parameters. This will unify checks that need to be written in the NameValueChecker. The statement number check is also moved to the argument converter so the NamedValueChecker may remove arguments passed to the query. Fixes #13567 Fixes #18079 Updates #18417 Updates #17834 Updates #16235 Updates #13067 Updates #19797 Change-Id: I89088bd9cca4596a48bba37bfd20d987453ef237 Reviewed-on: https://go-review.googlesource.com/38533 Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
@snadrus I think this is actually fixed. go1.9 now supports custom import types so it is now up to drivers to implement. Can you confirm? |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?1.7
What operating system and processor architecture are you using (
go env
)?All
What did you do?
db := ...connect to mysql db
cursor, err := db.Query("SELECT * FROM user WHERE firstName IN (?)",
[]string{"Bob", "Matt", "Sam"})
if err != nil { ////// Errored
fmt.Println(err)
return
}
.....
What did you expect to see?
Comparing to PHP, I expected the following query's result:
SELECT * FROM user WHERE firstName IN ('Bob', 'Matt', 'Sam')
What did you see instead?
sql: converting Exec argument #0's type: unsupported type []int, a slice
The text was updated successfully, but these errors were encountered: