-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
oci8_sql_go_113_test.go
84 lines (71 loc) · 1.96 KB
/
oci8_sql_go_113_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// +build go1.13
package oci8
import (
"context"
"testing"
)
// TestStatementCaching tests to ensure statement caching is working
func TestStatementCaching(t *testing.T) {
if TestDisableDatabase {
t.SkipNow()
}
t.Parallel()
var err error
db := testGetDB("?stmt_cache_size=10")
if db == nil {
t.Fatal("db is null")
}
defer func() {
err = db.Close()
if err != nil {
t.Fatal("db close error:", err)
}
}()
ctx, cancel := context.WithTimeout(context.Background(), TestContextTimeout)
conn, err := db.Conn(ctx)
cancel()
// we need to get access to the raw connection so we can access the different fields on the oci8.Stmt
var rawConn *Conn
// NOTE that conn.Raw() is only available with Go >= 1.13
_ = conn.Raw(func(driverConn interface{}) error {
rawConn = driverConn.(*Conn)
return nil
})
ctx, cancel = context.WithTimeout(context.Background(), TestContextTimeout)
stmt, err := rawConn.PrepareContext(ctx, "select ?, ?, ? from dual")
cancel()
if err != nil {
t.Fatal("prepare error:", err)
}
rawStmt := stmt.(*Stmt)
if rawStmt.cacheKey != "select ?, ?, ? from dual" {
err := stmt.Close()
if err != nil {
t.Fatal("stmt close error:", err)
}
t.Fatalf("cacheKey not equal: expected %s, but got %s", "select ?, ?, ? from dual", rawStmt.cacheKey)
}
// closing the statement should put the statement into the cache
err = stmt.Close()
if err != nil {
t.Fatal("stmt close error:", err)
}
ctx, cancel = context.WithTimeout(context.Background(), TestContextTimeout)
stmt, err = rawConn.PrepareContext(ctx, "select ?, ?, ? from dual")
cancel()
if err != nil {
t.Fatal("prepare error:", err)
}
rawStmt = stmt.(*Stmt)
if rawStmt.cacheKey != "select ?, ?, ? from dual" {
err := stmt.Close()
if err != nil {
t.Fatal("stmt close error:", err)
}
t.Fatalf("cacheKey not equal: expected %s, but got %s", "select ?, ?, ? from dual", rawStmt.cacheKey)
}
err = stmt.Close()
if err != nil {
t.Fatal("stmt close error:", err)
}
}