MCPcopy Create free account
hub / github.com/lib/pq / simpleQuery

Method simpleQuery

conn.go:625–700  ·  view source on GitHub ↗
(q string)

Source from the content-addressed store, hash-verified

623}
624
625func (cn *conn) simpleQuery(q string) (*rows, error) {
626 if debugProto {
627 fmt.Fprintln(os.Stderr, " START conn.simpleQuery")
628 defer fmt.Fprintln(os.Stderr, " END conn.simpleQuery")
629 }
630
631 b := cn.writeBuf(proto.Query)
632 b.string(q)
633 err := cn.send(b)
634 if err != nil {
635 return nil, cn.handleError(err, q)
636 }
637
638 var (
639 res *rows
640 resErr error
641 )
642 for {
643 t, r, err := cn.recv1()
644 if err != nil {
645 return nil, cn.handleError(err, q)
646 }
647 switch t {
648 case proto.CommandComplete, proto.EmptyQueryResponse:
649 // We allow queries which don't return any results through Query as
650 // well as Exec. We still have to give database/sql a rows object
651 // the user can close, though, to avoid connections from being
652 // leaked. A "rows" with done=true works fine for that purpose.
653 if resErr != nil {
654 cn.err.set(driver.ErrBadConn)
655 return nil, fmt.Errorf("pq: unexpected message %q in simple query execution", t)
656 }
657 if res == nil {
658 res = &rows{cn: cn}
659 }
660 // Set the result and tag to the last command complete if there wasn't a
661 // query already run. Although queries usually return from here and cede
662 // control to Next, a query with zero results does not.
663 if t == proto.CommandComplete {
664 res.result, res.tag, err = cn.parseComplete(r.string())
665 if err != nil {
666 return nil, cn.handleError(err, q)
667 }
668 if res.colNames != nil {
669 return res, cn.handleError(resErr, q)
670 }
671 }
672 res.done = true
673 case proto.ReadyForQuery:
674 cn.processReadyForQuery(r)
675 if err == nil && res == nil {
676 res = &rows{done: true}
677 }
678 return res, cn.handleError(resErr, q) // done
679 case proto.ErrorResponse:
680 res = nil
681 resErr = parseError(r, q)
682 case proto.DataRow:

Callers 3

getBoolMethod · 0.95
queryMethod · 0.95
PingMethod · 0.95

Calls 11

writeBufMethod · 0.95
sendMethod · 0.95
handleErrorMethod · 0.95
recv1Method · 0.95
parseCompleteMethod · 0.95
processReadyForQueryMethod · 0.95
saveMessageMethod · 0.95
parseErrorFunction · 0.85
parsePortalRowDescribeFunction · 0.85
setMethod · 0.80
stringMethod · 0.45

Tested by

no test coverage detected