-
Notifications
You must be signed in to change notification settings - Fork 0
/
sqlite_go18_test.go
49 lines (40 loc) · 972 Bytes
/
sqlite_go18_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// 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.
//go:build go1.8
// +build go1.8
package sqlite // import "modernc.org/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)
}
}