Revision 44858 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/expressionevaluator/impl/grammars/DataAccessGrammarFactory.java
DataAccessGrammarFactory.java | ||
---|---|---|
95 | 95 |
@Override |
96 | 96 |
public Codes build(StatementContext context) { |
97 | 97 |
context.trace(this.toString() + ".build"); |
98 |
|
|
99 |
CodeBuilder codeBuilder = context.getCodeBuilder(); |
|
100 |
BaseCodes args = (BaseCodes) codeBuilder.args(); |
|
101 |
return build(context,args); |
|
102 |
} |
|
103 |
|
|
104 |
public Codes build(StatementContext context, BaseCodes args) { |
|
98 | 105 |
int n; |
99 | 106 |
BaseCodes argsX; |
100 | 107 |
|
101 | 108 |
CodeBuilder codeBuilder = context.getCodeBuilder(); |
102 |
BaseCodes args = (BaseCodes) codeBuilder.args(); |
|
103 | 109 |
|
104 | 110 |
Code columns = context.getCode("COLUMNS"); |
105 | 111 |
args.add(columns); |
... | ... | |
151 | 157 |
} |
152 | 158 |
|
153 | 159 |
} |
160 |
private static class InsertIntoArgsBuilder |
|
161 |
extends SelectArgsBuilder |
|
162 |
implements ArgsBuilder |
|
163 |
{ |
|
154 | 164 |
|
165 |
public InsertIntoArgsBuilder() { |
|
166 |
} |
|
167 |
|
|
168 |
@Override |
|
169 |
public String toString() { |
|
170 |
return "insert_into_args()"; |
|
171 |
} |
|
172 |
|
|
173 |
@Override |
|
174 |
public Codes build(StatementContext context) { |
|
175 |
context.trace(this.toString() + ".build"); |
|
176 |
|
|
177 |
CodeBuilder codeBuilder = context.getCodeBuilder(); |
|
178 |
BaseCodes args = (BaseCodes) codeBuilder.args(); |
|
179 |
|
|
180 |
Code table = context.getCode("TARGETTABLE"); |
|
181 |
args.add(codeBuilder.identifier((String) ((Code.Constant) table).value())); |
|
182 |
|
|
183 |
return build(context,args); |
|
184 |
} |
|
185 |
|
|
186 |
} |
|
187 |
|
|
155 | 188 |
private static class SelectCountArgsBuilder implements ArgsBuilder { |
156 | 189 |
|
157 | 190 |
public SelectCountArgsBuilder() { |
... | ... | |
227 | 260 |
); |
228 | 261 |
theGrammar.addStatement(stmt); |
229 | 262 |
|
263 |
stmt = theGrammar.createStatement("CREATE_IN_MEMORY_TABLE"); |
|
264 |
stmt.addRule(stmt.require_any_token("CREATE")); |
|
265 |
stmt.addRule(stmt.require_any_token("IN")); |
|
266 |
stmt.addRule(stmt.require_any_token("MEMORY")); |
|
267 |
stmt.addRule(stmt.require_any_token("TABLE")); |
|
268 |
stmt.addRule(stmt.require_identifier().capture_as("NEWTABLE")); |
|
269 |
stmt.addRule(stmt.require_any_token("FROM")); |
|
270 |
stmt.addRule(stmt.require_identifier().capture_as("SOURCETABLE")); |
|
271 |
stmt.code( |
|
272 |
FUNCTION_FOREING_VALUE, |
|
273 |
stmt.args_names("NEWTABLE","SOURCETABLE") |
|
274 |
); |
|
275 |
theGrammar.addStatement(stmt); |
|
276 |
|
|
230 | 277 |
stmt = theGrammar.createStatement("SELECT"); |
231 | 278 |
stmt.addRule(stmt.require_any_token("SELECT")); |
232 | 279 |
stmt.addRule(stmt.optional_any_token("*") |
... | ... | |
263 | 310 |
); |
264 | 311 |
theGrammar.addStatement(stmt); |
265 | 312 |
|
313 |
stmt = theGrammar.createStatement("INSERT_INTO"); |
|
314 |
stmt.addRule(stmt.require_any_token("INSERT")); |
|
315 |
stmt.addRule(stmt.require_any_token("INTO")); |
|
316 |
stmt.addRule(stmt.require_identifier().capture_as("TARGETTABLE")); |
|
317 |
stmt.addRule(stmt.require_any_token("SELECT")); |
|
318 |
stmt.addRule(stmt.optional_any_token("*") |
|
319 |
.addRuleOnTrue(stmt.set_expression("COLUMNS", codeBuilder.tuple())) |
|
320 |
.addRuleOnFalse(stmt.require_identifiers(",").capture_as("COLUMNS")) |
|
321 |
); |
|
322 |
stmt.addRule(stmt.require_any_token("FROM")); |
|
323 |
stmt.addRule(stmt.require_identifier().capture_as("TABLE")); |
|
324 |
stmt.addRule(stmt.optional_any_token("WHERE") |
|
325 |
.addRuleOnTrue(stmt.require_expression().capture_as("WHERE")) |
|
326 |
); |
|
327 |
|
|
328 |
stmt.addRule(stmt.optional_any_token("ORDER") |
|
329 |
.addRuleOnTrue(stmt.require_any_token("BY")) |
|
330 |
.addRuleOnTrue(stmt.repeat() |
|
331 |
.addRule(stmt.require_expression().capture_as("ORDER#")) |
|
332 |
.addRule(stmt.switch_token() |
|
333 |
.addCase("ASC", stmt.set_expression("ORDER_MODE#", true)) |
|
334 |
.addCase("DESC", stmt.set_expression("ORDER_MODE#", false)) |
|
335 |
.addDefault(stmt.set_expression("ORDER_MODE#", true)) |
|
336 |
) |
|
337 |
.addRule(stmt.optional_any_token(",") |
|
338 |
.addRuleOnFalse(stmt.break_loop()) |
|
339 |
) |
|
340 |
) |
|
341 |
); |
|
342 |
stmt.addRule(stmt.optional_any_token("LIMIT") |
|
343 |
.addRuleOnTrue(stmt.require_expression().capture_as("LIMIT")) |
|
344 |
); |
|
345 |
stmt.addRule(stmt.optional_any_token(";")); |
|
346 |
stmt.code( |
|
347 |
FUNCTION_SELECT, |
|
348 |
new InsertIntoArgsBuilder() |
|
349 |
); |
|
350 |
theGrammar.addStatement(stmt); |
|
351 |
|
|
266 | 352 |
stmt = theGrammar.createStatement("SELECT_COUNT"); |
267 | 353 |
stmt.addRule(stmt.require_any_token("SELECT")); |
268 | 354 |
stmt.addRule(stmt.require_any_token("COUNT")); |
Also available in: Unified diff