diff options
author | Ian Lance Taylor <iant@golang.org> | 2019-09-06 18:12:46 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2019-09-06 18:12:46 +0000 |
commit | aa8901e9bb0399d2c16f988ba2fe46eb0c0c5d13 (patch) | |
tree | 7e63b06d1eec92beec6997c9d3ab47a5d6a835be /libgo/go/database/sql/driver | |
parent | 920ea3b8ba3164b61ac9490dfdfceb6936eda6dd (diff) | |
download | gcc-aa8901e9bb0399d2c16f988ba2fe46eb0c0c5d13.zip gcc-aa8901e9bb0399d2c16f988ba2fe46eb0c0c5d13.tar.gz gcc-aa8901e9bb0399d2c16f988ba2fe46eb0c0c5d13.tar.bz2 |
libgo: update to Go 1.13beta1 release
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/193497
From-SVN: r275473
Diffstat (limited to 'libgo/go/database/sql/driver')
-rw-r--r-- | libgo/go/database/sql/driver/driver.go | 2 | ||||
-rw-r--r-- | libgo/go/database/sql/driver/types.go | 17 | ||||
-rw-r--r-- | libgo/go/database/sql/driver/types_test.go | 14 |
3 files changed, 31 insertions, 2 deletions
diff --git a/libgo/go/database/sql/driver/driver.go b/libgo/go/database/sql/driver/driver.go index ecc6547..316e7ce 100644 --- a/libgo/go/database/sql/driver/driver.go +++ b/libgo/go/database/sql/driver/driver.go @@ -26,7 +26,7 @@ import ( // time.Time // // If the driver supports cursors, a returned Value may also implement the Rows interface -// in this package. This is used when, for example, when a user selects a cursor +// 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{} diff --git a/libgo/go/database/sql/driver/types.go b/libgo/go/database/sql/driver/types.go index 8b3cb6c..24c3a45 100644 --- a/libgo/go/database/sql/driver/types.go +++ b/libgo/go/database/sql/driver/types.go @@ -38,6 +38,7 @@ type ValueConverter interface { // themselves to a driver Value. type Valuer interface { // Value returns a driver Value. + // Value must not panic. Value() (Value, error) } @@ -179,6 +180,8 @@ func IsValue(v interface{}) bool { switch v.(type) { case []byte, bool, float64, int64, string, time.Time: return true + case decimalDecompose: + return true } return false } @@ -235,7 +238,8 @@ func (defaultConverter) ConvertValue(v interface{}) (Value, error) { return v, nil } - if vr, ok := v.(Valuer); ok { + switch vr := v.(type) { + case Valuer: sv, err := callValuerValue(vr) if err != nil { return nil, err @@ -244,6 +248,10 @@ func (defaultConverter) ConvertValue(v interface{}) (Value, error) { return nil, fmt.Errorf("non-Value type %T returned from Value", sv) } return sv, nil + + // For now, continue to prefer the Valuer interface over the decimal decompose interface. + case decimalDecompose: + return vr, nil } rv := reflect.ValueOf(v) @@ -280,3 +288,10 @@ func (defaultConverter) ConvertValue(v interface{}) (Value, error) { } return nil, fmt.Errorf("unsupported type %T, a %s", v, rv.Kind()) } + +type decimalDecompose interface { + // Decompose returns the internal decimal state into parts. + // If the provided buf has sufficient capacity, buf may be returned as the coefficient with + // the value set and length set as appropriate. + Decompose(buf []byte) (form byte, negative bool, coefficient []byte, exponent int32) +} diff --git a/libgo/go/database/sql/driver/types_test.go b/libgo/go/database/sql/driver/types_test.go index 0379bf8..4c2996d 100644 --- a/libgo/go/database/sql/driver/types_test.go +++ b/libgo/go/database/sql/driver/types_test.go @@ -57,6 +57,7 @@ var valueConverterTests = []valueConverterTest{ {DefaultParameterConverter, bs{1}, []byte{1}, ""}, {DefaultParameterConverter, s("a"), "a", ""}, {DefaultParameterConverter, is{1}, nil, "unsupported type driver.is, a slice of int"}, + {DefaultParameterConverter, dec{exponent: -6}, dec{exponent: -6}, ""}, } func TestValueConverters(t *testing.T) { @@ -79,3 +80,16 @@ func TestValueConverters(t *testing.T) { } } } + +type dec struct { + form byte + neg bool + coefficient [16]byte + exponent int32 +} + +func (d dec) Decompose(buf []byte) (form byte, negative bool, coefficient []byte, exponent int32) { + coef := make([]byte, 16) + copy(coef, d.coefficient[:]) + return d.form, d.neg, coef, d.exponent +} |