修复gdb.GetAll针对返回数据列表的for..range...的返回结果slice相同指针问题

This commit is contained in:
John
2018-05-04 17:59:37 +08:00
parent 6c0e4bd9a7
commit 5967af8cd3
2 changed files with 6 additions and 2 deletions

View File

@ -95,8 +95,12 @@ func (db *Db) GetAll(query string, args ...interface{}) (Result, error) {
}
row := make(Record)
for i, col := range values {
row[columns[i]] = Value(col)
k := columns[i]
v := make([]byte, len(col))
copy(v, col)
row[k] = v
}
//fmt.Printf("%p\n", row["typeid"])
records = append(records, row)
}
return records, nil

View File

@ -478,7 +478,7 @@ func mapToStruct() {
}
func main() {
r, _ := db.Table("user").Select()
r, _ := db.Table("user").Fields("*").Where("typeid = ?", 1).Limit(0, 10).Select()
j, _ := gparser.VarToJson(r.ToList())
fmt.Println(string(j))
fmt.Println(r)