I'm new to golang, pls help a noob.
I'm trying to fill a SQL insert statement from slice of data []interface{}
. In order to do that I need to call Exec function of sql package with arguments which are individual parts of slice I get from input channel.
Best to show piece of code in question:
// build INSERT vith variable number of columnes to fill
insertSql := "INSERT INTO " + database + "." + table + " VALUES ("
first := true
for _ = range format {
if !first {
insertSql += ","
}
first = false
insertSql += "?"
}
insertSql += ")"
// prepare statment
stm, err := db.Prepare(insertSql)
if err != nil {
return err
}
// execute the statement with data received via inputCh (type: []interface{})
outerLoop:
for {
select {
case data, opened := <-inputCh:
if !opened {
break outerLoop
}
// need to convert data of type []interface{} to individual arguments for Exec
_, err := stm.Exec(XXXXXXX)
if err != nil {
return err
}
}
}