diff options
Diffstat (limited to 'src/database/sql')
| -rw-r--r-- | src/database/sql/convert.go | 14 | ||||
| -rw-r--r-- | src/database/sql/convert_test.go | 42 | ||||
| -rw-r--r-- | src/database/sql/driver/driver.go | 2 | ||||
| -rw-r--r-- | src/database/sql/driver/types.go | 18 | ||||
| -rw-r--r-- | src/database/sql/driver/types_test.go | 4 | ||||
| -rw-r--r-- | src/database/sql/fakedb_test.go | 32 | ||||
| -rw-r--r-- | src/database/sql/sql.go | 96 | ||||
| -rw-r--r-- | src/database/sql/sql_test.go | 40 |
8 files changed, 124 insertions, 124 deletions
diff --git a/src/database/sql/convert.go b/src/database/sql/convert.go index c0997b7fc5..4d9d070137 100644 --- a/src/database/sql/convert.go +++ b/src/database/sql/convert.go @@ -104,7 +104,7 @@ func defaultCheckNamedValue(nv *driver.NamedValue) (err error) { // The statement ds may be nil, if no statement is available. // // ci must be locked. -func driverArgsConnLocked(ci driver.Conn, ds *driverStmt, args []interface{}) ([]driver.NamedValue, error) { +func driverArgsConnLocked(ci driver.Conn, ds *driverStmt, args []any) ([]driver.NamedValue, error) { nvargs := make([]driver.NamedValue, len(args)) // -1 means the driver doesn't know how to count the number of @@ -207,7 +207,7 @@ func driverArgsConnLocked(ci driver.Conn, ds *driverStmt, args []interface{}) ([ // convertAssign is the same as convertAssignRows, but without the optional // rows argument. -func convertAssign(dest, src interface{}) error { +func convertAssign(dest, src any) error { return convertAssignRows(dest, src, nil) } @@ -216,7 +216,7 @@ func convertAssign(dest, src interface{}) error { // dest should be a pointer type. If rows is passed in, the rows will // be used as the parent for any cursor values converted from a // driver.Rows to a *Rows. -func convertAssignRows(dest, src interface{}, rows *Rows) error { +func convertAssignRows(dest, src any, rows *Rows) error { // Common cases, without reflect. switch s := src.(type) { case string: @@ -248,7 +248,7 @@ func convertAssignRows(dest, src interface{}, rows *Rows) error { } *d = string(s) return nil - case *interface{}: + case *any: if d == nil { return errNilPtr } @@ -295,7 +295,7 @@ func convertAssignRows(dest, src interface{}, rows *Rows) error { } case nil: switch d := dest.(type) { - case *interface{}: + case *any: if d == nil { return errNilPtr } @@ -376,7 +376,7 @@ func convertAssignRows(dest, src interface{}, rows *Rows) error { *d = bv.(bool) } return err - case *interface{}: + case *any: *d = src return nil } @@ -495,7 +495,7 @@ func cloneBytes(b []byte) []byte { return c } -func asString(src interface{}) string { +func asString(src any) string { switch v := src.(type) { case string: return v diff --git a/src/database/sql/convert_test.go b/src/database/sql/convert_test.go index 400da7ea57..6d09fa1eae 100644 --- a/src/database/sql/convert_test.go +++ b/src/database/sql/convert_test.go @@ -25,7 +25,7 @@ type ( ) type conversionTest struct { - s, d interface{} // source and destination + s, d any // source and destination // following are used if they're non-zero wantint int64 @@ -38,7 +38,7 @@ type conversionTest struct { wanttime time.Time wantbool bool // used if d is of type *bool wanterr string - wantiface interface{} + wantiface any wantptr *int64 // if non-nil, *d's pointed value must be equal to *wantptr wantnil bool // if true, *d must be *int64(nil) wantusrdef userDefined @@ -58,7 +58,7 @@ var ( scanf64 float64 scantime time.Time scanptr *int64 - scaniface interface{} + scaniface any ) func conversionTests() []conversionTest { @@ -161,7 +161,7 @@ func conversionTests() []conversionTest { {s: "1.5", d: &scanf64, wantf64: float64(1.5)}, // Pointers - {s: interface{}(nil), d: &scanptr, wantnil: true}, + {s: any(nil), d: &scanptr, wantnil: true}, {s: int64(42), d: &scanptr, wantptr: &answer}, // To interface{} @@ -185,27 +185,27 @@ func conversionTests() []conversionTest { } } -func intPtrValue(intptr interface{}) interface{} { +func intPtrValue(intptr any) any { return reflect.Indirect(reflect.Indirect(reflect.ValueOf(intptr))).Int() } -func intValue(intptr interface{}) int64 { +func intValue(intptr any) int64 { return reflect.Indirect(reflect.ValueOf(intptr)).Int() } -func uintValue(intptr interface{}) uint64 { +func uintValue(intptr any) uint64 { return reflect.Indirect(reflect.ValueOf(intptr)).Uint() } -func float64Value(ptr interface{}) float64 { +func float64Value(ptr any) float64 { return *(ptr.(*float64)) } -func float32Value(ptr interface{}) float32 { +func float32Value(ptr any) float32 { return *(ptr.(*float32)) } -func timeValue(ptr interface{}) time.Time { +func timeValue(ptr any) time.Time { return *(ptr.(*time.Time)) } @@ -216,7 +216,7 @@ func TestConversions(t *testing.T) { if err != nil { errstr = err.Error() } - errf := func(format string, args ...interface{}) { + errf := func(format string, args ...any) { base := fmt.Sprintf("convertAssign #%d: for %v (%T) -> %T, ", n, ct.s, ct.s, ct.d) t.Errorf(base+format, args...) } @@ -260,7 +260,7 @@ func TestConversions(t *testing.T) { errf("want pointer to %v, got %v", *ct.wantptr, intPtrValue(ct.d)) } } - if ifptr, ok := ct.d.(*interface{}); ok { + if ifptr, ok := ct.d.(*any); ok { if !reflect.DeepEqual(ct.wantiface, scaniface) { errf("want interface %#v, got %#v", ct.wantiface, scaniface) continue @@ -301,7 +301,7 @@ func TestNullString(t *testing.T) { type valueConverterTest struct { c driver.ValueConverter - in, out interface{} + in, out any err string } @@ -335,7 +335,7 @@ func TestValueConverters(t *testing.T) { func TestRawBytesAllocs(t *testing.T) { var tests = []struct { name string - in interface{} + in any want string }{ {"uint64", uint64(12345678), "12345678"}, @@ -355,7 +355,7 @@ func TestRawBytesAllocs(t *testing.T) { } buf := make(RawBytes, 10) - test := func(name string, in interface{}, want string) { + test := func(name string, in any, want string) { if err := convertAssign(&buf, in); err != nil { t.Fatalf("%s: convertAssign = %v", name, err) } @@ -430,11 +430,11 @@ func TestDriverArgs(t *testing.T) { var nilValuerPPtr *Valuer_P var nilStrPtr *string tests := []struct { - args []interface{} + args []any want []driver.NamedValue }{ 0: { - args: []interface{}{Valuer_V("foo")}, + args: []any{Valuer_V("foo")}, want: []driver.NamedValue{ { Ordinal: 1, @@ -443,7 +443,7 @@ func TestDriverArgs(t *testing.T) { }, }, 1: { - args: []interface{}{nilValuerVPtr}, + args: []any{nilValuerVPtr}, want: []driver.NamedValue{ { Ordinal: 1, @@ -452,7 +452,7 @@ func TestDriverArgs(t *testing.T) { }, }, 2: { - args: []interface{}{nilValuerPPtr}, + args: []any{nilValuerPPtr}, want: []driver.NamedValue{ { Ordinal: 1, @@ -461,7 +461,7 @@ func TestDriverArgs(t *testing.T) { }, }, 3: { - args: []interface{}{"plain-str"}, + args: []any{"plain-str"}, want: []driver.NamedValue{ { Ordinal: 1, @@ -470,7 +470,7 @@ func TestDriverArgs(t *testing.T) { }, }, 4: { - args: []interface{}{nilStrPtr}, + args: []any{nilStrPtr}, want: []driver.NamedValue{ { Ordinal: 1, diff --git a/src/database/sql/driver/driver.go b/src/database/sql/driver/driver.go index ea1de5a8fb..5342315d12 100644 --- a/src/database/sql/driver/driver.go +++ b/src/database/sql/driver/driver.go @@ -58,7 +58,7 @@ import ( // in this package. This is used, for example, when a user selects a cursor // such as "select cursor(select * from my_table) from dual". If the Rows // from the select is closed, the cursor Rows will also be closed. -type Value interface{} +type Value any // NamedValue holds both the value name and value. type NamedValue struct { diff --git a/src/database/sql/driver/types.go b/src/database/sql/driver/types.go index 3337c2e0bc..506ce6c2cd 100644 --- a/src/database/sql/driver/types.go +++ b/src/database/sql/driver/types.go @@ -29,7 +29,7 @@ import ( // to a user's type in a scan. type ValueConverter interface { // ConvertValue converts a value to a driver Value. - ConvertValue(v interface{}) (Value, error) + ConvertValue(v any) (Value, error) } // Valuer is the interface providing the Value method. @@ -60,7 +60,7 @@ var _ ValueConverter = boolType{} func (boolType) String() string { return "Bool" } -func (boolType) ConvertValue(src interface{}) (Value, error) { +func (boolType) ConvertValue(src any) (Value, error) { switch s := src.(type) { case bool: return s, nil @@ -105,7 +105,7 @@ type int32Type struct{} var _ ValueConverter = int32Type{} -func (int32Type) ConvertValue(v interface{}) (Value, error) { +func (int32Type) ConvertValue(v any) (Value, error) { rv := reflect.ValueOf(v) switch rv.Kind() { case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: @@ -138,7 +138,7 @@ var String stringType type stringType struct{} -func (stringType) ConvertValue(v interface{}) (Value, error) { +func (stringType) ConvertValue(v any) (Value, error) { switch v.(type) { case string, []byte: return v, nil @@ -152,7 +152,7 @@ type Null struct { Converter ValueConverter } -func (n Null) ConvertValue(v interface{}) (Value, error) { +func (n Null) ConvertValue(v any) (Value, error) { if v == nil { return nil, nil } @@ -165,7 +165,7 @@ type NotNull struct { Converter ValueConverter } -func (n NotNull) ConvertValue(v interface{}) (Value, error) { +func (n NotNull) ConvertValue(v any) (Value, error) { if v == nil { return nil, fmt.Errorf("nil value not allowed") } @@ -173,7 +173,7 @@ func (n NotNull) ConvertValue(v interface{}) (Value, error) { } // IsValue reports whether v is a valid Value parameter type. -func IsValue(v interface{}) bool { +func IsValue(v any) bool { if v == nil { return true } @@ -188,7 +188,7 @@ func IsValue(v interface{}) bool { // IsScanValue is equivalent to IsValue. // It exists for compatibility. -func IsScanValue(v interface{}) bool { +func IsScanValue(v any) bool { return IsValue(v) } @@ -233,7 +233,7 @@ func callValuerValue(vr Valuer) (v Value, err error) { return vr.Value() } -func (defaultConverter) ConvertValue(v interface{}) (Value, error) { +func (defaultConverter) ConvertValue(v any) (Value, error) { if IsValue(v) { return v, nil } diff --git a/src/database/sql/driver/types_test.go b/src/database/sql/driver/types_test.go index 4c2996da85..80e5e05469 100644 --- a/src/database/sql/driver/types_test.go +++ b/src/database/sql/driver/types_test.go @@ -12,8 +12,8 @@ import ( type valueConverterTest struct { c ValueConverter - in interface{} - out interface{} + in any + out any err string } diff --git a/src/database/sql/fakedb_test.go b/src/database/sql/fakedb_test.go index 34e97e012b..8f953f6cb6 100644 --- a/src/database/sql/fakedb_test.go +++ b/src/database/sql/fakedb_test.go @@ -126,7 +126,7 @@ func (t *table) columnIndex(name string) int { } type row struct { - cols []interface{} // must be same size as its table colname + coltype + cols []any // must be same size as its table colname + coltype } type memToucher interface { @@ -198,10 +198,10 @@ type fakeStmt struct { closed bool - colName []string // used by CREATE, INSERT, SELECT (selected columns) - colType []string // used by CREATE - colValue []interface{} // used by INSERT (mix of strings and "?" for bound params) - placeholders int // used by INSERT/SELECT: number of ? params + colName []string // used by CREATE, INSERT, SELECT (selected columns) + colType []string // used by CREATE + colValue []any // used by INSERT (mix of strings and "?" for bound params) + placeholders int // used by INSERT/SELECT: number of ? params whereCol []boundCol // used by SELECT (all placeholders) @@ -504,7 +504,7 @@ func (c *fakeConn) QueryContext(ctx context.Context, query string, args []driver return nil, driver.ErrSkip } -func errf(msg string, args ...interface{}) error { +func errf(msg string, args ...any) error { return errors.New("fakedb: " + fmt.Sprintf(msg, args...)) } @@ -586,7 +586,7 @@ func (c *fakeConn) prepareInsert(ctx context.Context, stmt *fakeStmt, parts []st stmt.colName = append(stmt.colName, column) if !strings.HasPrefix(value, "?") { - var subsetVal interface{} + var subsetVal any // Convert to driver subset type switch ctype { case "string": @@ -829,9 +829,9 @@ func (s *fakeStmt) execInsert(args []driver.NamedValue, doInsert bool) (driver.R t.mu.Lock() defer t.mu.Unlock() - var cols []interface{} + var cols []any if doInsert { - cols = make([]interface{}, len(t.colname)) + cols = make([]any, len(t.colname)) } argPos := 0 for n, colname := range s.colName { @@ -839,7 +839,7 @@ func (s *fakeStmt) execInsert(args []driver.NamedValue, doInsert bool) (driver.R if colidx == -1 { return nil, fmt.Errorf("fakedb: column %q doesn't exist or dropped since prepared statement was created", colname) } - var val interface{} + var val any if strvalue, ok := s.colValue[n].(string); ok && strings.HasPrefix(strvalue, "?") { if strvalue == "?" { val = args[argPos].Value @@ -930,7 +930,7 @@ func (s *fakeStmt) QueryContext(ctx context.Context, args []driver.NamedValue) ( rows: [][]*row{ { { - cols: []interface{}{ + cols: []any{ txStatus, }, }, @@ -980,7 +980,7 @@ func (s *fakeStmt) QueryContext(ctx context.Context, args []driver.NamedValue) ( // lazy hack to avoid sprintf %v on a []byte tcol = string(bs) } - var argValue interface{} + var argValue any if wcol.Placeholder == "?" { argValue = args[wcol.Ordinal-1].Value } else { @@ -996,7 +996,7 @@ func (s *fakeStmt) QueryContext(ctx context.Context, args []driver.NamedValue) ( continue rows } } - mrow := &row{cols: make([]interface{}, len(s.colName))} + mrow := &row{cols: make([]any, len(s.colName))} for seli, name := range s.colName { mrow.cols[seli] = trow.cols[colIdx[name]] } @@ -1174,7 +1174,7 @@ func (rc *rowsCursor) NextResultSet() error { // type fakeDriverString struct{} -func (fakeDriverString) ConvertValue(v interface{}) (driver.Value, error) { +func (fakeDriverString) ConvertValue(v any) (driver.Value, error) { switch c := v.(type) { case string, []byte: return v, nil @@ -1189,7 +1189,7 @@ func (fakeDriverString) ConvertValue(v interface{}) (driver.Value, error) { type anyTypeConverter struct{} -func (anyTypeConverter) ConvertValue(v interface{}) (driver.Value, error) { +func (anyTypeConverter) ConvertValue(v any) (driver.Value, error) { return v, nil } @@ -1260,7 +1260,7 @@ func colTypeToReflectType(typ string) reflect.Type { case "datetime": return reflect.TypeOf(time.Time{}) case "any": - return reflect.TypeOf(new(interface{})).Elem() + return reflect.TypeOf(new(any)).Elem() } panic("invalid fakedb column type of " + typ) } 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 } diff --git a/src/database/sql/sql_test.go b/src/database/sql/sql_test.go index b887b40d71..1bb9afc407 100644 --- a/src/database/sql/sql_test.go +++ b/src/database/sql/sql_test.go @@ -135,7 +135,7 @@ func TestDriverPanic(t *testing.T) { exec(t, db, "WIPE") // check not deadlocked } -func exec(t testing.TB, db *DB, query string, args ...interface{}) { +func exec(t testing.TB, db *DB, query string, args ...any) { t.Helper() _, err := db.Exec(query, args...) if err != nil { @@ -743,7 +743,7 @@ func TestRowsColumnTypes(t *testing.T) { } types[i] = st } - values := make([]interface{}, len(tt)) + values := make([]any, len(tt)) for i := range values { values[i] = reflect.New(types[i]).Interface() } @@ -1006,23 +1006,23 @@ func TestExec(t *testing.T) { defer stmt.Close() type execTest struct { - args []interface{} + args []any wantErr string } execTests := []execTest{ // Okay: - {[]interface{}{"Brad", 31}, ""}, - {[]interface{}{"Brad", int64(31)}, ""}, - {[]interface{}{"Bob", "32"}, ""}, - {[]interface{}{7, 9}, ""}, + {[]any{"Brad", 31}, ""}, + {[]any{"Brad", int64(31)}, ""}, + {[]any{"Bob", "32"}, ""}, + {[]any{7, 9}, ""}, // Invalid conversions: - {[]interface{}{"Brad", int64(0xFFFFFFFF)}, "sql: converting argument $2 type: sql/driver: value 4294967295 overflows int32"}, - {[]interface{}{"Brad", "strconv fail"}, `sql: converting argument $2 type: sql/driver: value "strconv fail" can't be converted to int32`}, + {[]any{"Brad", int64(0xFFFFFFFF)}, "sql: converting argument $2 type: sql/driver: value 4294967295 overflows int32"}, + {[]any{"Brad", "strconv fail"}, `sql: converting argument $2 type: sql/driver: value "strconv fail" can't be converted to int32`}, // Wrong number of args: - {[]interface{}{}, "sql: expected 2 arguments, got 0"}, - {[]interface{}{1, 2, 3}, "sql: expected 2 arguments, got 3"}, + {[]any{}, "sql: expected 2 arguments, got 0"}, + {[]any{1, 2, 3}, "sql: expected 2 arguments, got 3"}, } for n, et := range execTests { _, err := stmt.Exec(et.args...) @@ -1409,7 +1409,7 @@ func TestConnRaw(t *testing.T) { defer conn.Close() sawFunc := false - err = conn.Raw(func(dc interface{}) error { + err = conn.Raw(func(dc any) error { sawFunc = true if _, ok := dc.(*fakeConn); !ok { return fmt.Errorf("got %T want *fakeConn", dc) @@ -1436,7 +1436,7 @@ func TestConnRaw(t *testing.T) { t.Fatal("expected connection to be closed after panic") } }() - err = conn.Raw(func(dc interface{}) error { + err = conn.Raw(func(dc any) error { panic("Conn.Raw panic should return an error") }) t.Fatal("expected panic from Raw func") @@ -1495,7 +1495,7 @@ func TestInvalidNilValues(t *testing.T) { tests := []struct { name string - input interface{} + input any expectedError string }{ { @@ -1593,7 +1593,7 @@ func TestConnIsValid(t *testing.T) { t.Fatal(err) } - err = c.Raw(func(raw interface{}) error { + err = c.Raw(func(raw any) error { dc := raw.(*fakeConn) dc.stickyBad = true return nil @@ -1772,9 +1772,9 @@ func TestIssue6651(t *testing.T) { } type nullTestRow struct { - nullParam interface{} - notNullParam interface{} - scanNullVal interface{} + nullParam any + notNullParam any + scanNullVal any } type nullTestSpec struct { @@ -4129,7 +4129,7 @@ func TestNamedValueChecker(t *testing.T) { t.Fatal("select", err) } - list := []struct{ got, want interface{} }{ + list := []struct{ got, want any }{ {o1, "from-server"}, {dec1, decimalInt{123}}, {str1, "hello"}, @@ -4318,7 +4318,7 @@ type alwaysErrScanner struct{} var errTestScanWrap = errors.New("errTestScanWrap") -func (alwaysErrScanner) Scan(interface{}) error { +func (alwaysErrScanner) Scan(any) error { return errTestScanWrap } |
