diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-02-09 08:19:58 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-02-09 08:19:58 +0000 |
commit | 94252f4bcc0a3f487b804ce535cb77b8bef4db83 (patch) | |
tree | 7ca86535c5a6b99d4cc432ba5cfddabc5ee4ea16 /libgo/go/database | |
parent | cd6368115dbd75d9187877097c48a0d8d4c04fd4 (diff) | |
download | gcc-94252f4bcc0a3f487b804ce535cb77b8bef4db83.zip gcc-94252f4bcc0a3f487b804ce535cb77b8bef4db83.tar.gz gcc-94252f4bcc0a3f487b804ce535cb77b8bef4db83.tar.bz2 |
libgo: Update to weekly.2012-02-07.
From-SVN: r184034
Diffstat (limited to 'libgo/go/database')
-rw-r--r-- | libgo/go/database/sql/convert.go | 8 | ||||
-rw-r--r-- | libgo/go/database/sql/convert_test.go | 38 | ||||
-rw-r--r-- | libgo/go/database/sql/driver/driver.go | 2 | ||||
-rw-r--r-- | libgo/go/database/sql/fakedb_test.go | 14 | ||||
-rw-r--r-- | libgo/go/database/sql/sql.go | 4 |
5 files changed, 50 insertions, 16 deletions
diff --git a/libgo/go/database/sql/convert.go b/libgo/go/database/sql/convert.go index e80420e..4924ac1 100644 --- a/libgo/go/database/sql/convert.go +++ b/libgo/go/database/sql/convert.go @@ -49,6 +49,11 @@ func convertAssign(dest, src interface{}) error { case *string: *d = string(s) return nil + case *interface{}: + bcopy := make([]byte, len(s)) + copy(bcopy, s) + *d = bcopy + return nil case *[]byte: *d = s return nil @@ -80,6 +85,9 @@ func convertAssign(dest, src interface{}) error { *d = bv.(bool) } return err + case *interface{}: + *d = src + return nil } if scanner, ok := dest.(ScannerInto); ok { diff --git a/libgo/go/database/sql/convert_test.go b/libgo/go/database/sql/convert_test.go index b188864..34ee939 100644 --- a/libgo/go/database/sql/convert_test.go +++ b/libgo/go/database/sql/convert_test.go @@ -18,14 +18,15 @@ type conversionTest struct { s, d interface{} // source and destination // following are used if they're non-zero - wantint int64 - wantuint uint64 - wantstr string - wantf32 float32 - wantf64 float64 - wanttime time.Time - wantbool bool // used if d is of type *bool - wanterr string + wantint int64 + wantuint uint64 + wantstr string + wantf32 float32 + wantf64 float64 + wanttime time.Time + wantbool bool // used if d is of type *bool + wanterr string + wantiface interface{} } // Target variables for scanning into. @@ -41,6 +42,7 @@ var ( scanf32 float32 scanf64 float64 scantime time.Time + scaniface interface{} ) var conversionTests = []conversionTest{ @@ -95,6 +97,14 @@ var conversionTests = []conversionTest{ {s: float64(1.5), d: &scanf32, wantf32: float32(1.5)}, {s: "1.5", d: &scanf32, wantf32: float32(1.5)}, {s: "1.5", d: &scanf64, wantf64: float64(1.5)}, + + // To interface{} + {s: float64(1.5), d: &scaniface, wantiface: float64(1.5)}, + {s: int64(1), d: &scaniface, wantiface: int64(1)}, + {s: "str", d: &scaniface, wantiface: "str"}, + {s: []byte("byteslice"), d: &scaniface, wantiface: []byte("byteslice")}, + {s: true, d: &scaniface, wantiface: true}, + {s: nil, d: &scaniface}, } func intValue(intptr interface{}) int64 { @@ -152,6 +162,18 @@ func TestConversions(t *testing.T) { if !ct.wanttime.IsZero() && !ct.wanttime.Equal(timeValue(ct.d)) { errf("want time %v, got %v", ct.wanttime, timeValue(ct.d)) } + if ifptr, ok := ct.d.(*interface{}); ok { + if !reflect.DeepEqual(ct.wantiface, scaniface) { + errf("want interface %#v, got %#v", ct.wantiface, scaniface) + continue + } + if srcBytes, ok := ct.s.([]byte); ok { + dstBytes := (*ifptr).([]byte) + if &dstBytes[0] == &srcBytes[0] { + errf("copy into interface{} didn't copy []byte data") + } + } + } } } diff --git a/libgo/go/database/sql/driver/driver.go b/libgo/go/database/sql/driver/driver.go index 0cd2562..b930077 100644 --- a/libgo/go/database/sql/driver/driver.go +++ b/libgo/go/database/sql/driver/driver.go @@ -5,7 +5,7 @@ // Package driver defines interfaces to be implemented by database // drivers as used by package sql. // -// Code simply using databases should use package sql. +// Most code should use package sql. // // Drivers only need to be aware of a subset of Go's types. The sql package // will convert all types into one of the following: diff --git a/libgo/go/database/sql/fakedb_test.go b/libgo/go/database/sql/fakedb_test.go index df25023..889e2a2 100644 --- a/libgo/go/database/sql/fakedb_test.go +++ b/libgo/go/database/sql/fakedb_test.go @@ -586,25 +586,25 @@ func converterForType(typ string) driver.ValueConverter { case "bool": return driver.Bool case "nullbool": - return driver.Null{driver.Bool} + return driver.Null{Converter: driver.Bool} case "int32": return driver.Int32 case "string": - return driver.NotNull{driver.String} + return driver.NotNull{Converter: driver.String} case "nullstring": - return driver.Null{driver.String} + return driver.Null{Converter: driver.String} case "int64": // TODO(coopernurse): add type-specific converter - return driver.NotNull{driver.DefaultParameterConverter} + return driver.NotNull{Converter: driver.DefaultParameterConverter} case "nullint64": // TODO(coopernurse): add type-specific converter - return driver.Null{driver.DefaultParameterConverter} + return driver.Null{Converter: driver.DefaultParameterConverter} case "float64": // TODO(coopernurse): add type-specific converter - return driver.NotNull{driver.DefaultParameterConverter} + return driver.NotNull{Converter: driver.DefaultParameterConverter} case "nullfloat64": // TODO(coopernurse): add type-specific converter - return driver.Null{driver.DefaultParameterConverter} + return driver.Null{Converter: driver.DefaultParameterConverter} case "datetime": return driver.DefaultParameterConverter } diff --git a/libgo/go/database/sql/sql.go b/libgo/go/database/sql/sql.go index 34a7652..436d495 100644 --- a/libgo/go/database/sql/sql.go +++ b/libgo/go/database/sql/sql.go @@ -880,6 +880,10 @@ func (rs *Rows) Columns() ([]string, error) { // be modified and held indefinitely. The copy can be avoided by using // an argument of type *RawBytes instead; see the documentation for // RawBytes for restrictions on its use. +// +// If an argument has type *interface{}, Scan copies the value +// provided by the underlying driver without conversion. If the value +// is of type []byte, a copy is made and the caller owns the result. func (rs *Rows) Scan(dest ...interface{}) error { if rs.closed { return errors.New("sql: Rows closed") |