2
0

Always return non-nil *Rows from Query to fix QueryRow

Since QueryRow delegates to Query, it needs Query to always return
non-nil *Rows to prevent a nil pointer deference when the QueryRow
caller calls Scan(). This commit fixes the few returns in QueryEx that
return nil on errors rather than *Rows with its err field set.
This commit is contained in:
Kelsey Francis
2017-08-31 11:31:23 -07:00
parent 47c0e9cbac
commit fc18cc8d76
2 changed files with 45 additions and 6 deletions
+8 -6
View File
@@ -364,19 +364,21 @@ type QueryExOptions struct {
}
func (c *Conn) QueryEx(ctx context.Context, sql string, options *QueryExOptions, args ...interface{}) (rows *Rows, err error) {
rows = c.getRows(sql, args)
err = c.waitForPreviousCancelQuery(ctx)
if err != nil {
return nil, err
rows.fatal(err)
return rows, err
}
if err := c.ensureConnectionReadyForQuery(); err != nil {
return nil, err
rows.fatal(err)
return rows, err
}
c.lastActivityTime = time.Now()
rows = c.getRows(sql, args)
if err := c.lock(); err != nil {
rows.fatal(err)
return rows, err
@@ -413,14 +415,14 @@ func (c *Conn) QueryEx(ctx context.Context, sql string, options *QueryExOptions,
if err != nil && fatalWriteErr(n, err) {
rows.fatal(err)
c.die(err)
return nil, err
return rows, err
}
c.pendingReadyForQueryCount++
fieldDescriptions, err := c.readUntilRowDescription()
if err != nil {
rows.fatal(err)
return nil, err
return rows, err
}
if len(options.ResultFormatCodes) == 0 {