resultForMax1RowIter ensures that an empty iterator returns at most one row
(ctx *sql.Context, schema sql.Schema, iter sql.RowIter, resultFields []pgproto3.FieldDescription)
| 698 | |
| 699 | // resultForMax1RowIter ensures that an empty iterator returns at most one row |
| 700 | func (h *DuckHandler) resultForMax1RowIter(ctx *sql.Context, schema sql.Schema, iter sql.RowIter, resultFields []pgproto3.FieldDescription) (*Result, error) { |
| 701 | defer trace.StartRegion(ctx, "DuckHandler.resultForMax1RowIter").End() |
| 702 | row, err := iter.Next(ctx) |
| 703 | if err == io.EOF { |
| 704 | return &Result{Fields: resultFields}, nil |
| 705 | } else if err != nil { |
| 706 | return nil, err |
| 707 | } |
| 708 | |
| 709 | if _, err = iter.Next(ctx); err != io.EOF { |
| 710 | return nil, fmt.Errorf("result max1Row iterator returned more than one row") |
| 711 | } |
| 712 | if err := iter.Close(ctx); err != nil { |
| 713 | return nil, err |
| 714 | } |
| 715 | |
| 716 | outputRow, err := h.rowToBytes(ctx, schema, resultFields, row) |
| 717 | if err != nil { |
| 718 | return nil, err |
| 719 | } |
| 720 | |
| 721 | ctx.GetLogger().Tracef("spooling result row %s", outputRow) |
| 722 | |
| 723 | return &Result{Fields: resultFields, Rows: []Row{{outputRow}}, RowsAffected: 1}, nil |
| 724 | } |
| 725 | |
| 726 | // resultForDefaultIter reads batches of rows from the iterator |
| 727 | // and writes results into the callback function. |
no test coverage detected