aboutsummaryrefslogtreecommitdiff
path: root/sqlite_go18_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'sqlite_go18_test.go')
-rw-r--r--sqlite_go18_test.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/sqlite_go18_test.go b/sqlite_go18_test.go
new file mode 100644
index 0000000..d558488
--- /dev/null
+++ b/sqlite_go18_test.go
@@ -0,0 +1,48 @@
+// Copyright 2017 The Sqlite Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//+build go1.8
+
+package sqlite
+
+import (
+ "database/sql"
+ "os"
+ "reflect"
+ "testing"
+)
+
+func TestNamedParameters(t *testing.T) {
+ dir, db := tempDB(t)
+ defer func() {
+ db.Close()
+ os.RemoveAll(dir)
+ }()
+
+ _, err := db.Exec(`
+ create table t(s1 varchar(32), s2 varchar(32), s3 varchar(32), s4 varchar(32));
+ insert into t values(?, @aa, $aa, @bb);
+ `, "1", sql.Named("aa", "one"), sql.Named("bb", "two"))
+
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ rows, err := db.Query("select * from t")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ rec := make([]string, 4)
+ for rows.Next() {
+ if err := rows.Scan(&rec[0], &rec[1], &rec[2], &rec[3]); err != nil {
+ t.Fatal(err)
+ }
+ }
+
+ w := []string{"1", "one", "one", "two"}
+ if !reflect.DeepEqual(rec, w) {
+ t.Fatal(rec, w)
+ }
+}