resultForMax1RowIter ensures that an empty iterator returns at most one row
(ctx *sql.Context, schema sql.Schema, iter sql.RowIter, resultFields []pgproto3.FieldDescription, formatCodes []int16)
| 591 | |
| 592 | // resultForMax1RowIter ensures that an empty iterator returns at most one row |
| 593 | func resultForMax1RowIter(ctx *sql.Context, schema sql.Schema, iter sql.RowIter, resultFields []pgproto3.FieldDescription, formatCodes []int16) (*Result, error) { |
| 594 | defer trace.StartRegion(ctx, "DoltgresHandler.resultForMax1RowIter").End() |
| 595 | row, err := iter.Next(ctx) |
| 596 | if err == io.EOF { |
| 597 | return &Result{Fields: resultFields}, nil |
| 598 | } else if err != nil { |
| 599 | return nil, err |
| 600 | } |
| 601 | |
| 602 | if _, err = iter.Next(ctx); err != io.EOF { |
| 603 | return nil, errors.Errorf("result max1Row iterator returned more than one row") |
| 604 | } |
| 605 | if err := iter.Close(ctx); err != nil { |
| 606 | return nil, err |
| 607 | } |
| 608 | |
| 609 | outputRow, err := rowToBytes(ctx, schema, row, formatCodes) |
| 610 | if err != nil { |
| 611 | return nil, err |
| 612 | } |
| 613 | |
| 614 | ctx.GetLogger().Tracef("spooling result row %s", outputRow) |
| 615 | |
| 616 | return &Result{Fields: resultFields, Rows: []Row{{outputRow}}, RowsAffected: 1}, nil |
| 617 | } |
| 618 | |
| 619 | // resultForDefaultIter reads batches of rows from the iterator |
| 620 | // and writes results into the callback function. |
no test coverage detected