forked from sqlancer/sqlancer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostgresVisitor.java
More file actions
125 lines (100 loc) · 4.84 KB
/
PostgresVisitor.java
File metadata and controls
125 lines (100 loc) · 4.84 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
package sqlancer.postgres;
import java.util.List;
import sqlancer.postgres.PostgresSchema.PostgresColumn;
import sqlancer.postgres.PostgresSchema.PostgresDataType;
import sqlancer.postgres.ast.PostgresAggregate;
import sqlancer.postgres.ast.PostgresBetweenOperation;
import sqlancer.postgres.ast.PostgresCastOperation;
import sqlancer.postgres.ast.PostgresCollate;
import sqlancer.postgres.ast.PostgresColumnValue;
import sqlancer.postgres.ast.PostgresConstant;
import sqlancer.postgres.ast.PostgresExpression;
import sqlancer.postgres.ast.PostgresFunction;
import sqlancer.postgres.ast.PostgresInOperation;
import sqlancer.postgres.ast.PostgresOrderByTerm;
import sqlancer.postgres.ast.PostgresPOSIXRegularExpression;
import sqlancer.postgres.ast.PostgresPostfixOperation;
import sqlancer.postgres.ast.PostgresPostfixText;
import sqlancer.postgres.ast.PostgresPrefixOperation;
import sqlancer.postgres.ast.PostgresSelect;
import sqlancer.postgres.ast.PostgresSelect.PostgresFromTable;
import sqlancer.postgres.ast.PostgresSimilarTo;
import sqlancer.postgres.gen.PostgresExpressionGenerator;
public interface PostgresVisitor {
void visit(PostgresConstant constant);
void visit(PostgresPostfixOperation op);
void visit(PostgresColumnValue c);
void visit(PostgresPrefixOperation op);
void visit(PostgresSelect op);
void visit(PostgresOrderByTerm op);
void visit(PostgresFunction f);
void visit(PostgresCastOperation cast);
void visit(PostgresBetweenOperation op);
void visit(PostgresInOperation op);
void visit(PostgresPostfixText op);
void visit(PostgresAggregate op);
void visit(PostgresSimilarTo op);
void visit(PostgresCollate op);
void visit(PostgresPOSIXRegularExpression op);
void visit(PostgresFromTable from);
default void visit(PostgresExpression expression) {
if (expression instanceof PostgresConstant) {
visit((PostgresConstant) expression);
} else if (expression instanceof PostgresPostfixOperation) {
visit((PostgresPostfixOperation) expression);
} else if (expression instanceof PostgresColumnValue) {
visit((PostgresColumnValue) expression);
} else if (expression instanceof PostgresPrefixOperation) {
visit((PostgresPrefixOperation) expression);
} else if (expression instanceof PostgresSelect) {
visit((PostgresSelect) expression);
} else if (expression instanceof PostgresOrderByTerm) {
visit((PostgresOrderByTerm) expression);
} else if (expression instanceof PostgresFunction) {
visit((PostgresFunction) expression);
} else if (expression instanceof PostgresCastOperation) {
visit((PostgresCastOperation) expression);
} else if (expression instanceof PostgresBetweenOperation) {
visit((PostgresBetweenOperation) expression);
} else if (expression instanceof PostgresInOperation) {
visit((PostgresInOperation) expression);
} else if (expression instanceof PostgresAggregate) {
visit((PostgresAggregate) expression);
} else if (expression instanceof PostgresPostfixText) {
visit((PostgresPostfixText) expression);
} else if (expression instanceof PostgresSimilarTo) {
visit((PostgresSimilarTo) expression);
} else if (expression instanceof PostgresPOSIXRegularExpression) {
visit((PostgresPOSIXRegularExpression) expression);
} else if (expression instanceof PostgresCollate) {
visit((PostgresCollate) expression);
} else if (expression instanceof PostgresFromTable) {
visit((PostgresFromTable) expression);
} else {
throw new AssertionError(expression);
}
}
static String asString(PostgresExpression expr) {
PostgresToStringVisitor visitor = new PostgresToStringVisitor();
visitor.visit(expr);
return visitor.get();
}
static String asExpectedValues(PostgresExpression expr) {
PostgresExpectedValueVisitor v = new PostgresExpectedValueVisitor();
v.visit(expr);
return v.get();
}
static String getExpressionAsString(PostgresGlobalState globalState, PostgresDataType type) {
PostgresExpression expression = PostgresExpressionGenerator.generateExpression(globalState, type);
PostgresToStringVisitor visitor = new PostgresToStringVisitor();
visitor.visit(expression);
return visitor.get();
}
static String getExpressionAsString(PostgresGlobalState globalState, PostgresDataType type,
List<PostgresColumn> columns) {
PostgresExpression expression = PostgresExpressionGenerator.generateExpression(globalState, columns, type);
PostgresToStringVisitor visitor = new PostgresToStringVisitor();
visitor.visit(expression);
return visitor.get();
}
}