forked from pingcap/tidb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmisc.go
152 lines (130 loc) · 3.81 KB
/
misc.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
146
147
148
149
150
151
152
package ast
var (
_ Node = &ExplainStmt{}
_ Node = &PreparedStmt{}
_ Node = &DeallocateStmt{}
_ Node = &ExecuteStmt{}
_ Node = &BeginStmt{}
_ Node = &CommitStmt{}
_ Node = &RollbackStmt{}
_ Node = &VariableAssignment{}
_ Node = &SetStmt{}
)
// AuthOption is used for parsing create use statement.
type AuthOption struct {
// AuthString/HashString can be empty, so we need to decide which one to use.
ByAuthString bool
AuthString string
HashString string
// TODO: support auth_plugin
}
// ExplainStmt is a statement to provide information about how is SQL statement executed
// or get columns information in a table.
// See: https://dev.mysql.com/doc/refman/5.7/en/explain.html
type ExplainStmt struct {
txtNode
S Node
}
// PreparedStmt is a statement to prepares a SQL statement which contains placeholders,
// and it is executed with ExecuteStmt and released with DeallocateStmt.
// See: https://dev.mysql.com/doc/refman/5.7/en/prepare.html
type PreparedStmt struct {
txtNode
InPrepare bool // true for prepare mode, false for use mode
Name string
ID uint32 // For binary protocol, there is no Name but only ID
SQLVar *Variable
SQLStmt Node // The parsed statement from sql text with placeholder
Params []*ParamMarker
}
// DeallocateStmt is a statement to release PreparedStmt.
// See: https://dev.mysql.com/doc/refman/5.7/en/deallocate-prepare.html
type DeallocateStmt struct {
txtNode
Name string
ID uint32 // For binary protocol, there is no Name but only ID.
}
// ExecuteStmt is a statement to execute PreparedStmt.
// See: https://dev.mysql.com/doc/refman/5.7/en/execute.html
type ExecuteStmt struct {
txtNode
Name string
ID uint32 // For binary protocol, there is no Name but only ID
UsingVars []Expression
}
// ShowStmt is a statement to provide information about databases, tables, columns and so on.
// See: https://dev.mysql.com/doc/refman/5.7/en/show.html
type ShowStmt struct {
txtNode
Target int // Databases/Tables/Columns/....
DBName string
Table *TableRef // Used for showing columns.
ColumnName string // Used for `desc table column`.
Flag int // Some flag parsed from sql, such as FULL.
Full bool
// Used by show variables
GlobalScope bool
Pattern *PatternLike
Where Expression
}
// BeginStmt is a statement to start a new transaction.
// See: https://dev.mysql.com/doc/refman/5.7/en/commit.html
type BeginStmt struct {
txtNode
}
// CommitStmt is a statement to commit the current transaction.
// See: https://dev.mysql.com/doc/refman/5.7/en/commit.html
type CommitStmt struct {
txtNode
}
// RollbackStmt is a statement to roll back the current transaction.
// See: https://dev.mysql.com/doc/refman/5.7/en/commit.html
type RollbackStmt struct {
txtNode
}
// UseStmt is a statement to use the DBName database as the current database.
// See: https://dev.mysql.com/doc/refman/5.7/en/use.html
type UseStmt struct {
txtNode
DBName string
}
// VariableAssignment is a variable assignment struct.
type VariableAssignment struct {
txtNode
Name string
Value Expression
IsGlobal bool
IsSystem bool
}
// Accept implements Node interface.
func (va *VariableAssignment) Accept(v Visitor) (Node, bool) {
if !v.Enter(va) {
return va, false
}
node, ok := va.Value.Accept(v)
if !ok {
return va, false
}
va.Value = node.(Expression)
return v.Leave(va)
}
// SetStmt is the statement to set variables.
type SetStmt struct {
txtNode
// Variables is the list of variable assignment.
Variables []*VariableAssignment
}
// Accept implements Node Accept interface.
func (set *SetStmt) Accept(v Visitor) (Node, bool) {
if !v.Enter(set) {
return set, false
}
for i, val := range set.Variables {
node, ok := val.Accept(v)
if !ok {
return set, false
}
set.Variables[i] = node.(*VariableAssignment)
}
return v.Leave(set)
}