From 3bcdbe57b6847e5fc3ab16016f5f66d9960fff97 Mon Sep 17 00:00:00 2001 From: Sarah Adams Date: Mon, 5 Jun 2017 15:45:04 -0700 Subject: [PATCH] database/sql: properly document QueryRow Fixes golang/go#20163 Change-Id: I0caf95fc84aa502715848151c93b6e7bee003ea5 Reviewed-on: https://go-review.googlesource.com/44890 Reviewed-by: Daniel Theophanes --- src/database/sql/sql.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/database/sql/sql.go b/src/database/sql/sql.go index aa254b87a1..9bc6414f2b 100644 --- a/src/database/sql/sql.go +++ b/src/database/sql/sql.go @@ -1352,6 +1352,9 @@ func (db *DB) queryDC(ctx, txctx context.Context, dc *driverConn, releaseConn fu // QueryRowContext executes a query that is expected to return at most one row. // QueryRowContext always returns a non-nil value. Errors are deferred until // Row's Scan method is called. +// If the query selects no rows, the *Row's Scan will return ErrNoRows. +// Otherwise, the *Row's Scan scans the first selected row and discards +// the rest. func (db *DB) QueryRowContext(ctx context.Context, query string, args ...interface{}) *Row { rows, err := db.QueryContext(ctx, query, args...) return &Row{rows: rows, err: err} @@ -1360,6 +1363,9 @@ func (db *DB) QueryRowContext(ctx context.Context, query string, args ...interfa // QueryRow executes a query that is expected to return at most one row. // QueryRow always returns a non-nil value. Errors are deferred until // Row's Scan method is called. +// If the query selects no rows, the *Row's Scan will return ErrNoRows. +// Otherwise, the *Row's Scan scans the first selected row and discards +// the rest. func (db *DB) QueryRow(query string, args ...interface{}) *Row { return db.QueryRowContext(context.Background(), query, args...) } @@ -1540,6 +1546,9 @@ func (c *Conn) QueryContext(ctx context.Context, query string, args ...interface // QueryRowContext executes a query that is expected to return at most one row. // QueryRowContext always returns a non-nil value. Errors are deferred until // Row's Scan method is called. +// If the query selects no rows, the *Row's Scan will return ErrNoRows. +// Otherwise, the *Row's Scan scans the first selected row and discards +// the rest. func (c *Conn) QueryRowContext(ctx context.Context, query string, args ...interface{}) *Row { rows, err := c.QueryContext(ctx, query, args...) return &Row{rows: rows, err: err} @@ -1971,6 +1980,9 @@ func (tx *Tx) Query(query string, args ...interface{}) (*Rows, error) { // QueryRowContext executes a query that is expected to return at most one row. // QueryRowContext always returns a non-nil value. Errors are deferred until // Row's Scan method is called. +// If the query selects no rows, the *Row's Scan will return ErrNoRows. +// Otherwise, the *Row's Scan scans the first selected row and discards +// the rest. func (tx *Tx) QueryRowContext(ctx context.Context, query string, args ...interface{}) *Row { rows, err := tx.QueryContext(ctx, query, args...) return &Row{rows: rows, err: err} @@ -1979,6 +1991,9 @@ func (tx *Tx) QueryRowContext(ctx context.Context, query string, args ...interfa // QueryRow executes a query that is expected to return at most one row. // QueryRow always returns a non-nil value. Errors are deferred until // Row's Scan method is called. +// If the query selects no rows, the *Row's Scan will return ErrNoRows. +// Otherwise, the *Row's Scan scans the first selected row and discards +// the rest. func (tx *Tx) QueryRow(query string, args ...interface{}) *Row { return tx.QueryRowContext(context.Background(), query, args...) } -- 2.50.0