2
0

Add CommandTag to Rows interface

This allows handling queries where it is unknown if there will be a
result set or not. If it is not a result set returning query the
command tag will still be available.
This commit is contained in:
Jack Christensen
2019-09-02 09:53:26 -05:00
parent 0ef89ae0b7
commit b5ce0220f8
3 changed files with 43 additions and 11 deletions
+22 -11
View File
@@ -21,7 +21,12 @@ type Rows interface {
// to call Close after rows is already closed.
Close()
// Err returns any error that occurred while reading.
Err() error
// CommandTag returns the command tag from this query. It is only available after Rows is closed.
CommandTag() pgconn.CommandTag
FieldDescriptions() []pgproto3.FieldDescription
// Next prepares the next row for reading. It returns true if there is another
@@ -76,16 +81,17 @@ type rowLog interface {
// connRows implements the Rows interface for Conn.Query.
type connRows struct {
ctx context.Context
logger rowLog
connInfo *pgtype.ConnInfo
values [][]byte
rowCount int
err error
startTime time.Time
sql string
args []interface{}
closed bool
ctx context.Context
logger rowLog
connInfo *pgtype.ConnInfo
values [][]byte
rowCount int
err error
commandTag pgconn.CommandTag
startTime time.Time
sql string
args []interface{}
closed bool
resultReader *pgconn.ResultReader
multiResultReader *pgconn.MultiResultReader
@@ -103,7 +109,8 @@ func (rows *connRows) Close() {
rows.closed = true
if rows.resultReader != nil {
_, closeErr := rows.resultReader.Close()
var closeErr error
rows.commandTag, closeErr = rows.resultReader.Close()
if rows.err == nil {
rows.err = closeErr
}
@@ -128,6 +135,10 @@ func (rows *connRows) Close() {
}
}
func (rows *connRows) CommandTag() pgconn.CommandTag {
return rows.commandTag
}
func (rows *connRows) Err() error {
return rows.err
}