-
Notifications
You must be signed in to change notification settings - Fork 398
Expand file tree
/
Copy pathMySQLExpectedValueVisitor.java
More file actions
205 lines (173 loc) · 5.04 KB
/
MySQLExpectedValueVisitor.java
File metadata and controls
205 lines (173 loc) · 5.04 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package sqlancer.mysql;
import java.util.List;
import sqlancer.IgnoreMeException;
import sqlancer.mysql.ast.MySQLAggregate;
import sqlancer.mysql.ast.MySQLBetweenOperation;
import sqlancer.mysql.ast.MySQLBinaryComparisonOperation;
import sqlancer.mysql.ast.MySQLBinaryLogicalOperation;
import sqlancer.mysql.ast.MySQLBinaryOperation;
import sqlancer.mysql.ast.MySQLCaseOperator;
import sqlancer.mysql.ast.MySQLCastOperation;
import sqlancer.mysql.ast.MySQLCollate;
import sqlancer.mysql.ast.MySQLColumnReference;
import sqlancer.mysql.ast.MySQLComputableFunction;
import sqlancer.mysql.ast.MySQLConstant;
import sqlancer.mysql.ast.MySQLExists;
import sqlancer.mysql.ast.MySQLExpression;
import sqlancer.mysql.ast.MySQLInOperation;
import sqlancer.mysql.ast.MySQLJoin;
import sqlancer.mysql.ast.MySQLOrderByTerm;
import sqlancer.mysql.ast.MySQLSelect;
import sqlancer.mysql.ast.MySQLStringExpression;
import sqlancer.mysql.ast.MySQLTableReference;
import sqlancer.mysql.ast.MySQLText;
import sqlancer.mysql.ast.MySQLUnaryPostfixOperation;
public class MySQLExpectedValueVisitor implements MySQLVisitor {
private final StringBuilder sb = new StringBuilder();
private int nrTabs;
private void print(MySQLExpression expr) {
MySQLToStringVisitor v = new MySQLToStringVisitor();
v.visit(expr);
for (int i = 0; i < nrTabs; i++) {
sb.append("\t");
}
sb.append(v.get());
sb.append(" -- ");
sb.append(expr.getExpectedValue());
sb.append("\n");
}
@Override
public void visit(MySQLExpression expr) {
nrTabs++;
try {
MySQLVisitor.super.visit(expr);
} catch (IgnoreMeException e) {
}
nrTabs--;
}
@Override
public void visit(MySQLConstant constant) {
print(constant);
}
@Override
public void visit(MySQLColumnReference column) {
print(column);
}
@Override
public void visit(MySQLUnaryPostfixOperation op) {
print(op);
visit(op.getExpression());
}
@Override
public void visit(MySQLComputableFunction f) {
print(f);
for (MySQLExpression expr : f.getArguments()) {
visit(expr);
}
}
@Override
public void visit(MySQLBinaryLogicalOperation op) {
print(op);
visit(op.getLeft());
visit(op.getRight());
}
public String get() {
return sb.toString();
}
@Override
public void visit(MySQLSelect select) {
for (MySQLExpression j : select.getJoinList()) {
visit(j);
}
if (select.getWhereClause() != null) {
visit(select.getWhereClause());
}
}
@Override
public void visit(MySQLBinaryComparisonOperation op) {
print(op);
visit(op.getLeft());
visit(op.getRight());
}
@Override
public void visit(MySQLCastOperation op) {
print(op);
visit(op.getExpr());
}
@Override
public void visit(MySQLInOperation op) {
print(op);
for (MySQLExpression right : op.getListElements()) {
visit(right);
}
}
@Override
public void visit(MySQLBinaryOperation op) {
print(op);
visit(op.getLeft());
visit(op.getRight());
}
@Override
public void visit(MySQLOrderByTerm op) {
}
@Override
public void visit(MySQLExists op) {
print(op);
visit(op.getExpr());
}
@Override
public void visit(MySQLStringExpression op) {
print(op);
}
@Override
public void visit(MySQLBetweenOperation op) {
print(op);
visit(op.getExpr());
visit(op.getLeft());
visit(op.getRight());
}
@Override
public void visit(MySQLTableReference ref) {
}
@Override
public void visit(MySQLCollate collate) {
print(collate);
visit(collate.getExpectedValue());
}
@Override
public void visit(MySQLJoin join) {
print(join);
visit(join.getOnClause());
}
@Override
public void visit(MySQLText text) {
print(text);
}
@Override
public void visit(MySQLAggregate aggr) {
// PQS is currently unsupported for aggregates.
throw new IgnoreMeException();
}
@Override
public void visit(MySQLCaseOperator caseOp) {
print(caseOp);
MySQLExpression switchCondition = caseOp.getSwitchCondition();
if (switchCondition != null) {
print(switchCondition);
visit(switchCondition);
}
List<MySQLExpression> whenConditions = caseOp.getConditions();
List<MySQLExpression> thenExpressions = caseOp.getExpressions();
for (int i = 0; i < whenConditions.size(); i++) {
print(whenConditions.get(i));
visit(whenConditions.get(i));
print(thenExpressions.get(i));
visit(thenExpressions.get(i));
}
MySQLExpression elseExpr = caseOp.getElseExpr();
if (elseExpr != null) {
print(elseExpr);
visit(elseExpr);
}
}
}