1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| func makeRowsMap(rows *sql.Rows) []map[string]interface{} { colTypes, _ := rows.ColumnTypes() var rowParam = make([]interface{}, len(colTypes)) var rowValue = make([]interface{}, len(colTypes))
for i, colType := range colTypes { rowValue[i] = reflect.New(colType.ScanType()) rowParam[i] = reflect.ValueOf(&rowValue[i]).Interface() }
var arrays []map[string]interface{} = make([]map[string]interface{},0) for rows.Next() { rows.Scan(rowParam...) record := make(map[string]interface{}) for i, colType := range colTypes { if colType.ScanType().String() == "time.Time" { record[colType.Name()] = rowValue[i].(time.Time).Format("2006-01-02 15:04:05") }else if colType.DatabaseTypeName() == "NUMERIC" { record[colType.Name()],_ = strconv.ParseFloat(string(rowValue[i].([]byte)),64) }else{ record[colType.Name()] = rowValue[i] }
} arrays = append(arrays, record) } return arrays }
func byteToFloat64(bytes []byte) float64 { bits := binary.LittleEndian.Uint64(bytes)
return math.Float64frombits(bits) }
|