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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user