View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.shardingsphere.sql.parser.mysql.visitor.statement.type;
19  
20  import org.apache.shardingsphere.sql.parser.api.ASTNode;
21  import org.apache.shardingsphere.sql.parser.api.visitor.statement.type.DALStatementVisitor;
22  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.AlterResourceGroupContext;
23  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.AnalyzeTableContext;
24  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.BinaryLogFileIndexNumberContext;
25  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.BinlogContext;
26  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CacheIndexContext;
27  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CacheTableIndexListContext;
28  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ChannelOptionContext;
29  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CheckTableContext;
30  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ChecksumTableContext;
31  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CloneActionContext;
32  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CloneContext;
33  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CloneInstanceContext;
34  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ComponentNameContext;
35  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CreateLoadableFunctionContext;
36  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CreateResourceGroupContext;
37  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.DelimiterContext;
38  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.DropResourceGroupContext;
39  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ExplainContext;
40  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ExplainableStatementContext;
41  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.FlushContext;
42  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.FromSchemaContext;
43  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.FromTableContext;
44  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.HelpContext;
45  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.IndexNameContext;
46  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.InstallComponentContext;
47  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.InstallPluginContext;
48  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.KillContext;
49  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.LoadIndexInfoContext;
50  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.LoadTableIndexListContext;
51  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.OptimizeTableContext;
52  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.OptionTypeContext;
53  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.OptionValueContext;
54  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.OptionValueListContext;
55  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.OptionValueNoOptionTypeContext;
56  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.PartitionListContext;
57  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.PartitionNameContext;
58  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.RepairTableContext;
59  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ResetOptionContext;
60  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ResetPersistContext;
61  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ResetStatementContext;
62  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.RestartContext;
63  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.SetCharacterContext;
64  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.SetResourceGroupContext;
65  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.SetVariableContext;
66  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowBinaryLogsContext;
67  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowBinlogEventsContext;
68  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowCharacterSetContext;
69  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowCharsetContext;
70  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowCollationContext;
71  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowColumnsContext;
72  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowCreateDatabaseContext;
73  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowCreateEventContext;
74  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowCreateFunctionContext;
75  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowCreateProcedureContext;
76  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowCreateTableContext;
77  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowCreateTriggerContext;
78  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowCreateUserContext;
79  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowCreateViewContext;
80  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowDatabasesContext;
81  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowEngineContext;
82  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowEnginesContext;
83  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowErrorsContext;
84  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowEventsContext;
85  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowFilterContext;
86  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowFunctionCodeContext;
87  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowFunctionStatusContext;
88  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowGrantsContext;
89  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowIndexContext;
90  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowLikeContext;
91  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowMasterStatusContext;
92  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowOpenTablesContext;
93  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowPluginsContext;
94  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowPrivilegesContext;
95  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowProcedureCodeContext;
96  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowProcedureStatusContext;
97  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowProcesslistContext;
98  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowProfileContext;
99  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowProfilesContext;
100 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowRelaylogEventContext;
101 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowReplicaStatusContext;
102 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowReplicasContext;
103 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowSlaveHostsContext;
104 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowSlaveStatusContext;
105 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowStatusContext;
106 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowTableStatusContext;
107 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowTablesContext;
108 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowTriggersContext;
109 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowVariablesContext;
110 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowWarningsContext;
111 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowWhereClauseContext;
112 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShutdownContext;
113 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.TableNameContext;
114 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.TablesOptionContext;
115 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.UninstallComponentContext;
116 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.UninstallPluginContext;
117 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.UseContext;
118 import org.apache.shardingsphere.sql.parser.mysql.visitor.statement.MySQLStatementVisitor;
119 import org.apache.shardingsphere.sql.parser.sql.common.segment.dal.FromSchemaSegment;
120 import org.apache.shardingsphere.sql.parser.sql.common.segment.dal.FromTableSegment;
121 import org.apache.shardingsphere.sql.parser.sql.common.segment.dal.ShowFilterSegment;
122 import org.apache.shardingsphere.sql.parser.sql.common.segment.dal.ShowLikeSegment;
123 import org.apache.shardingsphere.sql.parser.sql.common.segment.dal.VariableAssignSegment;
124 import org.apache.shardingsphere.sql.parser.sql.common.segment.dal.VariableSegment;
125 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment;
126 import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
127 import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
128 import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.FunctionSegment;
129 import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.pagination.limit.LimitSegment;
130 import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.WhereSegment;
131 import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.DatabaseSegment;
132 import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
133 import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
134 import org.apache.shardingsphere.sql.parser.sql.common.value.collection.CollectionValue;
135 import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
136 import org.apache.shardingsphere.sql.parser.sql.common.value.literal.impl.NumberLiteralValue;
137 import org.apache.shardingsphere.sql.parser.sql.common.value.literal.impl.StringLiteralValue;
138 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLAlterResourceGroupStatement;
139 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLAnalyzeTableStatement;
140 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLBinlogStatement;
141 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLCacheIndexStatement;
142 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLCheckTableStatement;
143 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLChecksumTableStatement;
144 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLCloneStatement;
145 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLCreateLoadableFunctionStatement;
146 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLCreateResourceGroupStatement;
147 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLDelimiterStatement;
148 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLDropResourceGroupStatement;
149 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLExplainStatement;
150 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLFlushStatement;
151 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLHelpStatement;
152 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLInstallComponentStatement;
153 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLInstallPluginStatement;
154 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLKillStatement;
155 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLLoadIndexInfoStatement;
156 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLOptimizeTableStatement;
157 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLRepairTableStatement;
158 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLResetPersistStatement;
159 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLResetStatement;
160 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLRestartStatement;
161 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLSetResourceGroupStatement;
162 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLSetStatement;
163 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowBinaryLogsStatement;
164 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowBinlogEventsStatement;
165 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowCharacterSetStatement;
166 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowCollationStatement;
167 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowColumnsStatement;
168 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowCreateDatabaseStatement;
169 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowCreateEventStatement;
170 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowCreateFunctionStatement;
171 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowCreateProcedureStatement;
172 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowCreateTableStatement;
173 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowCreateTriggerStatement;
174 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowCreateUserStatement;
175 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowCreateViewStatement;
176 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowDatabasesStatement;
177 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowEngineStatement;
178 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowErrorsStatement;
179 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowEventsStatement;
180 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowFunctionCodeStatement;
181 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowFunctionStatusStatement;
182 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowGrantsStatement;
183 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowIndexStatement;
184 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowMasterStatusStatement;
185 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowOpenTablesStatement;
186 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowOtherStatement;
187 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowPluginsStatement;
188 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowPrivilegesStatement;
189 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowProcedureCodeStatement;
190 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowProcedureStatusStatement;
191 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowProcessListStatement;
192 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowProfileStatement;
193 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowProfilesStatement;
194 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowRelayLogEventsStatement;
195 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowReplicaStatusStatement;
196 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowReplicasStatement;
197 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowSlaveHostsStatement;
198 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowSlaveStatusStatement;
199 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowStatusStatement;
200 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowTableStatusStatement;
201 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowTablesStatement;
202 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowTriggersStatement;
203 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowVariablesStatement;
204 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowWarningsStatement;
205 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShutdownStatement;
206 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLUninstallComponentStatement;
207 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLUninstallPluginStatement;
208 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLUseStatement;
209 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.segment.CacheTableIndexSegment;
210 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.segment.CloneActionSegment;
211 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.segment.CloneInstanceSegment;
212 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.segment.LoadTableIndexSegment;
213 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.segment.PartitionDefinitionSegment;
214 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.segment.PartitionSegment;
215 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.segment.ResetMasterOptionSegment;
216 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.segment.ResetOptionSegment;
217 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.segment.ResetSlaveOptionSegment;
218 
219 import java.util.Collection;
220 import java.util.LinkedList;
221 import java.util.List;
222 
223 /**
224  * DAL statement visitor for MySQL.
225  */
226 public final class MySQLDALStatementVisitor extends MySQLStatementVisitor implements DALStatementVisitor {
227     
228     @Override
229     public ASTNode visitUninstallPlugin(final UninstallPluginContext ctx) {
230         MySQLUninstallPluginStatement result = new MySQLUninstallPluginStatement();
231         result.setPluginName(((IdentifierValue) visit(ctx.pluginName())).getValue());
232         return result;
233     }
234     
235     @Override
236     public ASTNode visitShowCreateDatabase(final ShowCreateDatabaseContext ctx) {
237         MySQLShowCreateDatabaseStatement result = new MySQLShowCreateDatabaseStatement();
238         result.setDatabaseName(((DatabaseSegment) visit(ctx.schemaName())).getIdentifier().getValue());
239         return result;
240     }
241     
242     @Override
243     public ASTNode visitShowBinaryLogs(final ShowBinaryLogsContext ctx) {
244         return new MySQLShowBinaryLogsStatement();
245     }
246     
247     @Override
248     public ASTNode visitShowStatus(final ShowStatusContext ctx) {
249         MySQLShowStatusStatement result = new MySQLShowStatusStatement();
250         if (null != ctx.showFilter()) {
251             result.setFilter((ShowFilterSegment) visit(ctx.showFilter()));
252         }
253         result.addParameterMarkerSegments(getParameterMarkerSegments());
254         return result;
255     }
256     
257     @Override
258     public ASTNode visitShowCreateView(final ShowCreateViewContext ctx) {
259         return new MySQLShowCreateViewStatement();
260     }
261     
262     @Override
263     public ASTNode visitShowEngines(final ShowEnginesContext ctx) {
264         return new MySQLShowOtherStatement();
265     }
266     
267     @Override
268     public ASTNode visitShowEngine(final ShowEngineContext ctx) {
269         MySQLShowEngineStatement result = new MySQLShowEngineStatement();
270         result.setEngineName(ctx.engineRef().getText());
271         return result;
272     }
273     
274     @Override
275     public ASTNode visitShowCharset(final ShowCharsetContext ctx) {
276         return new MySQLShowOtherStatement();
277     }
278     
279     @Override
280     public ASTNode visitShowCreateEvent(final ShowCreateEventContext ctx) {
281         MySQLShowCreateEventStatement result = new MySQLShowCreateEventStatement();
282         result.setEventName(((IdentifierValue) visit(ctx.eventName())).getValue());
283         return result;
284     }
285     
286     @Override
287     public ASTNode visitShowCreateFunction(final ShowCreateFunctionContext ctx) {
288         MySQLShowCreateFunctionStatement result = new MySQLShowCreateFunctionStatement();
289         result.setFunctionName(((FunctionSegment) visit(ctx.functionName())).getFunctionName());
290         return result;
291     }
292     
293     @Override
294     public ASTNode visitShowCreateProcedure(final ShowCreateProcedureContext ctx) {
295         MySQLShowCreateProcedureStatement result = new MySQLShowCreateProcedureStatement();
296         result.setProcedureName(((IdentifierValue) visit(ctx.procedureName())).getValue());
297         return result;
298     }
299     
300     @Override
301     public ASTNode visitShowBinlogEvents(final ShowBinlogEventsContext ctx) {
302         MySQLShowBinlogEventsStatement result = new MySQLShowBinlogEventsStatement();
303         if (null != ctx.logName()) {
304             result.setLogName(ctx.logName().getText());
305         }
306         if (null != ctx.limitClause()) {
307             result.setLimit((LimitSegment) visit(ctx.limitClause()));
308         }
309         return result;
310     }
311     
312     @Override
313     public ASTNode visitShowErrors(final ShowErrorsContext ctx) {
314         MySQLShowErrorsStatement result = new MySQLShowErrorsStatement();
315         if (null != ctx.limitClause()) {
316             result.setLimit((LimitSegment) visit(ctx.limitClause()));
317         }
318         return result;
319     }
320     
321     @Override
322     public ASTNode visitShowWarnings(final ShowWarningsContext ctx) {
323         MySQLShowWarningsStatement result = new MySQLShowWarningsStatement();
324         if (null != ctx.limitClause()) {
325             result.setLimit((LimitSegment) visit(ctx.limitClause()));
326         }
327         return result;
328     }
329     
330     @Override
331     public ASTNode visitResetStatement(final ResetStatementContext ctx) {
332         ResetPersistContext persistContext = ctx.resetPersist();
333         if (null != persistContext) {
334             return visit(persistContext);
335         }
336         MySQLResetStatement result = new MySQLResetStatement();
337         for (ResetOptionContext each : ctx.resetOption()) {
338             if (null != each.MASTER() || null != each.SLAVE()) {
339                 result.getOptions().add((ResetOptionSegment) visit(each));
340             }
341         }
342         return result;
343     }
344     
345     @Override
346     public ASTNode visitResetPersist(final ResetPersistContext ctx) {
347         return new MySQLResetPersistStatement(null != ctx.ifExists(), null == ctx.identifier() ? null : new IdentifierValue(ctx.identifier().getText()));
348     }
349     
350     @Override
351     public ASTNode visitResetOption(final ResetOptionContext ctx) {
352         if (null != ctx.MASTER()) {
353             ResetMasterOptionSegment result = new ResetMasterOptionSegment();
354             if (null != ctx.binaryLogFileIndexNumber()) {
355                 result.setBinaryLogFileIndexNumber(((NumberLiteralValue) visit(ctx.binaryLogFileIndexNumber())).getValue().longValue());
356             }
357             result.setStartIndex(ctx.start.getStartIndex());
358             result.setStopIndex(ctx.stop.getStopIndex());
359             return result;
360         }
361         ResetSlaveOptionSegment result = new ResetSlaveOptionSegment();
362         if (null != ctx.ALL()) {
363             result.setAll(true);
364         }
365         if (null != ctx.channelOption()) {
366             result.setChannelOption(((StringLiteralValue) visit(ctx.channelOption())).getValue());
367         }
368         result.setStartIndex(ctx.start.getStartIndex());
369         result.setStopIndex(ctx.stop.getStopIndex());
370         return result;
371     }
372     
373     @Override
374     public ASTNode visitChannelOption(final ChannelOptionContext ctx) {
375         return visit(ctx.string_());
376     }
377     
378     @Override
379     public ASTNode visitBinaryLogFileIndexNumber(final BinaryLogFileIndexNumberContext ctx) {
380         return new NumberLiteralValue(ctx.getText());
381     }
382     
383     @Override
384     public ASTNode visitShowReplicas(final ShowReplicasContext ctx) {
385         return new MySQLShowReplicasStatement();
386     }
387     
388     @SuppressWarnings("unchecked")
389     @Override
390     public ASTNode visitRepairTable(final RepairTableContext ctx) {
391         MySQLRepairTableStatement result = new MySQLRepairTableStatement();
392         result.getTables().addAll(((CollectionValue<SimpleTableSegment>) visit(ctx.tableList())).getValue());
393         return result;
394     }
395     
396     @SuppressWarnings("unchecked")
397     @Override
398     public ASTNode visitAnalyzeTable(final AnalyzeTableContext ctx) {
399         MySQLAnalyzeTableStatement result = new MySQLAnalyzeTableStatement();
400         result.getTables().addAll(((CollectionValue<SimpleTableSegment>) visit(ctx.tableList())).getValue());
401         return result;
402     }
403     
404     @Override
405     public ASTNode visitCacheIndex(final CacheIndexContext ctx) {
406         MySQLCacheIndexStatement result = new MySQLCacheIndexStatement();
407         if (null != ctx.cacheTableIndexList()) {
408             for (CacheTableIndexListContext each : ctx.cacheTableIndexList()) {
409                 result.getTableIndexes().add((CacheTableIndexSegment) visit(each));
410             }
411         }
412         if (null != ctx.partitionList()) {
413             SimpleTableSegment table = (SimpleTableSegment) visit(ctx.tableName());
414             PartitionDefinitionSegment segment = new PartitionDefinitionSegment(ctx.tableName().getStart().getStartIndex(), ctx.partitionList().getStop().getStopIndex(), table);
415             segment.getPartitions().addAll(((CollectionValue<PartitionSegment>) visit(ctx.partitionList())).getValue());
416             result.setPartitionDefinition(segment);
417         }
418         if (null != ctx.DEFAULT()) {
419             result.setName(new IdentifierValue(ctx.DEFAULT().getText()));
420         } else {
421             result.setName((IdentifierValue) visit(ctx.identifier()));
422         }
423         return result;
424     }
425     
426     @Override
427     public ASTNode visitCacheTableIndexList(final CacheTableIndexListContext ctx) {
428         CacheTableIndexSegment result = new CacheTableIndexSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (SimpleTableSegment) visit(ctx.tableName()));
429         for (IndexNameContext each : ctx.indexName()) {
430             result.getIndexes().add((IndexSegment) visitIndexName(each));
431         }
432         return result;
433     }
434     
435     @Override
436     public ASTNode visitPartitionList(final PartitionListContext ctx) {
437         CollectionValue<PartitionSegment> result = new CollectionValue<>();
438         for (PartitionNameContext each : ctx.partitionName()) {
439             result.getValue().add((PartitionSegment) visit(each));
440         }
441         return result;
442     }
443     
444     @Override
445     public ASTNode visitPartitionName(final PartitionNameContext ctx) {
446         return new PartitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (IdentifierValue) visit(ctx.identifier()));
447     }
448     
449     @Override
450     public ASTNode visitChecksumTable(final ChecksumTableContext ctx) {
451         MySQLChecksumTableStatement result = new MySQLChecksumTableStatement();
452         result.getTables().addAll(((CollectionValue<SimpleTableSegment>) visit(ctx.tableList())).getValue());
453         return result;
454     }
455     
456     @Override
457     public ASTNode visitFlush(final FlushContext ctx) {
458         if (null != ctx.tablesOption()) {
459             return visit(ctx.tablesOption());
460         }
461         return new MySQLFlushStatement();
462     }
463     
464     @Override
465     public ASTNode visitTablesOption(final TablesOptionContext ctx) {
466         MySQLFlushStatement result = new MySQLFlushStatement();
467         result.setFlushTable(true);
468         for (TableNameContext each : ctx.tableName()) {
469             result.getTables().add((SimpleTableSegment) visit(each));
470         }
471         return result;
472     }
473     
474     @Override
475     public ASTNode visitKill(final KillContext ctx) {
476         MySQLKillStatement result = new MySQLKillStatement();
477         if (null != ctx.AT_()) {
478             result.setProcessId(ctx.AT_().getText().concat(ctx.IDENTIFIER_().getText()));
479         } else {
480             result.setProcessId(ctx.IDENTIFIER_().getText());
481         }
482         return result;
483     }
484     
485     @Override
486     public ASTNode visitLoadIndexInfo(final LoadIndexInfoContext ctx) {
487         MySQLLoadIndexInfoStatement result = new MySQLLoadIndexInfoStatement();
488         for (LoadTableIndexListContext each : ctx.loadTableIndexList()) {
489             result.getTableIndexes().add((LoadTableIndexSegment) visit(each));
490         }
491         return result;
492     }
493     
494     @Override
495     public ASTNode visitLoadTableIndexList(final LoadTableIndexListContext ctx) {
496         LoadTableIndexSegment result = new LoadTableIndexSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (SimpleTableSegment) visit(ctx.tableName()));
497         if (null != ctx.indexName()) {
498             for (IndexNameContext each : ctx.indexName()) {
499                 result.getIndexes().add((IndexSegment) visitIndexName(each));
500             }
501         }
502         if (null != ctx.partitionList()) {
503             result.getPartitions().addAll(((CollectionValue<PartitionSegment>) visit(ctx.partitionList())).getValue());
504         }
505         return result;
506     }
507     
508     @Override
509     public ASTNode visitInstallPlugin(final InstallPluginContext ctx) {
510         MySQLInstallPluginStatement result = new MySQLInstallPluginStatement();
511         result.setPluginName(((IdentifierValue) visit(ctx.pluginName())).getValue());
512         return result;
513     }
514     
515     @Override
516     public ASTNode visitClone(final CloneContext ctx) {
517         MySQLCloneStatement result = new MySQLCloneStatement();
518         result.setCloneActionSegment((CloneActionSegment) visit(ctx.cloneAction()));
519         return result;
520     }
521     
522     @Override
523     public ASTNode visitCloneAction(final CloneActionContext ctx) {
524         CloneActionSegment result = new CloneActionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
525         if (null != ctx.cloneInstance()) {
526             CloneInstanceContext cloneInstance = ctx.cloneInstance();
527             CloneInstanceSegment cloneInstanceSegment = new CloneInstanceSegment(cloneInstance.start.getStartIndex(), cloneInstance.stop.getStopIndex());
528             cloneInstanceSegment.setUsername(((StringLiteralValue) visitUsername(cloneInstance.username())).getValue());
529             cloneInstanceSegment.setHostname(((StringLiteralValue) visit(cloneInstance.hostname())).getValue());
530             cloneInstanceSegment.setPort(new NumberLiteralValue(cloneInstance.port().NUMBER_().getText()).getValue().intValue());
531             cloneInstanceSegment.setPassword(((StringLiteralValue) visit(ctx.string_())).getValue());
532             if (null != ctx.SSL() && null == ctx.NO()) {
533                 cloneInstanceSegment.setSslRequired(true);
534             }
535             result.setCloneInstance(cloneInstanceSegment);
536         }
537         if (null != ctx.cloneDir()) {
538             result.setCloneDir(((StringLiteralValue) visit(ctx.cloneDir())).getValue());
539         }
540         return result;
541     }
542     
543     @SuppressWarnings("unchecked")
544     @Override
545     public ASTNode visitOptimizeTable(final OptimizeTableContext ctx) {
546         MySQLOptimizeTableStatement result = new MySQLOptimizeTableStatement();
547         result.getTables().addAll(((CollectionValue<SimpleTableSegment>) visit(ctx.tableList())).getValue());
548         return result;
549     }
550     
551     @Override
552     public ASTNode visitUse(final UseContext ctx) {
553         MySQLUseStatement result = new MySQLUseStatement();
554         result.setSchema(((DatabaseSegment) visit(ctx.schemaName())).getIdentifier().getValue());
555         return result;
556     }
557     
558     @Override
559     public ASTNode visitExplain(final ExplainContext ctx) {
560         MySQLExplainStatement result = new MySQLExplainStatement();
561         if (null != ctx.tableName()) {
562             result.setTable((SimpleTableSegment) visit(ctx.tableName()));
563             if (null != ctx.columnRef()) {
564                 result.setColumnWild((ColumnSegment) visit(ctx.columnRef()));
565             } else if (null != ctx.textString()) {
566                 result.setColumnWild((ColumnSegment) visit(ctx.textString()));
567             }
568         } else if (null != ctx.explainableStatement()) {
569             result.setStatement((SQLStatement) visit(ctx.explainableStatement()));
570         } else if (null != ctx.select()) {
571             result.setStatement((SQLStatement) visit(ctx.select()));
572         } else if (null != ctx.delete()) {
573             result.setStatement((SQLStatement) visit(ctx.delete()));
574         } else if (null != ctx.update()) {
575             result.setStatement((SQLStatement) visit(ctx.update()));
576         } else if (null != ctx.insert()) {
577             result.setStatement((SQLStatement) visit(ctx.insert()));
578         }
579         return result;
580     }
581     
582     @Override
583     public ASTNode visitExplainableStatement(final ExplainableStatementContext ctx) {
584         if (null != ctx.select()) {
585             return visit(ctx.select());
586         }
587         if (null != ctx.delete()) {
588             return visit(ctx.delete());
589         }
590         if (null != ctx.insert()) {
591             return visit(ctx.insert());
592         }
593         if (null != ctx.replace()) {
594             return visit(ctx.replace());
595         }
596         return visit(ctx.update());
597     }
598     
599     @Override
600     public ASTNode visitShowProcedureCode(final ShowProcedureCodeContext ctx) {
601         MySQLShowProcedureCodeStatement result = new MySQLShowProcedureCodeStatement();
602         result.setFunction((FunctionSegment) visit(ctx.functionName()));
603         return result;
604     }
605     
606     @Override
607     public ASTNode visitShowProfile(final ShowProfileContext ctx) {
608         MySQLShowProfileStatement result = new MySQLShowProfileStatement();
609         if (null != ctx.limitClause()) {
610             result.setLimit((LimitSegment) visit(ctx.limitClause()));
611         }
612         return result;
613     }
614     
615     @Override
616     public ASTNode visitShowProfiles(final ShowProfilesContext ctx) {
617         return new MySQLShowProfilesStatement();
618     }
619     
620     @Override
621     public ASTNode visitShowDatabases(final ShowDatabasesContext ctx) {
622         MySQLShowDatabasesStatement result = new MySQLShowDatabasesStatement();
623         if (null != ctx.showFilter()) {
624             result.setFilter((ShowFilterSegment) visit(ctx.showFilter()));
625         }
626         result.addParameterMarkerSegments(getParameterMarkerSegments());
627         return result;
628     }
629     
630     @Override
631     public ASTNode visitShowEvents(final ShowEventsContext ctx) {
632         MySQLShowEventsStatement result = new MySQLShowEventsStatement();
633         if (null != ctx.fromSchema()) {
634             result.setFromSchema((FromSchemaSegment) visit(ctx.fromSchema()));
635         }
636         if (null != ctx.showFilter()) {
637             result.setFilter((ShowFilterSegment) visit(ctx.showFilter()));
638         }
639         result.addParameterMarkerSegments(getParameterMarkerSegments());
640         return result;
641     }
642     
643     @Override
644     public ASTNode visitShowTables(final ShowTablesContext ctx) {
645         MySQLShowTablesStatement result = new MySQLShowTablesStatement();
646         if (null != ctx.fromSchema()) {
647             result.setFromSchema((FromSchemaSegment) visit(ctx.fromSchema()));
648         }
649         if (null != ctx.showFilter()) {
650             result.setFilter((ShowFilterSegment) visit(ctx.showFilter()));
651         }
652         result.setContainsFull(null != ctx.FULL());
653         result.addParameterMarkerSegments(getParameterMarkerSegments());
654         return result;
655     }
656     
657     @Override
658     public ASTNode visitShowTriggers(final ShowTriggersContext ctx) {
659         MySQLShowTriggersStatement result = new MySQLShowTriggersStatement();
660         if (null != ctx.fromSchema()) {
661             result.setFromSchema((FromSchemaSegment) visit(ctx.fromSchema()));
662         }
663         if (null != ctx.showFilter()) {
664             result.setFilter((ShowFilterSegment) visit(ctx.showFilter()));
665         }
666         result.addParameterMarkerSegments(getParameterMarkerSegments());
667         return result;
668     }
669     
670     @Override
671     public ASTNode visitShowWhereClause(final ShowWhereClauseContext ctx) {
672         return new WhereSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (ExpressionSegment) visit(ctx.expr()));
673     }
674     
675     @Override
676     public ASTNode visitShowTableStatus(final ShowTableStatusContext ctx) {
677         MySQLShowTableStatusStatement result = new MySQLShowTableStatusStatement();
678         if (null != ctx.fromSchema()) {
679             result.setFromSchema((FromSchemaSegment) visit(ctx.fromSchema()));
680         }
681         if (null != ctx.showFilter()) {
682             result.setFilter((ShowFilterSegment) visit(ctx.showFilter()));
683         }
684         result.addParameterMarkerSegments(getParameterMarkerSegments());
685         return result;
686     }
687     
688     @Override
689     public ASTNode visitShowColumns(final ShowColumnsContext ctx) {
690         MySQLShowColumnsStatement result = new MySQLShowColumnsStatement();
691         if (null != ctx.fromTable()) {
692             result.setTable(((FromTableSegment) visit(ctx.fromTable())).getTable());
693         }
694         if (null != ctx.fromSchema()) {
695             result.setFromSchema((FromSchemaSegment) visit(ctx.fromSchema()));
696         }
697         if (null != ctx.showFilter()) {
698             result.setFilter((ShowFilterSegment) visit(ctx.showFilter()));
699         }
700         result.addParameterMarkerSegments(getParameterMarkerSegments());
701         return result;
702     }
703     
704     @Override
705     public ASTNode visitShowFilter(final ShowFilterContext ctx) {
706         ShowFilterSegment result = new ShowFilterSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex());
707         if (null != ctx.showLike()) {
708             result.setLike((ShowLikeSegment) visit(ctx.showLike()));
709         }
710         if (null != ctx.showWhereClause()) {
711             result.setWhere((WhereSegment) visit(ctx.showWhereClause()));
712         }
713         return result;
714     }
715     
716     @Override
717     public ASTNode visitShowIndex(final ShowIndexContext ctx) {
718         MySQLShowIndexStatement result = new MySQLShowIndexStatement();
719         if (null != ctx.fromSchema()) {
720             result.setFromSchema((FromSchemaSegment) visit(ctx.fromSchema()));
721         }
722         if (null != ctx.fromTable()) {
723             result.setTable(((FromTableSegment) visitFromTable(ctx.fromTable())).getTable());
724         }
725         return result;
726     }
727     
728     @Override
729     public ASTNode visitShowCreateTable(final ShowCreateTableContext ctx) {
730         MySQLShowCreateTableStatement result = new MySQLShowCreateTableStatement();
731         result.setTable((SimpleTableSegment) visit(ctx.tableName()));
732         return result;
733     }
734     
735     @Override
736     public ASTNode visitShowCreateTrigger(final ShowCreateTriggerContext ctx) {
737         MySQLShowCreateTriggerStatement result = new MySQLShowCreateTriggerStatement();
738         result.setName(((IdentifierValue) visit(ctx.triggerName())).getValue());
739         return result;
740     }
741     
742     @Override
743     public ASTNode visitShowRelaylogEvent(final ShowRelaylogEventContext ctx) {
744         MySQLShowRelayLogEventsStatement result = new MySQLShowRelayLogEventsStatement();
745         if (null != ctx.logName()) {
746             result.setLogName(((StringLiteralValue) visit(ctx.logName().stringLiterals().string_())).getValue());
747         }
748         if (null != ctx.limitClause()) {
749             result.setLimit((LimitSegment) visit(ctx.limitClause()));
750         }
751         if (null != ctx.channelName()) {
752             result.setChannel(((IdentifierValue) visit(ctx.channelName())).getValue());
753         }
754         return result;
755     }
756     
757     @Override
758     public ASTNode visitShowFunctionCode(final ShowFunctionCodeContext ctx) {
759         MySQLShowFunctionCodeStatement result = new MySQLShowFunctionCodeStatement();
760         result.setFunctionName(((FunctionSegment) visit(ctx.functionName())).getFunctionName());
761         return result;
762     }
763     
764     @Override
765     public ASTNode visitShowGrants(final ShowGrantsContext ctx) {
766         return new MySQLShowGrantsStatement();
767     }
768     
769     @Override
770     public ASTNode visitShowMasterStatus(final ShowMasterStatusContext ctx) {
771         return new MySQLShowMasterStatusStatement();
772     }
773     
774     @Override
775     public ASTNode visitShowSlaveHosts(final ShowSlaveHostsContext ctx) {
776         return new MySQLShowSlaveHostsStatement();
777     }
778     
779     @Override
780     public ASTNode visitShowReplicaStatus(final ShowReplicaStatusContext ctx) {
781         MySQLShowReplicaStatusStatement result = new MySQLShowReplicaStatusStatement();
782         if (null != ctx.channelName()) {
783             result.setChannel(((IdentifierValue) visit(ctx.channelName())).getValue());
784         }
785         return result;
786     }
787     
788     @Override
789     public ASTNode visitShowSlaveStatus(final ShowSlaveStatusContext ctx) {
790         MySQLShowSlaveStatusStatement result = new MySQLShowSlaveStatusStatement();
791         if (null != ctx.channelName()) {
792             result.setChannel(((IdentifierValue) visit(ctx.channelName())).getValue());
793         }
794         return result;
795     }
796     
797     @Override
798     public ASTNode visitCreateResourceGroup(final CreateResourceGroupContext ctx) {
799         MySQLCreateResourceGroupStatement result = new MySQLCreateResourceGroupStatement();
800         result.setGroupName(((IdentifierValue) visit(ctx.groupName())).getValue());
801         return result;
802     }
803     
804     @Override
805     public ASTNode visitBinlog(final BinlogContext ctx) {
806         return new MySQLBinlogStatement(((StringLiteralValue) visit(ctx.stringLiterals())).getValue());
807     }
808     
809     @Override
810     public ASTNode visitFromTable(final FromTableContext ctx) {
811         FromTableSegment result = new FromTableSegment();
812         result.setTable((SimpleTableSegment) visit(ctx.tableName()));
813         return result;
814     }
815     
816     @Override
817     public ASTNode visitShowVariables(final ShowVariablesContext ctx) {
818         MySQLShowVariablesStatement result = new MySQLShowVariablesStatement();
819         if (null != ctx.showFilter()) {
820             result.setFilter((ShowFilterSegment) visit(ctx.showFilter()));
821         }
822         result.addParameterMarkerSegments(getParameterMarkerSegments());
823         return result;
824     }
825     
826     @Override
827     public ASTNode visitShowCharacterSet(final ShowCharacterSetContext ctx) {
828         MySQLShowCharacterSetStatement result = new MySQLShowCharacterSetStatement();
829         if (null != ctx.showFilter()) {
830             result.setFilter((ShowFilterSegment) visit(ctx.showFilter()));
831         }
832         result.addParameterMarkerSegments(getParameterMarkerSegments());
833         return result;
834     }
835     
836     @Override
837     public ASTNode visitShowCollation(final ShowCollationContext ctx) {
838         MySQLShowCollationStatement result = new MySQLShowCollationStatement();
839         if (null != ctx.showFilter()) {
840             result.setFilter((ShowFilterSegment) visit(ctx.showFilter()));
841         }
842         result.addParameterMarkerSegments(getParameterMarkerSegments());
843         return result;
844     }
845     
846     @Override
847     public ASTNode visitShowFunctionStatus(final ShowFunctionStatusContext ctx) {
848         MySQLShowFunctionStatusStatement result = new MySQLShowFunctionStatusStatement();
849         if (null != ctx.showFilter()) {
850             result.setFilter((ShowFilterSegment) visit(ctx.showFilter()));
851         }
852         result.addParameterMarkerSegments(getParameterMarkerSegments());
853         return result;
854     }
855     
856     @Override
857     public ASTNode visitShowProcedureStatus(final ShowProcedureStatusContext ctx) {
858         MySQLShowProcedureStatusStatement result = new MySQLShowProcedureStatusStatement();
859         if (null != ctx.showFilter()) {
860             result.setFilter((ShowFilterSegment) visit(ctx.showFilter()));
861         }
862         result.addParameterMarkerSegments(getParameterMarkerSegments());
863         return result;
864     }
865     
866     @Override
867     public ASTNode visitShowOpenTables(final ShowOpenTablesContext ctx) {
868         MySQLShowOpenTablesStatement result = new MySQLShowOpenTablesStatement();
869         if (null != ctx.fromSchema()) {
870             result.setFromSchema((FromSchemaSegment) visit(ctx.fromSchema()));
871         }
872         if (null != ctx.showFilter()) {
873             result.setFilter((ShowFilterSegment) visit(ctx.showFilter()));
874         }
875         result.addParameterMarkerSegments(getParameterMarkerSegments());
876         return result;
877     }
878     
879     @Override
880     public ASTNode visitShowPlugins(final ShowPluginsContext ctx) {
881         return new MySQLShowPluginsStatement();
882     }
883     
884     @Override
885     public ASTNode visitShowPrivileges(final ShowPrivilegesContext ctx) {
886         return new MySQLShowPrivilegesStatement();
887     }
888     
889     @Override
890     public ASTNode visitShutdown(final ShutdownContext ctx) {
891         return new MySQLShutdownStatement();
892     }
893     
894     @Override
895     public ASTNode visitShowProcesslist(final ShowProcesslistContext ctx) {
896         return new MySQLShowProcessListStatement(null != ctx.FULL());
897     }
898     
899     @Override
900     public ASTNode visitShowCreateUser(final ShowCreateUserContext ctx) {
901         MySQLShowCreateUserStatement result = new MySQLShowCreateUserStatement();
902         result.setName(((IdentifierValue) visit(ctx.username())).getValue());
903         return result;
904     }
905     
906     @Override
907     public ASTNode visitSetVariable(final SetVariableContext ctx) {
908         MySQLSetStatement result = new MySQLSetStatement();
909         Collection<VariableAssignSegment> variableAssigns = getVariableAssigns(ctx.optionValueList());
910         result.getVariableAssigns().addAll(variableAssigns);
911         return result;
912     }
913     
914     private Collection<VariableAssignSegment> getVariableAssigns(final OptionValueListContext ctx) {
915         Collection<VariableAssignSegment> result = new LinkedList<>();
916         if (null == ctx.optionValueNoOptionType()) {
917             VariableAssignSegment variableAssign = new VariableAssignSegment();
918             variableAssign.setStartIndex(ctx.start.getStartIndex());
919             variableAssign.setStopIndex(ctx.setExprOrDefault().stop.getStopIndex());
920             VariableSegment variable = new VariableSegment(ctx.internalVariableName().start.getStartIndex(), ctx.internalVariableName().stop.getStopIndex(), ctx.internalVariableName().getText());
921             variable.setScope(ctx.optionType().getText());
922             variableAssign.setVariable(variable);
923             variableAssign.setAssignValue(ctx.setExprOrDefault().getText());
924             result.add(variableAssign);
925         } else {
926             result.add(getVariableAssign(ctx.optionValueNoOptionType()));
927         }
928         for (OptionValueContext each : ctx.optionValue()) {
929             result.add(getVariableAssign(each));
930         }
931         return result;
932     }
933     
934     private VariableAssignSegment getVariableAssign(final OptionValueNoOptionTypeContext ctx) {
935         VariableAssignSegment result = new VariableAssignSegment();
936         result.setStartIndex(ctx.start.getStartIndex());
937         result.setStopIndex(ctx.stop.getStopIndex());
938         if (null != ctx.NAMES()) {
939             // TODO Consider setting all three system variables: character_set_client, character_set_results, character_set_connection
940             result.setVariable(new VariableSegment(ctx.NAMES().getSymbol().getStartIndex(), ctx.NAMES().getSymbol().getStopIndex(), "character_set_client"));
941             result.setAssignValue(ctx.charsetName().getText());
942         } else if (null != ctx.internalVariableName()) {
943             result.setVariable(new VariableSegment(ctx.internalVariableName().start.getStartIndex(), ctx.internalVariableName().stop.getStopIndex(), ctx.internalVariableName().getText()));
944             result.setAssignValue(ctx.setExprOrDefault().getText());
945         } else if (null != ctx.userVariable()) {
946             result.setVariable(new VariableSegment(ctx.userVariable().start.getStartIndex(), ctx.userVariable().stop.getStopIndex(), ctx.userVariable().getText()));
947             result.setAssignValue(ctx.expr().getText());
948         } else if (null != ctx.setSystemVariable()) {
949             VariableSegment variable = new VariableSegment(
950                     ctx.setSystemVariable().start.getStartIndex(), ctx.setSystemVariable().stop.getStopIndex(), ctx.setSystemVariable().internalVariableName().getText());
951             result.setVariable(variable);
952             result.setAssignValue(ctx.setExprOrDefault().getText());
953             OptionTypeContext optionType = ctx.setSystemVariable().optionType();
954             variable.setScope(null != optionType ? optionType.getText() : "SESSION");
955         }
956         return result;
957     }
958     
959     private VariableAssignSegment getVariableAssign(final OptionValueContext ctx) {
960         if (null != ctx.optionValueNoOptionType()) {
961             return getVariableAssign(ctx.optionValueNoOptionType());
962         }
963         VariableAssignSegment result = new VariableAssignSegment();
964         result.setStartIndex(ctx.start.getStartIndex());
965         result.setStopIndex(ctx.stop.getStopIndex());
966         VariableSegment variable = new VariableSegment(ctx.internalVariableName().start.getStartIndex(), ctx.internalVariableName().stop.getStopIndex(), ctx.internalVariableName().getText());
967         variable.setScope(ctx.optionType().getText());
968         result.setVariable(variable);
969         result.setAssignValue(ctx.setExprOrDefault().getText());
970         return result;
971     }
972     
973     @Override
974     public ASTNode visitSetCharacter(final SetCharacterContext ctx) {
975         VariableAssignSegment characterSet = new VariableAssignSegment();
976         int startIndex = null == ctx.CHARSET() ? ctx.CHARACTER().getSymbol().getStartIndex() : ctx.CHARSET().getSymbol().getStartIndex();
977         int stopIndex = null == ctx.CHARSET() ? ctx.SET(1).getSymbol().getStopIndex() : ctx.CHARSET().getSymbol().getStopIndex();
978         // TODO Consider setting all three system variables: character_set_client, character_set_results, character_set_connection
979         String variableName = (null != ctx.CHARSET()) ? ctx.CHARSET().getText() : "character_set_client";
980         VariableSegment variable = new VariableSegment(startIndex, stopIndex, variableName);
981         characterSet.setVariable(variable);
982         String assignValue = (null != ctx.DEFAULT()) ? ctx.DEFAULT().getText() : ctx.charsetName().getText();
983         characterSet.setAssignValue(assignValue);
984         MySQLSetStatement result = new MySQLSetStatement();
985         result.getVariableAssigns().add(characterSet);
986         return result;
987     }
988     
989     @Override
990     public ASTNode visitFromSchema(final FromSchemaContext ctx) {
991         return new FromSchemaSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (DatabaseSegment) visit(ctx.schemaName()));
992     }
993     
994     @Override
995     public ASTNode visitShowLike(final ShowLikeContext ctx) {
996         StringLiteralValue literalValue = (StringLiteralValue) visit(ctx.stringLiterals());
997         return new ShowLikeSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), literalValue.getValue());
998     }
999     
1000     @Override
1001     public ASTNode visitCreateLoadableFunction(final CreateLoadableFunctionContext ctx) {
1002         return new MySQLCreateLoadableFunctionStatement();
1003     }
1004     
1005     @Override
1006     public ASTNode visitInstallComponent(final InstallComponentContext ctx) {
1007         MySQLInstallComponentStatement result = new MySQLInstallComponentStatement();
1008         List<String> components = new LinkedList<>();
1009         for (ComponentNameContext each : ctx.componentName()) {
1010             components.add(((StringLiteralValue) visit(each.string_())).getValue());
1011         }
1012         result.getComponents().addAll(components);
1013         return result;
1014     }
1015     
1016     @Override
1017     public ASTNode visitUninstallComponent(final UninstallComponentContext ctx) {
1018         MySQLUninstallComponentStatement result = new MySQLUninstallComponentStatement();
1019         List<String> components = new LinkedList<>();
1020         for (ComponentNameContext each : ctx.componentName()) {
1021             components.add(((StringLiteralValue) visit(each.string_())).getValue());
1022         }
1023         result.getComponents().addAll(components);
1024         return result;
1025     }
1026     
1027     @Override
1028     public ASTNode visitRestart(final RestartContext ctx) {
1029         return new MySQLRestartStatement();
1030     }
1031     
1032     @Override
1033     public ASTNode visitSetResourceGroup(final SetResourceGroupContext ctx) {
1034         MySQLSetResourceGroupStatement result = new MySQLSetResourceGroupStatement();
1035         result.setGroupName(((IdentifierValue) visit(ctx.groupName())).getValue());
1036         return result;
1037     }
1038     
1039     @Override
1040     public ASTNode visitCheckTable(final CheckTableContext ctx) {
1041         MySQLCheckTableStatement result = new MySQLCheckTableStatement();
1042         result.getTables().addAll(((CollectionValue<SimpleTableSegment>) visit(ctx.tableList())).getValue());
1043         return result;
1044     }
1045     
1046     @Override
1047     public ASTNode visitDropResourceGroup(final DropResourceGroupContext ctx) {
1048         MySQLDropResourceGroupStatement result = new MySQLDropResourceGroupStatement();
1049         result.setGroupName(((IdentifierValue) visit(ctx.groupName())).getValue());
1050         return result;
1051     }
1052     
1053     @Override
1054     public ASTNode visitAlterResourceGroup(final AlterResourceGroupContext ctx) {
1055         MySQLAlterResourceGroupStatement result = new MySQLAlterResourceGroupStatement();
1056         result.setGroupName(((IdentifierValue) visit(ctx.groupName())).getValue());
1057         return result;
1058     }
1059     
1060     @Override
1061     public ASTNode visitDelimiter(final DelimiterContext ctx) {
1062         MySQLDelimiterStatement result = new MySQLDelimiterStatement();
1063         result.setDelimiterName(ctx.delimiterName().getText());
1064         return result;
1065     }
1066     
1067     @Override
1068     public ASTNode visitHelp(final HelpContext ctx) {
1069         MySQLHelpStatement result = new MySQLHelpStatement();
1070         result.setSearchString(ctx.textOrIdentifier().getText());
1071         return result;
1072     }
1073 }