]> Cypherpunks repositories - gostls13.git/commitdiff
database/sql: properly document QueryRow
authorSarah Adams <shadams@google.com>
Mon, 5 Jun 2017 22:45:04 +0000 (15:45 -0700)
committerSarah Adams <shadams@google.com>
Mon, 12 Jun 2017 20:17:47 +0000 (20:17 +0000)
Fixes golang/go#20163

Change-Id: I0caf95fc84aa502715848151c93b6e7bee003ea5
Reviewed-on: https://go-review.googlesource.com/44890
Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
src/database/sql/sql.go

index aa254b87a1efdf4bca0cd930bd177031be2faaa8..9bc6414f2bfd13bd7e96e340e2f452e1e4041fe1 100644 (file)
@@ -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...)
 }