Did you use the correct calling convension e.g.
db.Query(query, cond...)
The ... makes the slice variadic, passing echData.Active, exchData.Role
instead of just a interface slice
On 17/05/2020 23:27, Saied Seghatoleslami wrote:
I hate to dig up something from 2012, but I have come across a similar
issue where I can use an explanation. The signature of the Query
function in the sql package is:
|
func (db *DB <https://golang.org/pkg/database/sql/#DB>)Query(query string
<https://golang.org/pkg/builtin/#string>,args ...interface{})(*Rows
<https://golang.org/pkg/database/sql/#Rows>,error <https://golang.org/pkg/builtin/#error>)
|
so, one would assume that passing something like this for args would
work (Active is bool and Role is a string:
|
varcond =[]interface{}{exchData.Active,exchData.Role}
|
but it does not, it results in this error:
|
sql:converting argument $1 type:unsupported type []interface{},a slice
of interface
|
I suspect there is a good explanation for this that I do not get.
On Friday, September 7, 2012 at 4:45:07 PM UTC-4, Paddy Foran wrote:
Consider the following:
In package fmt: func Println(a …interface{})
One would think the following code would work:
func main() {
testslice := []string { "this", "is", "a", "test" }
fmt.Println(testslice…)
}
One would subsequently be met with "cannot use testslice (type
[]string) as type []interface {} in function argument"
(http://play.golang.org/p/H3349TDJnS
<http://play.golang.org/p/H3349TDJnS>)
On the other hand, if one were to try:
func print(words …string) {
for _, word := range words {
fmt.Printf("%s", word)
}
}
func main() {
testslice := []string { "this", "is", "a", "test" }
print(testslice…)
}
Everything works as expected (http://play.golang.org/p/1ZnIwge19V
<http://play.golang.org/p/1ZnIwge19V>). Can anyone explain why the
empty interface in variadic parameters prevents me from using
argument expansion?
God, I hope I used the right names for all these things.
--
You received this message because you are subscribed to the Google
Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to golang-nuts+unsubscr...@googlegroups.com
<mailto:golang-nuts+unsubscr...@googlegroups.com>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/1cc28db0-98c6-49cd-bd3e-7752ef2b5328%40googlegroups.com
<https://groups.google.com/d/msgid/golang-nuts/1cc28db0-98c6-49cd-bd3e-7752ef2b5328%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/04082c78-b064-24a7-08e2-16bec1ac690d%40multiplay.co.uk.