Next retrieves the next row. It will return io.EOF if it's the last row.
(ctx *sql.Context)
| 138 | |
| 139 | // Next retrieves the next row. It will return io.EOF if it's the last row. |
| 140 | func (iter *SqlRowIter) Next(ctx *sql.Context) (sql.Row, error) { |
| 141 | if !iter.rows.Next() { |
| 142 | if err := iter.rows.Err(); err != nil { |
| 143 | return nil, err |
| 144 | } |
| 145 | return nil, io.EOF |
| 146 | } |
| 147 | |
| 148 | // Scan the values into the buffer |
| 149 | if err := iter.rows.Scan(iter.pointers[:len(iter.columns)]...); err != nil { |
| 150 | return nil, err |
| 151 | } |
| 152 | |
| 153 | // logrus.Debugf("iter.decimals=%v, iter.lists=%v iter.buffer=%#v\n", iter.decimals, iter.lists, iter.buffer) |
| 154 | |
| 155 | // Process decimal values |
| 156 | for _, idx := range iter.decimals { |
| 157 | switch v := iter.buffer[idx].(type) { |
| 158 | case nil: |
| 159 | continue |
| 160 | case duckdb.Decimal: |
| 161 | iter.buffer[idx] = pgtype.Numeric{Int: v.Value, Exp: -int32(v.Scale), Valid: true} |
| 162 | case string: |
| 163 | var n pgtype.Numeric |
| 164 | if err := n.Scan(v); err != nil { |
| 165 | return nil, err |
| 166 | } |
| 167 | iter.buffer[idx] = n |
| 168 | case []any: |
| 169 | array := make([]pgtype.Numeric, len(v)) |
| 170 | for i, x := range v { |
| 171 | switch y := x.(type) { |
| 172 | case nil: |
| 173 | array[i] = pgtype.Numeric{} |
| 174 | case duckdb.Decimal: |
| 175 | array[i] = pgtype.Numeric{Int: y.Value, Exp: -int32(y.Scale), Valid: true} |
| 176 | case string: |
| 177 | if err := array[i].Scan(y); err != nil { |
| 178 | return nil, err |
| 179 | } |
| 180 | default: |
| 181 | return nil, fmt.Errorf("unexpected type %T for decimal value", x) |
| 182 | } |
| 183 | } |
| 184 | iter.buffer[idx] = array |
| 185 | default: |
| 186 | return nil, fmt.Errorf("unexpected type %T for decimal value", v) |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | // Process list values |
| 191 | for _, idx := range iter.lists { |
| 192 | var list []any |
| 193 | switch v := iter.buffer[idx].(type) { |
| 194 | case nil: |
| 195 | list = nil |
| 196 | case []pgtype.Numeric: // from the previous decimal processing step |
| 197 | iter.buffer[idx] = pgtype.FlatArray[pgtype.Numeric](v) |