diff options
author | Philip O'Toole <philip.otoole@yahoo.com> | 2017-06-17 12:02:47 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-17 12:02:47 -0700 |
commit | b951516ea086ff8c8a97eff7a59f2b95458b0a1c (patch) | |
tree | 035930342ee0510d83ab8ee47e4068bdc50247c3 /sqlite3_go18_test.go | |
parent | Merge pull request #1 from mattn/master (diff) | |
parent | Merge pull request #425 from xxr3376/empty-bytes (diff) | |
download | golite-b951516ea086ff8c8a97eff7a59f2b95458b0a1c.tar.gz golite-b951516ea086ff8c8a97eff7a59f2b95458b0a1c.tar.xz |
Merge pull request #2 from mattn/master
Merge upstream
Diffstat (limited to 'sqlite3_go18_test.go')
-rw-r--r-- | sqlite3_go18_test.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/sqlite3_go18_test.go b/sqlite3_go18_test.go new file mode 100644 index 0000000..f076b81 --- /dev/null +++ b/sqlite3_go18_test.go @@ -0,0 +1,50 @@ +// Copyright (C) 2014 Yasuhiro Matsumoto <mattn.jp@gmail.com>. +// +// Use of this source code is governed by an MIT-style +// license that can be found in the LICENSE file. + +// +build go1.8 + +package sqlite3 + +import ( + "database/sql" + "os" + "testing" +) + +func TestNamedParams(t *testing.T) { + tempFilename := TempFilename(t) + defer os.Remove(tempFilename) + db, err := sql.Open("sqlite3", tempFilename) + if err != nil { + t.Fatal("Failed to open database:", err) + } + defer db.Close() + + _, err = db.Exec(` + create table foo (id integer, name text, extra text); + `) + if err != nil { + t.Error("Failed to call db.Query:", err) + } + + _, err = db.Exec(`insert into foo(id, name, extra) values(:id, :name, :name)`, sql.Named("name", "foo"), sql.Named("id", 1)) + if err != nil { + t.Error("Failed to call db.Exec:", err) + } + + row := db.QueryRow(`select id, extra from foo where id = :id and extra = :extra`, sql.Named("id", 1), sql.Named("extra", "foo")) + if row == nil { + t.Error("Failed to call db.QueryRow") + } + var id int + var extra string + err = row.Scan(&id, &extra) + if err != nil { + t.Error("Failed to db.Scan:", err) + } + if id != 1 || extra != "foo" { + t.Error("Failed to db.QueryRow: not matched results") + } +} |