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
112 lines (84 loc) · 2.79 KB
/
PostgresSelect.java
File metadata and controls
112 lines (84 loc) · 2.79 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
package sqlancer.postgres.ast;
import java.util.Collections;
import java.util.List;
import sqlancer.Randomly;
import sqlancer.ast.SelectBase;
import sqlancer.postgres.PostgresSchema.PostgresDataType;
import sqlancer.postgres.PostgresSchema.PostgresTable;
public class PostgresSelect extends SelectBase<PostgresExpression> implements PostgresExpression {
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 PostgresTable t;
private 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 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;
}
public void setJoinClauses(List<PostgresJoin> joinStatements) {
this.joinClauses = joinStatements;
}
public List<PostgresJoin> getJoinClauses() {
return joinClauses;
}
public PostgresExpression getDistinctOnClause() {
return distinctOnClause;
}
public void setForClause(ForClause forClause) {
this.forClause = forClause;
}
public ForClause getForClause() {
return forClause;
}
}