forked from opencensus-integrations/ocsql
-
Notifications
You must be signed in to change notification settings - Fork 1
/
driver_go1.9.go
145 lines (136 loc) · 3.53 KB
/
driver_go1.9.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// +build go1.9,!go1.10
package ocsql
import (
"database/sql"
"database/sql/driver"
)
var errConnDone = sql.ErrConnDone
// ocDriver implements driver.Driver
type ocDriver struct {
parent driver.Driver
options TraceOptions
}
func wrapDriver(d driver.Driver, o TraceOptions) driver.Driver {
return ocDriver{parent: d, options: o}
}
func wrapConn(parent driver.Conn, options TraceOptions) driver.Conn {
var (
n, hasNameValueChecker = parent.(driver.NamedValueChecker)
)
c := &ocConn{parent: parent, options: options}
if hasNameValueChecker {
return struct {
conn
driver.NamedValueChecker
}{c, n}
}
return c
}
func wrapStmt(stmt driver.Stmt, query string, options TraceOptions) driver.Stmt {
var (
_, hasExeCtx = stmt.(driver.StmtExecContext)
_, hasQryCtx = stmt.(driver.StmtQueryContext)
c, hasColConv = stmt.(driver.ColumnConverter)
n, hasNamValChk = stmt.(driver.NamedValueChecker)
)
s := ocStmt{parent: stmt, query: query, options: options}
switch {
case !hasExeCtx && !hasQryCtx && !hasColConv && !hasNamValChk:
return struct {
driver.Stmt
}{s}
case !hasExeCtx && hasQryCtx && !hasColConv && !hasNamValChk:
return struct {
driver.Stmt
driver.StmtQueryContext
}{s, s}
case hasExeCtx && !hasQryCtx && !hasColConv && !hasNamValChk:
return struct {
driver.Stmt
driver.StmtExecContext
}{s, s}
case hasExeCtx && hasQryCtx && !hasColConv && !hasNamValChk:
return struct {
driver.Stmt
driver.StmtExecContext
driver.StmtQueryContext
}{s, s, s}
case !hasExeCtx && !hasQryCtx && hasColConv && !hasNamValChk:
return struct {
driver.Stmt
driver.ColumnConverter
}{s, c}
case !hasExeCtx && hasQryCtx && hasColConv && !hasNamValChk:
return struct {
driver.Stmt
driver.StmtQueryContext
driver.ColumnConverter
}{s, s, c}
case hasExeCtx && !hasQryCtx && hasColConv && !hasNamValChk:
return struct {
driver.Stmt
driver.StmtExecContext
driver.ColumnConverter
}{s, s, c}
case hasExeCtx && hasQryCtx && hasColConv && !hasNamValChk:
return struct {
driver.Stmt
driver.StmtExecContext
driver.StmtQueryContext
driver.ColumnConverter
}{s, s, s, c}
case !hasExeCtx && !hasQryCtx && !hasColConv && hasNamValChk:
return struct {
driver.Stmt
driver.NamedValueChecker
}{s, n}
case !hasExeCtx && hasQryCtx && !hasColConv && hasNamValChk:
return struct {
driver.Stmt
driver.StmtQueryContext
driver.NamedValueChecker
}{s, s, n}
case hasExeCtx && !hasQryCtx && !hasColConv && hasNamValChk:
return struct {
driver.Stmt
driver.StmtExecContext
driver.NamedValueChecker
}{s, s, n}
case hasExeCtx && hasQryCtx && !hasColConv && hasNamValChk:
return struct {
driver.Stmt
driver.StmtExecContext
driver.StmtQueryContext
driver.NamedValueChecker
}{s, s, s, n}
case !hasExeCtx && !hasQryCtx && hasColConv && hasNamValChk:
return struct {
driver.Stmt
driver.ColumnConverter
driver.NamedValueChecker
}{s, c, n}
case !hasExeCtx && hasQryCtx && hasColConv && hasNamValChk:
return struct {
driver.Stmt
driver.StmtQueryContext
driver.ColumnConverter
driver.NamedValueChecker
}{s, s, c, n}
case hasExeCtx && !hasQryCtx && hasColConv && hasNamValChk:
return struct {
driver.Stmt
driver.StmtExecContext
driver.ColumnConverter
driver.NamedValueChecker
}{s, s, c, n}
case hasExeCtx && hasQryCtx && hasColConv && hasNamValChk:
return struct {
driver.Stmt
driver.StmtExecContext
driver.StmtQueryContext
driver.ColumnConverter
driver.NamedValueChecker
}{s, s, s, c, n}
}
panic("unreachable")
}