-
Notifications
You must be signed in to change notification settings - Fork 502
/
queries_go110pre_test.go
57 lines (48 loc) · 1.07 KB
/
queries_go110pre_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
50
51
52
53
54
55
56
57
// +build !go1.10
package mssql
import (
"testing"
)
func TestIdentity(t *testing.T) {
conn := open(t)
defer conn.Close()
tx, err := conn.Begin()
if err != nil {
t.Fatal("Begin tran failed", err)
}
defer tx.Rollback()
res, err := tx.Exec("create table #foo (bar int identity, baz int unique)")
if err != nil {
t.Fatal("create table failed")
}
res, err = tx.Exec("insert into #foo (baz) values (1)")
if err != nil {
t.Fatal("insert failed")
}
n, err := res.LastInsertId()
if err != nil {
t.Fatal("last insert id failed")
}
if n != 1 {
t.Error("Expected 1 for identity, got ", n)
}
res, err = tx.Exec("insert into #foo (baz) values (20)")
if err != nil {
t.Fatal("insert failed")
}
n, err = res.LastInsertId()
if err != nil {
t.Fatal("last insert id failed")
}
if n != 2 {
t.Error("Expected 2 for identity, got ", n)
}
res, err = tx.Exec("insert into #foo (baz) values (1)")
if err == nil {
t.Fatal("insert should fail")
}
res, err = tx.Exec("insert into #foo (baz) values (?)", 1)
if err == nil {
t.Fatal("insert should fail")
}
}