我想在数据库中选择fild并使用golang返回3个vriables, 这是我的实际代码:
func db_tabela_select(cliente string) (id string, cod1 string, cod2 string, cod3 string) {
db, err := sql.Open("mysql", mysql_login)
if err != nil {
log.Fatal(err)
}
defer db.Close()
err = db.Ping()
if err != nil {
log.Fatal(err)
}
var Saldo, grup1, grup2, grup3, timestamp, user_agent string
err = db.QueryRow(fmt.Sprintf("select * from db_tabela WHERE `cliente`='%s' LIMIT 1;", string(cliente) )).Scan(
&id, &cliente, &Saldo, &cod1, &cod2, &cod3, &grup1, &grup2, &grup3, &user_agent, ×tamp)
if err != nil {
fmt.Println(err)
} else {
log.Printf("cod results : ", cod1, cod2, cod3)
}
return id, cod1, cod2, cod3
}
将此错误归还给我,我不会忘记我的错误在哪里:
sql: Scan error on column index 2: unsupported Scan, storing driver.Value type <
nil> into type *string
答案 0 :(得分:0)
由于数据库字段指定的是docker run ...
而不是null
,所以我不得不替换为:
not null
作者:
type MyStruct struct {
TheDatetime time.Time `json:"the_datetime"`
}