diff options
| author | Russ Cox <rsc@golang.org> | 2021-12-01 12:15:45 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2021-12-13 18:45:54 +0000 |
| commit | 2580d0e08d5e9f979b943758d3c49877fb2324cb (patch) | |
| tree | 3aafccfd81087734156a1778ce2321adf345f271 /src/database/sql/sql.go | |
| parent | 083ef5462494e81ee23316245c5d65085a3f62d9 (diff) | |
| download | go-2580d0e08d5e9f979b943758d3c49877fb2324cb.tar.xz | |
all: gofmt -w -r 'interface{} -> any' src
And then revert the bootstrap cmd directories and certain testdata.
And adjust tests as needed.
Not reverting the changes in std that are bootstrapped,
because some of those changes would appear in API docs,
and we want to use any consistently.
Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories
when preparing the bootstrap copy.
A few files changed as a result of running gofmt -w
not because of interface{} -> any but because they
hadn't been updated for the new //go:build lines.
Fixes #49884.
Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09
Reviewed-on: https://go-review.googlesource.com/c/go/+/368254
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/database/sql/sql.go')
| -rw-r--r-- | src/database/sql/sql.go | 96 |
1 files changed, 48 insertions, 48 deletions
diff --git a/src/database/sql/sql.go b/src/database/sql/sql.go index c5b4f50aa7..d55cee1210 100644 --- a/src/database/sql/sql.go +++ b/src/database/sql/sql.go @@ -92,7 +92,7 @@ type NamedArg struct { // Value is the value of the parameter. // It may be assigned the same value types as the query // arguments. - Value interface{} + Value any } // Named provides a more concise way to create NamedArg values. @@ -107,7 +107,7 @@ type NamedArg struct { // sql.Named("start", startTime), // sql.Named("end", endTime), // ) -func Named(name string, value interface{}) NamedArg { +func Named(name string, value any) NamedArg { // This method exists because the go1compat promise // doesn't guarantee that structs don't grow more fields, // so unkeyed struct literals are a vet error. Thus, we don't @@ -191,7 +191,7 @@ type NullString struct { } // Scan implements the Scanner interface. -func (ns *NullString) Scan(value interface{}) error { +func (ns *NullString) Scan(value any) error { if value == nil { ns.String, ns.Valid = "", false return nil @@ -217,7 +217,7 @@ type NullInt64 struct { } // Scan implements the Scanner interface. -func (n *NullInt64) Scan(value interface{}) error { +func (n *NullInt64) Scan(value any) error { if value == nil { n.Int64, n.Valid = 0, false return nil @@ -243,7 +243,7 @@ type NullInt32 struct { } // Scan implements the Scanner interface. -func (n *NullInt32) Scan(value interface{}) error { +func (n *NullInt32) Scan(value any) error { if value == nil { n.Int32, n.Valid = 0, false return nil @@ -269,7 +269,7 @@ type NullInt16 struct { } // Scan implements the Scanner interface. -func (n *NullInt16) Scan(value interface{}) error { +func (n *NullInt16) Scan(value any) error { if value == nil { n.Int16, n.Valid = 0, false return nil @@ -296,7 +296,7 @@ type NullByte struct { } // Scan implements the Scanner interface. -func (n *NullByte) Scan(value interface{}) error { +func (n *NullByte) Scan(value any) error { if value == nil { n.Byte, n.Valid = 0, false return nil @@ -323,7 +323,7 @@ type NullFloat64 struct { } // Scan implements the Scanner interface. -func (n *NullFloat64) Scan(value interface{}) error { +func (n *NullFloat64) Scan(value any) error { if value == nil { n.Float64, n.Valid = 0, false return nil @@ -349,7 +349,7 @@ type NullBool struct { } // Scan implements the Scanner interface. -func (n *NullBool) Scan(value interface{}) error { +func (n *NullBool) Scan(value any) error { if value == nil { n.Bool, n.Valid = false, false return nil @@ -375,7 +375,7 @@ type NullTime struct { } // Scan implements the Scanner interface. -func (n *NullTime) Scan(value interface{}) error { +func (n *NullTime) Scan(value any) error { if value == nil { n.Time, n.Valid = time.Time{}, false return nil @@ -412,7 +412,7 @@ type Scanner interface { // Reference types such as []byte are only valid until the next call to Scan // and should not be retained. Their underlying memory is owned by the driver. // If retention is necessary, copy their values before the next call to Scan. - Scan(src interface{}) error + Scan(src any) error } // Out may be used to retrieve OUTPUT value parameters from stored procedures. @@ -428,7 +428,7 @@ type Out struct { // Dest is a pointer to the value that will be set to the result of the // stored procedure's OUTPUT parameter. - Dest interface{} + Dest any // In is whether the parameter is an INOUT parameter. If so, the input value to the stored // procedure is the dereferenced value of Dest's pointer, which is then replaced with @@ -680,7 +680,7 @@ func (ds *driverStmt) Close() error { } // depSet is a finalCloser's outstanding dependencies -type depSet map[interface{}]bool // set of true bools +type depSet map[any]bool // set of true bools // The finalCloser interface is used by (*DB).addDep and related // dependency reference counting. @@ -692,13 +692,13 @@ type finalCloser interface { // addDep notes that x now depends on dep, and x's finalClose won't be // called until all of x's dependencies are removed with removeDep. -func (db *DB) addDep(x finalCloser, dep interface{}) { +func (db *DB) addDep(x finalCloser, dep any) { db.mu.Lock() defer db.mu.Unlock() db.addDepLocked(x, dep) } -func (db *DB) addDepLocked(x finalCloser, dep interface{}) { +func (db *DB) addDepLocked(x finalCloser, dep any) { if db.dep == nil { db.dep = make(map[finalCloser]depSet) } @@ -714,14 +714,14 @@ func (db *DB) addDepLocked(x finalCloser, dep interface{}) { // If x still has dependencies, nil is returned. // If x no longer has any dependencies, its finalClose method will be // called and its error value will be returned. -func (db *DB) removeDep(x finalCloser, dep interface{}) error { +func (db *DB) removeDep(x finalCloser, dep any) error { db.mu.Lock() fn := db.removeDepLocked(x, dep) db.mu.Unlock() return fn() } -func (db *DB) removeDepLocked(x finalCloser, dep interface{}) func() error { +func (db *DB) removeDepLocked(x finalCloser, dep any) func() error { xdep, ok := db.dep[x] if !ok { @@ -1627,7 +1627,7 @@ func (db *DB) prepareDC(ctx context.Context, dc *driverConn, release func(error) // ExecContext executes a query without returning any rows. // The args are for any placeholder parameters in the query. -func (db *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (Result, error) { +func (db *DB) ExecContext(ctx context.Context, query string, args ...any) (Result, error) { var res Result var err error var isBadConn bool @@ -1649,11 +1649,11 @@ func (db *DB) ExecContext(ctx context.Context, query string, args ...interface{} // // Exec uses context.Background internally; to specify the context, use // ExecContext. -func (db *DB) Exec(query string, args ...interface{}) (Result, error) { +func (db *DB) Exec(query string, args ...any) (Result, error) { return db.ExecContext(context.Background(), query, args...) } -func (db *DB) exec(ctx context.Context, query string, args []interface{}, strategy connReuseStrategy) (Result, error) { +func (db *DB) exec(ctx context.Context, query string, args []any, strategy connReuseStrategy) (Result, error) { dc, err := db.conn(ctx, strategy) if err != nil { return nil, err @@ -1661,7 +1661,7 @@ func (db *DB) exec(ctx context.Context, query string, args []interface{}, strate return db.execDC(ctx, dc, dc.releaseConn, query, args) } -func (db *DB) execDC(ctx context.Context, dc *driverConn, release func(error), query string, args []interface{}) (res Result, err error) { +func (db *DB) execDC(ctx context.Context, dc *driverConn, release func(error), query string, args []any) (res Result, err error) { defer func() { release(err) }() @@ -1702,7 +1702,7 @@ func (db *DB) execDC(ctx context.Context, dc *driverConn, release func(error), q // QueryContext executes a query that returns rows, typically a SELECT. // The args are for any placeholder parameters in the query. -func (db *DB) QueryContext(ctx context.Context, query string, args ...interface{}) (*Rows, error) { +func (db *DB) QueryContext(ctx context.Context, query string, args ...any) (*Rows, error) { var rows *Rows var err error var isBadConn bool @@ -1724,11 +1724,11 @@ func (db *DB) QueryContext(ctx context.Context, query string, args ...interface{ // // Query uses context.Background internally; to specify the context, use // QueryContext. -func (db *DB) Query(query string, args ...interface{}) (*Rows, error) { +func (db *DB) Query(query string, args ...any) (*Rows, error) { return db.QueryContext(context.Background(), query, args...) } -func (db *DB) query(ctx context.Context, query string, args []interface{}, strategy connReuseStrategy) (*Rows, error) { +func (db *DB) query(ctx context.Context, query string, args []any, strategy connReuseStrategy) (*Rows, error) { dc, err := db.conn(ctx, strategy) if err != nil { return nil, err @@ -1741,7 +1741,7 @@ func (db *DB) query(ctx context.Context, query string, args []interface{}, strat // The connection gets released by the releaseConn function. // The ctx context is from a query method and the txctx context is from an // optional transaction context. -func (db *DB) queryDC(ctx, txctx context.Context, dc *driverConn, releaseConn func(error), query string, args []interface{}) (*Rows, error) { +func (db *DB) queryDC(ctx, txctx context.Context, dc *driverConn, releaseConn func(error), query string, args []any) (*Rows, error) { queryerCtx, ok := dc.ci.(driver.QueryerContext) var queryer driver.Queryer if !ok { @@ -1811,7 +1811,7 @@ func (db *DB) queryDC(ctx, txctx context.Context, dc *driverConn, releaseConn fu // 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 { +func (db *DB) QueryRowContext(ctx context.Context, query string, args ...any) *Row { rows, err := db.QueryContext(ctx, query, args...) return &Row{rows: rows, err: err} } @@ -1825,7 +1825,7 @@ func (db *DB) QueryRowContext(ctx context.Context, query string, args ...interfa // // QueryRow uses context.Background internally; to specify the context, use // QueryRowContext. -func (db *DB) QueryRow(query string, args ...interface{}) *Row { +func (db *DB) QueryRow(query string, args ...any) *Row { return db.QueryRowContext(context.Background(), query, args...) } @@ -1995,7 +1995,7 @@ func (c *Conn) PingContext(ctx context.Context) error { // ExecContext executes a query without returning any rows. // The args are for any placeholder parameters in the query. -func (c *Conn) ExecContext(ctx context.Context, query string, args ...interface{}) (Result, error) { +func (c *Conn) ExecContext(ctx context.Context, query string, args ...any) (Result, error) { dc, release, err := c.grabConn(ctx) if err != nil { return nil, err @@ -2005,7 +2005,7 @@ func (c *Conn) ExecContext(ctx context.Context, query string, args ...interface{ // QueryContext executes a query that returns rows, typically a SELECT. // The args are for any placeholder parameters in the query. -func (c *Conn) QueryContext(ctx context.Context, query string, args ...interface{}) (*Rows, error) { +func (c *Conn) QueryContext(ctx context.Context, query string, args ...any) (*Rows, error) { dc, release, err := c.grabConn(ctx) if err != nil { return nil, err @@ -2019,7 +2019,7 @@ func (c *Conn) QueryContext(ctx context.Context, query string, args ...interface // 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 { +func (c *Conn) QueryRowContext(ctx context.Context, query string, args ...any) *Row { rows, err := c.QueryContext(ctx, query, args...) return &Row{rows: rows, err: err} } @@ -2045,7 +2045,7 @@ func (c *Conn) PrepareContext(ctx context.Context, query string) (*Stmt, error) // // Once f returns and err is not driver.ErrBadConn, the Conn will continue to be usable // until Conn.Close is called. -func (c *Conn) Raw(f func(driverConn interface{}) error) (err error) { +func (c *Conn) Raw(f func(driverConn any) error) (err error) { var dc *driverConn var release releaseConn @@ -2483,7 +2483,7 @@ func (tx *Tx) Stmt(stmt *Stmt) *Stmt { // ExecContext executes a query that doesn't return rows. // For example: an INSERT and UPDATE. -func (tx *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (Result, error) { +func (tx *Tx) ExecContext(ctx context.Context, query string, args ...any) (Result, error) { dc, release, err := tx.grabConn(ctx) if err != nil { return nil, err @@ -2496,12 +2496,12 @@ func (tx *Tx) ExecContext(ctx context.Context, query string, args ...interface{} // // Exec uses context.Background internally; to specify the context, use // ExecContext. -func (tx *Tx) Exec(query string, args ...interface{}) (Result, error) { +func (tx *Tx) Exec(query string, args ...any) (Result, error) { return tx.ExecContext(context.Background(), query, args...) } // QueryContext executes a query that returns rows, typically a SELECT. -func (tx *Tx) QueryContext(ctx context.Context, query string, args ...interface{}) (*Rows, error) { +func (tx *Tx) QueryContext(ctx context.Context, query string, args ...any) (*Rows, error) { dc, release, err := tx.grabConn(ctx) if err != nil { return nil, err @@ -2514,7 +2514,7 @@ func (tx *Tx) QueryContext(ctx context.Context, query string, args ...interface{ // // Query uses context.Background internally; to specify the context, use // QueryContext. -func (tx *Tx) Query(query string, args ...interface{}) (*Rows, error) { +func (tx *Tx) Query(query string, args ...any) (*Rows, error) { return tx.QueryContext(context.Background(), query, args...) } @@ -2524,7 +2524,7 @@ func (tx *Tx) Query(query string, args ...interface{}) (*Rows, error) { // 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 { +func (tx *Tx) QueryRowContext(ctx context.Context, query string, args ...any) *Row { rows, err := tx.QueryContext(ctx, query, args...) return &Row{rows: rows, err: err} } @@ -2538,7 +2538,7 @@ func (tx *Tx) QueryRowContext(ctx context.Context, query string, args ...interfa // // QueryRow uses context.Background internally; to specify the context, use // QueryRowContext. -func (tx *Tx) QueryRow(query string, args ...interface{}) *Row { +func (tx *Tx) QueryRow(query string, args ...any) *Row { return tx.QueryRowContext(context.Background(), query, args...) } @@ -2615,7 +2615,7 @@ type Stmt struct { // ExecContext executes a prepared statement with the given arguments and // returns a Result summarizing the effect of the statement. -func (s *Stmt) ExecContext(ctx context.Context, args ...interface{}) (Result, error) { +func (s *Stmt) ExecContext(ctx context.Context, args ...any) (Result, error) { s.closemu.RLock() defer s.closemu.RUnlock() @@ -2647,11 +2647,11 @@ func (s *Stmt) ExecContext(ctx context.Context, args ...interface{}) (Result, er // // Exec uses context.Background internally; to specify the context, use // ExecContext. -func (s *Stmt) Exec(args ...interface{}) (Result, error) { +func (s *Stmt) Exec(args ...any) (Result, error) { return s.ExecContext(context.Background(), args...) } -func resultFromStatement(ctx context.Context, ci driver.Conn, ds *driverStmt, args ...interface{}) (Result, error) { +func resultFromStatement(ctx context.Context, ci driver.Conn, ds *driverStmt, args ...any) (Result, error) { ds.Lock() defer ds.Unlock() @@ -2763,7 +2763,7 @@ func (s *Stmt) prepareOnConnLocked(ctx context.Context, dc *driverConn) (*driver // QueryContext executes a prepared query statement with the given arguments // and returns the query results as a *Rows. -func (s *Stmt) QueryContext(ctx context.Context, args ...interface{}) (*Rows, error) { +func (s *Stmt) QueryContext(ctx context.Context, args ...any) (*Rows, error) { s.closemu.RLock() defer s.closemu.RUnlock() @@ -2821,11 +2821,11 @@ func (s *Stmt) QueryContext(ctx context.Context, args ...interface{}) (*Rows, er // // Query uses context.Background internally; to specify the context, use // QueryContext. -func (s *Stmt) Query(args ...interface{}) (*Rows, error) { +func (s *Stmt) Query(args ...any) (*Rows, error) { return s.QueryContext(context.Background(), args...) } -func rowsiFromStatement(ctx context.Context, ci driver.Conn, ds *driverStmt, args ...interface{}) (driver.Rows, error) { +func rowsiFromStatement(ctx context.Context, ci driver.Conn, ds *driverStmt, args ...any) (driver.Rows, error) { ds.Lock() defer ds.Unlock() dargs, err := driverArgsConnLocked(ci, ds, args) @@ -2841,7 +2841,7 @@ func rowsiFromStatement(ctx context.Context, ci driver.Conn, ds *driverStmt, arg // 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 (s *Stmt) QueryRowContext(ctx context.Context, args ...interface{}) *Row { +func (s *Stmt) QueryRowContext(ctx context.Context, args ...any) *Row { rows, err := s.QueryContext(ctx, args...) if err != nil { return &Row{err: err} @@ -2863,7 +2863,7 @@ func (s *Stmt) QueryRowContext(ctx context.Context, args ...interface{}) *Row { // // QueryRow uses context.Background internally; to specify the context, use // QueryRowContext. -func (s *Stmt) QueryRow(args ...interface{}) *Row { +func (s *Stmt) QueryRow(args ...any) *Row { return s.QueryRowContext(context.Background(), args...) } @@ -3185,7 +3185,7 @@ func rowsColumnInfoSetupConnLocked(rowsi driver.Rows) []*ColumnType { if prop, ok := rowsi.(driver.RowsColumnTypeScanType); ok { ci.scanType = prop.ColumnTypeScanType(i) } else { - ci.scanType = reflect.TypeOf(new(interface{})).Elem() + ci.scanType = reflect.TypeOf(new(any)).Elem() } if prop, ok := rowsi.(driver.RowsColumnTypeDatabaseTypeName); ok { ci.databaseType = prop.ColumnTypeDatabaseTypeName(i) @@ -3263,7 +3263,7 @@ func rowsColumnInfoSetupConnLocked(rowsi driver.Rows) []*ColumnType { // // If any of the first arguments implementing Scanner returns an error, // that error will be wrapped in the returned error -func (rs *Rows) Scan(dest ...interface{}) error { +func (rs *Rows) Scan(dest ...any) error { rs.closemu.RLock() if rs.lasterr != nil && rs.lasterr != io.EOF { @@ -3346,7 +3346,7 @@ type Row struct { // If more than one row matches the query, // Scan uses the first row and discards the rest. If no row matches // the query, Scan returns ErrNoRows. -func (r *Row) Scan(dest ...interface{}) error { +func (r *Row) Scan(dest ...any) error { if r.err != nil { return r.err } |
