aboutsummaryrefslogtreecommitdiff
path: root/src/database/sql/sql_test.go
diff options
context:
space:
mode:
authorDaniel Theophanes <kardianos@gmail.com>2017-03-30 16:03:03 -0700
committerDaniel Theophanes <kardianos@gmail.com>2017-03-31 05:02:02 +0000
commit5a45a157f2e94cb3fec38a3be8afa3bffd800067 (patch)
tree87943651501f40c7f810f2844e45ebc9f1c49716 /src/database/sql/sql_test.go
parentbfd8093c969d2b7b7e1e60866031508ea6e462d6 (diff)
downloadgo-5a45a157f2e94cb3fec38a3be8afa3bffd800067.tar.xz
database/sql: support scanning into user defined string types
User defined numeric types such as "type Int int64" have been able to be scanned into without a custom scanner by using the reflect scan code path used to convert between various numeric types. Add in a path for string types for symmetry and least surprise. Fixes #18101 Change-Id: I00553bcf021ffe6d95047eca0067ee94b54ff501 Reviewed-on: https://go-review.googlesource.com/39031 Run-TryBot: Daniel Theophanes <kardianos@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/database/sql/sql_test.go')
-rw-r--r--src/database/sql/sql_test.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/database/sql/sql_test.go b/src/database/sql/sql_test.go
index 4c1adf51b6..f511aa4ac3 100644
--- a/src/database/sql/sql_test.go
+++ b/src/database/sql/sql_test.go
@@ -3155,6 +3155,24 @@ func TestPing(t *testing.T) {
}
}
+// Issue 18101.
+func TestTypedString(t *testing.T) {
+ db := newTestDB(t, "people")
+ defer closeDB(t, db)
+
+ type Str string
+ var scanned Str
+
+ err := db.QueryRow("SELECT|people|name|name=?", "Alice").Scan(&scanned)
+ if err != nil {
+ t.Fatal(err)
+ }
+ expected := Str("Alice")
+ if scanned != expected {
+ t.Errorf("expected %+v, got %+v", expected, scanned)
+ }
+}
+
func BenchmarkConcurrentDBExec(b *testing.B) {
b.ReportAllocs()
ct := new(concurrentDBExecTest)