MCPcopy
hub / github.com/jackc/pgx / NextResult

Method NextResult

pgconn/pgconn.go:1618–1689  ·  view source on GitHub ↗

NextResult returns advances the MultiResultReader to the next result and returns true if a result is available.

()

Source from the content-addressed store, hash-verified

1616
1617// NextResult returns advances the MultiResultReader to the next result and returns true if a result is available.
1618func (mrr *MultiResultReader) NextResult() bool {
1619 for !mrr.closed && mrr.err == nil {
1620 msg, _ := mrr.pgConn.peekMessage()
1621 if _, ok := msg.(*pgproto3.DataRow); ok {
1622 if len(mrr.statementDescriptions) > 0 {
1623 rr := ResultReader{
1624 pgConn: mrr.pgConn,
1625 multiResultReader: mrr,
1626 ctx: mrr.ctx,
1627 }
1628
1629 // This result corresponds to a prepared statement description that was provided when queuing the batch.
1630 sd := mrr.statementDescriptions[0]
1631 mrr.statementDescriptions = mrr.statementDescriptions[1:]
1632
1633 resultFormats := mrr.resultFormats[0]
1634 mrr.resultFormats = mrr.resultFormats[1:]
1635
1636 sdFields := sd.Fields
1637 rr.fieldDescriptions = rr.pgConn.getFieldDescriptionSlice(len(sdFields))
1638
1639 err := combineFieldDescriptionsAndResultFormats(rr.fieldDescriptions, sdFields, resultFormats)
1640 if err != nil {
1641 rr.concludeCommand(CommandTag{}, err)
1642 }
1643
1644 mrr.pgConn.resultReader = rr
1645 mrr.rr = &mrr.pgConn.resultReader
1646 return true
1647 }
1648
1649 mrr.err = fmt.Errorf("unexpected DataRow message without preceding RowDescription")
1650 return false
1651 }
1652
1653 msg, err := mrr.receiveMessage()
1654 if err != nil {
1655 return false
1656 }
1657
1658 switch msg := msg.(type) {
1659 case *pgproto3.RowDescription:
1660 mrr.pgConn.resultReader = ResultReader{
1661 pgConn: mrr.pgConn,
1662 multiResultReader: mrr,
1663 ctx: mrr.ctx,
1664 fieldDescriptions: mrr.pgConn.getFieldDescriptionSlice(len(msg.Fields)),
1665 }
1666 convertRowDescription(mrr.pgConn.resultReader.fieldDescriptions, msg)
1667
1668 mrr.rr = &mrr.pgConn.resultReader
1669 return true
1670 case *pgproto3.CommandComplete:
1671 mrr.pgConn.resultReader = ResultReader{
1672 commandTag: mrr.pgConn.makeCommandTag(msg.CommandTag),
1673 commandConcluded: true,
1674 closed: true,
1675 }

Callers 12

ReadAllMethod · 0.95
execSimpleProtocolMethod · 0.80
QueryMethod · 0.80
ExecMethod · 0.80
QueryMethod · 0.80
TestConnCancelRequestFunction · 0.80
BenchmarkExecFunction · 0.80

Calls 7

concludeCommandMethod · 0.95
receiveMessageMethod · 0.95
convertRowDescriptionFunction · 0.85
peekMessageMethod · 0.80
makeCommandTagMethod · 0.80