Next retrieves the next row. It will return io.EOF if it's the last row.
(ctx *sql.Context)
| 49 | |
| 50 | // Next retrieves the next row. It will return io.EOF if it's the last row. |
| 51 | func (iter *DriverRowIter) Next(ctx *sql.Context) (sql.Row, error) { |
| 52 | if err := iter.rows.Next(iter.buffer[:len(iter.columns)]); err != nil { |
| 53 | if err == io.EOF { |
| 54 | return nil, io.EOF |
| 55 | } |
| 56 | return nil, err |
| 57 | } |
| 58 | |
| 59 | // Prune or fill the values to match the schema |
| 60 | width := len(iter.schema) // the desired width |
| 61 | if width == 0 { |
| 62 | width = len(iter.columns) |
| 63 | } else if len(iter.columns) < width { |
| 64 | for i := len(iter.columns); i < width; i++ { |
| 65 | iter.buffer[i] = nil |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | for i := 0; i < width; i++ { |
| 70 | iter.row[i] = iter.buffer[i] |
| 71 | } |
| 72 | |
| 73 | return sql.NewRow(iter.row[:width]...), nil |
| 74 | } |
| 75 | |
| 76 | // Close closes the underlying driver.Rows. |
| 77 | func (iter *DriverRowIter) Close(ctx *sql.Context) error { |