(rows *stdsql.Rows, schema sql.Schema)
| 92 | } |
| 93 | |
| 94 | func NewSqlRowIter(rows *stdsql.Rows, schema sql.Schema) (*SqlRowIter, error) { |
| 95 | columns, err := rows.ColumnTypes() |
| 96 | if err != nil { |
| 97 | return nil, err |
| 98 | } |
| 99 | |
| 100 | width := max(len(columns), len(schema)) |
| 101 | buf := make([]any, width) |
| 102 | ptrs := make([]any, width) |
| 103 | for i := range buf { |
| 104 | ptrs[i] = &buf[i] |
| 105 | } |
| 106 | |
| 107 | var decimals []int |
| 108 | for i, c := range columns { |
| 109 | if strings.HasPrefix(c.DatabaseTypeName(), "DECIMAL") { |
| 110 | decimals = append(decimals, i) |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | var lists []int |
| 115 | for i, t := range columns { |
| 116 | if strings.HasSuffix(t.DatabaseTypeName(), "[]") { |
| 117 | lists = append(lists, i) |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | var hugeInts []int |
| 122 | for i, t := range columns { |
| 123 | if t.DatabaseTypeName() == "HUGEINT" { |
| 124 | hugeInts = append(hugeInts, i) |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | iter := &SqlRowIter{rows, columns, schema, buf, ptrs, decimals, lists, hugeInts} |
| 129 | if logrus.GetLevel() >= logrus.DebugLevel { |
| 130 | logrus.Debug("New " + iter.String()) |
| 131 | } |
| 132 | return iter, nil |
| 133 | } |
| 134 | |
| 135 | func (iter *SqlRowIter) String() string { |
| 136 | return fmt.Sprintf("SqlRowIter: columns=[%s], schema=[%s]", formatColumnTypes(iter.columns), formatSchema(iter.schema)) |
no test coverage detected