forked from JSQLParser/JSqlParser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMySqlSelectIntoClause.java
More file actions
205 lines (165 loc) · 5.35 KB
/
MySqlSelectIntoClause.java
File metadata and controls
205 lines (165 loc) · 5.35 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
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2026 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.statement.select;
import java.io.Serializable;
import net.sf.jsqlparser.expression.StringValue;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
public class MySqlSelectIntoClause extends ASTNodeAccessImpl implements Serializable {
public enum Position {
BEFORE_FROM, TRAILING
}
public enum Type {
OUTFILE, DUMPFILE
}
public enum FieldsKeyword {
FIELDS, COLUMNS
}
private Position position = Position.TRAILING;
private Type type;
private StringValue fileName;
private String characterSet;
private FieldsKeyword fieldsKeyword;
private StringValue fieldsTerminatedBy;
private boolean fieldsOptionallyEnclosed;
private StringValue fieldsEnclosedBy;
private StringValue fieldsEscapedBy;
private StringValue linesStartingBy;
private StringValue linesTerminatedBy;
public Position getPosition() {
return position;
}
public void setPosition(Position position) {
this.position = position;
}
public MySqlSelectIntoClause withPosition(Position position) {
this.setPosition(position);
return this;
}
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
public StringValue getFileName() {
return fileName;
}
public void setFileName(StringValue fileName) {
this.fileName = fileName;
}
public String getCharacterSet() {
return characterSet;
}
public void setCharacterSet(String characterSet) {
this.characterSet = characterSet;
}
public FieldsKeyword getFieldsKeyword() {
return fieldsKeyword;
}
public void setFieldsKeyword(FieldsKeyword fieldsKeyword) {
this.fieldsKeyword = fieldsKeyword;
}
public StringValue getFieldsTerminatedBy() {
return fieldsTerminatedBy;
}
public void setFieldsTerminatedBy(StringValue fieldsTerminatedBy) {
this.fieldsTerminatedBy = fieldsTerminatedBy;
}
public boolean isFieldsOptionallyEnclosed() {
return fieldsOptionallyEnclosed;
}
public void setFieldsOptionallyEnclosed(boolean fieldsOptionallyEnclosed) {
this.fieldsOptionallyEnclosed = fieldsOptionallyEnclosed;
}
public StringValue getFieldsEnclosedBy() {
return fieldsEnclosedBy;
}
public void setFieldsEnclosedBy(StringValue fieldsEnclosedBy) {
this.fieldsEnclosedBy = fieldsEnclosedBy;
}
public StringValue getFieldsEscapedBy() {
return fieldsEscapedBy;
}
public void setFieldsEscapedBy(StringValue fieldsEscapedBy) {
this.fieldsEscapedBy = fieldsEscapedBy;
}
public StringValue getLinesStartingBy() {
return linesStartingBy;
}
public void setLinesStartingBy(StringValue linesStartingBy) {
this.linesStartingBy = linesStartingBy;
}
public StringValue getLinesTerminatedBy() {
return linesTerminatedBy;
}
public void setLinesTerminatedBy(StringValue linesTerminatedBy) {
this.linesTerminatedBy = linesTerminatedBy;
}
public boolean hasFieldsClause() {
return fieldsKeyword != null || fieldsTerminatedBy != null || fieldsEnclosedBy != null
|| fieldsEscapedBy != null;
}
public boolean hasLinesClause() {
return linesStartingBy != null || linesTerminatedBy != null;
}
public StringBuilder appendTo(StringBuilder builder) {
builder.append("INTO ").append(type);
appendFileName(builder);
appendCharacterSet(builder);
appendFieldsClause(builder);
appendLinesClause(builder);
return builder;
}
private void appendFileName(StringBuilder builder) {
if (fileName != null) {
builder.append(" ").append(fileName);
}
}
private void appendCharacterSet(StringBuilder builder) {
if (characterSet != null) {
builder.append(" CHARACTER SET ").append(characterSet);
}
}
private void appendFieldsClause(StringBuilder builder) {
if (!hasFieldsClause()) {
return;
}
builder.append(" ").append(fieldsKeyword != null ? fieldsKeyword : FieldsKeyword.FIELDS);
if (fieldsTerminatedBy != null) {
builder.append(" TERMINATED BY ").append(fieldsTerminatedBy);
}
if (fieldsEnclosedBy != null) {
builder.append(" ");
if (fieldsOptionallyEnclosed) {
builder.append("OPTIONALLY ");
}
builder.append("ENCLOSED BY ").append(fieldsEnclosedBy);
}
if (fieldsEscapedBy != null) {
builder.append(" ESCAPED BY ").append(fieldsEscapedBy);
}
}
private void appendLinesClause(StringBuilder builder) {
if (!hasLinesClause()) {
return;
}
builder.append(" LINES");
if (linesStartingBy != null) {
builder.append(" STARTING BY ").append(linesStartingBy);
}
if (linesTerminatedBy != null) {
builder.append(" TERMINATED BY ").append(linesTerminatedBy);
}
}
@Override
public String toString() {
return appendTo(new StringBuilder()).toString();
}
}