(columns []string, dataTypes []dataType, rows *sql.Rows)
| 85 | } |
| 86 | |
| 87 | func getColumnValues(columns []string, dataTypes []dataType, |
| 88 | rows *sql.Rows) ([]interface{}, error) { |
| 89 | // ptrToValues takes a slice of pointers, deference them, and return the values referenced |
| 90 | // by these pointers |
| 91 | ptrToValues := func(ptrs []interface{}) []interface{} { |
| 92 | values := make([]interface{}, 0, len(ptrs)) |
| 93 | for _, ptr := range ptrs { |
| 94 | // dereference the pointer to get the actual value |
| 95 | v := reflect.ValueOf(ptr).Elem().Interface() |
| 96 | values = append(values, v) |
| 97 | } |
| 98 | return values |
| 99 | } |
| 100 | |
| 101 | valuePtrs := make([]interface{}, 0, len(columns)) |
| 102 | for i := range columns { |
| 103 | switch dataTypes[i] { |
| 104 | case stringType: |
| 105 | valuePtrs = append(valuePtrs, new([]byte)) // the value can be nil |
| 106 | case intType: |
| 107 | valuePtrs = append(valuePtrs, new(sql.NullInt64)) |
| 108 | case floatType: |
| 109 | valuePtrs = append(valuePtrs, new(sql.NullFloat64)) |
| 110 | case datetimeType: |
| 111 | valuePtrs = append(valuePtrs, new(mysql.NullTime)) |
| 112 | default: |
| 113 | x.Panic(errors.Errorf("detected unsupported type %s on column %s", |
| 114 | dataTypes[i], columns[i])) |
| 115 | } |
| 116 | } |
| 117 | if err := rows.Scan(valuePtrs...); err != nil { |
| 118 | return nil, errors.Wrapf(err, "while scanning column values") |
| 119 | } |
| 120 | colValues := ptrToValues(valuePtrs) |
| 121 | return colValues, nil |
| 122 | } |
no test coverage detected