diff options
| author | Brad Fitzpatrick <bradfitz@golang.org> | 2012-01-13 15:45:05 -0800 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2012-01-13 15:45:05 -0800 |
| commit | bf734d62d8210b3030757522c3e9ff581457daa4 (patch) | |
| tree | a9eddad664995399ceba9632174a701c3526e1be /src/pkg/exp/sql/driver | |
| parent | a08c1960dd8d5915029bf9f07fffd5d8842cd839 (diff) | |
| download | go-bf734d62d8210b3030757522c3e9ff581457daa4.tar.xz | |
exp/sql: add time.Time support
Fixes #2694
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5541057
Diffstat (limited to 'src/pkg/exp/sql/driver')
| -rw-r--r-- | src/pkg/exp/sql/driver/driver.go | 1 | ||||
| -rw-r--r-- | src/pkg/exp/sql/driver/types.go | 7 | ||||
| -rw-r--r-- | src/pkg/exp/sql/driver/types_test.go | 4 |
3 files changed, 10 insertions, 2 deletions
diff --git a/src/pkg/exp/sql/driver/driver.go b/src/pkg/exp/sql/driver/driver.go index f0bcca2910..0cd2562d68 100644 --- a/src/pkg/exp/sql/driver/driver.go +++ b/src/pkg/exp/sql/driver/driver.go @@ -16,6 +16,7 @@ // nil // []byte // string [*] everywhere except from Rows.Next. +// time.Time // package driver diff --git a/src/pkg/exp/sql/driver/types.go b/src/pkg/exp/sql/driver/types.go index 086b529c84..0ee278856d 100644 --- a/src/pkg/exp/sql/driver/types.go +++ b/src/pkg/exp/sql/driver/types.go @@ -8,6 +8,7 @@ import ( "fmt" "reflect" "strconv" + "time" ) // ValueConverter is the interface providing the ConvertValue method. @@ -143,9 +144,10 @@ func (stringType) ConvertValue(v interface{}) (interface{}, error) { // bool // nil // []byte +// time.Time // string // -// This is the ame list as IsScanSubsetType, with the addition of +// This is the same list as IsScanSubsetType, with the addition of // string. func IsParameterSubsetType(v interface{}) bool { if IsScanSubsetType(v) { @@ -165,6 +167,7 @@ func IsParameterSubsetType(v interface{}) bool { // bool // nil // []byte +// time.Time // // This is the same list as IsParameterSubsetType, without string. func IsScanSubsetType(v interface{}) bool { @@ -172,7 +175,7 @@ func IsScanSubsetType(v interface{}) bool { return true } switch v.(type) { - case int64, float64, []byte, bool: + case int64, float64, []byte, bool, time.Time: return true } return false diff --git a/src/pkg/exp/sql/driver/types_test.go b/src/pkg/exp/sql/driver/types_test.go index 4b049e26e5..966bc6b458 100644 --- a/src/pkg/exp/sql/driver/types_test.go +++ b/src/pkg/exp/sql/driver/types_test.go @@ -7,6 +7,7 @@ package driver import ( "reflect" "testing" + "time" ) type valueConverterTest struct { @@ -16,6 +17,8 @@ type valueConverterTest struct { err string } +var now = time.Now() + var valueConverterTests = []valueConverterTest{ {Bool, "true", true, ""}, {Bool, "True", true, ""}, @@ -33,6 +36,7 @@ var valueConverterTests = []valueConverterTest{ {Bool, uint16(0), false, ""}, {c: Bool, in: "foo", err: "sql/driver: couldn't convert \"foo\" into type bool"}, {c: Bool, in: 2, err: "sql/driver: couldn't convert 2 into type bool"}, + {DefaultParameterConverter, now, now, ""}, } func TestValueConverters(t *testing.T) { |
