aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSarah Adams <shadams@google.com>2017-06-05 15:45:04 -0700
committerSarah Adams <shadams@google.com>2017-06-12 20:17:47 +0000
commit3bcdbe57b6847e5fc3ab16016f5f66d9960fff97 (patch)
treebd399f7da18987cb62cf0f361daa829923825baf
parent32543a8bf7c74320acb6bb147bc17bf0dd7df9bb (diff)
downloadgo-3bcdbe57b6847e5fc3ab16016f5f66d9960fff97.tar.gz
go-3bcdbe57b6847e5fc3ab16016f5f66d9960fff97.zip
database/sql: properly document QueryRow
Fixes golang/go#20163 Change-Id: I0caf95fc84aa502715848151c93b6e7bee003ea5 Reviewed-on: https://go-review.googlesource.com/44890 Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
-rw-r--r--src/database/sql/sql.go15
1 files changed, 15 insertions, 0 deletions
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...)
}