mysql - Issue with sql query in GO -
i have simple mysql table, 3 columns, a, b , c.
a , b keys.
i have go app , i'm trying retrieve data db. other queries works charm, 1 doesn't:
aparam := "avalue" bparam := "3,4,6,9" stmt, err := o.database.prepare("select * tablex `a`= ? , `b` in ( ? )") defer stmt.close() rows, err := stmt.query(aparam, bparam) rows.next() { ... }
if replace second ? values, works perfect:
stmt, err := o.database.prepare("select * tablex `a`= ? , `b` in ( 3,4,6,9 )")
i tried (it doesn't work):
stmt, err := o.database.prepare("select * tablex `a`= ? , `b` in ( " + bparam +" )")
any idea?
the issue single ?
not expanded select
statement (like string replace), single string value 3,4,5,6
you need expand each value of in
clause such:
params := []interface{} { "avalue", 3, 4, 6, 9 } stmt, err := o.database.prepare("select * tablex `a`= ? , `b` in ( ?, ?, ?, ? )") defer stmt.close() rows, err := stmt.query(params...)
to make life easier, can use package sqlx, has better support parameterized in
queries
Comments
Post a Comment