如何在EXE语句中传递绑定参数值?
例如-
actualvalue = append(actualvalue, 1)
actualvalue = append(actualvalue, 2)
actualvalue = append(actualvalue, 3)
query = “insert into table (a,b,c) values (:a,:b,:c) returning primarykey, secondarykey into :primarykey,:secondarykey”
stmtIns, err := dbConnImbl.Prep(query)
if err != nil { fmt.Println("Second Method Error 22====>> ",err) }
var id uint64
var id2 uint64
rowsAffected, err := stmtIns.Exe(actualvalue…, &id,&id2)//.Scan(&id,&id2)
if err != nil { fmt.Println("Error Cluses " , err) }
突出显示的行不起作用。
最佳答案
在对可变参数函数的调用中,您不能在...
之后传递其他参数,因此您还需要将id指针附加到Actualvalue slice 上。
var actualvalue []interface{}
var id uint64
var id2 uint64
actualvalue = append(actualvalue, 1)
actualvalue = append(actualvalue, 2)
actualvalue = append(actualvalue, 3)
actualvalue = append(actualvalue, &id)
actualvalue = append(actualvalue, &id2)
query = "insert into table (a,b,c) values (:a,:b,:c) returning primarykey, secondarykey into :primarykey,:secondarykey"
stmtIns, err := dbConnImbl.Prep(query)
if err != nil { fmt.Println("Second Method Error 22====>> ",err) }
rowsAffected, err := stmtIns.Exe(actualvalue...)
if err != nil { fmt.Println("Error Cluses " , err) }