forked from sqlancer/sqlancer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostgresSelect.java
More file actions
145 lines (112 loc) · 3.67 KB
/
PostgresSelect.java
File metadata and controls
145 lines (112 loc) · 3.67 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
package sqlancer.postgres.ast;
import java.util.Collections;
import java.util.List;
import sqlancer.Randomly;
import sqlancer.common.ast.SelectBase;
import sqlancer.common.ast.newast.Select;
import sqlancer.postgres.PostgresSchema.PostgresColumn;
import sqlancer.postgres.PostgresSchema.PostgresDataType;
import sqlancer.postgres.PostgresSchema.PostgresTable;
import sqlancer.postgres.PostgresVisitor;
public class PostgresSelect extends SelectBase<PostgresExpression>
implements PostgresExpression, Select<PostgresJoin, PostgresExpression, PostgresTable, PostgresColumn> {
private SelectType selectOption = SelectType.ALL;
private List<PostgresJoin> joinClauses = Collections.emptyList();
private PostgresExpression distinctOnClause;
private ForClause forClause;
public enum ForClause {
UPDATE("UPDATE"), NO_KEY_UPDATE("NO KEY UPDATE"), SHARE("SHARE"), KEY_SHARE("KEY SHARE");
private final String textRepresentation;
ForClause(String textRepresentation) {
this.textRepresentation = textRepresentation;
}
public String getTextRepresentation() {
return textRepresentation;
}
public static ForClause getRandom() {
return Randomly.fromOptions(values());
}
}
public static class PostgresFromTable implements PostgresExpression {
private final PostgresTable t;
private final boolean only;
public PostgresFromTable(PostgresTable t, boolean only) {
this.t = t;
this.only = only;
}
public PostgresTable getTable() {
return t;
}
public boolean isOnly() {
return only;
}
@Override
public PostgresDataType getExpressionType() {
return null;
}
}
public static class PostgresSubquery implements PostgresExpression {
private final PostgresSelect s;
private final String name;
public PostgresSubquery(PostgresSelect s, String name) {
this.s = s;
this.name = name;
}
public PostgresSelect getSelect() {
return s;
}
public String getName() {
return name;
}
@Override
public PostgresDataType getExpressionType() {
return null;
}
}
public enum SelectType {
DISTINCT, ALL;
public static SelectType getRandom() {
return Randomly.fromOptions(values());
}
}
public void setSelectType(SelectType fromOptions) {
this.setSelectOption(fromOptions);
}
public void setDistinctOnClause(PostgresExpression distinctOnClause) {
if (selectOption != SelectType.DISTINCT) {
throw new IllegalArgumentException();
}
this.distinctOnClause = distinctOnClause;
}
public SelectType getSelectOption() {
return selectOption;
}
public void setSelectOption(SelectType fromOptions) {
this.selectOption = fromOptions;
}
@Override
public PostgresDataType getExpressionType() {
return null;
}
@Override
public void setJoinClauses(List<PostgresJoin> joinStatements) {
this.joinClauses = joinStatements;
}
@Override
public List<PostgresJoin> getJoinClauses() {
return joinClauses;
}
public PostgresExpression getDistinctOnClause() {
return distinctOnClause;
}
public void setForClause(ForClause forClause) {
this.forClause = forClause;
}
public ForClause getForClause() {
return forClause;
}
@Override
public String asString() {
return PostgresVisitor.asString(this);
}
}