private Call parseCall() { Call command = new Call(session); currentPrepared = command; command.setExpression(readExpression()); return command; }
private Prepared parseBackup() { BackupCommand command = new BackupCommand(session); read("TO"); command.setFileName(readExpression()); return command; }
/** * Parse a SQL code snippet that represents an expression. * * @param sql the code snippet * @return the expression object */ public Expression parseExpression(String sql) { parameters = New.arrayList(); initialize(sql); read(); return readExpression(); }
private String readString() { Expression expr = readExpression().optimize(session); if (!(expr instanceof ValueExpression)) { throw DbException.getSyntaxError(sqlCommand, parseIndex, "string"); } String s = expr.getValue(session).getString(); return s; }
private ArrayList<SelectOrderBy> parseSimpleOrderList() { ArrayList<SelectOrderBy> orderList = New.arrayList(); do { SelectOrderBy order = new SelectOrderBy(); Expression expr = readExpression(); order.expression = expr; if (readIf("DESC")) { order.descending = true; } else { readIf("ASC"); } orderList.add(order); } while (readIf(",")); return orderList; }
Expression elsePart = readExpression().optimize(session); read("END"); readIf("CASE"); i = 1; do { function.setParameter(i++, readExpression()); read("THEN"); function.setParameter(i++, readExpression()); } while (readIf("WHEN")); } else { Expression expr = readExpression(); if (readIf("END")) { readIf("CASE"); Expression elsePart = readExpression().optimize(session); read("END"); readIf("CASE"); read("WHEN"); do { function.setParameter(i++, readExpression()); read("THEN"); function.setParameter(i++, readExpression()); } while (readIf("WHEN")); function.setParameter(i, readExpression());
} else { boolean distinct = readIf("DISTINCT"); Expression on = readExpression(); if (on instanceof Wildcard && !distinct) { boolean distinct = readIf("DISTINCT"); Aggregate agg = new Aggregate(Aggregate.GROUP_CONCAT, readExpression(), currentSelect, distinct); if (readIf("ORDER")) { read("BY"); agg.setGroupConcatSeparator(readExpression()); r = new Aggregate(aggregateType, readExpression(), currentSelect, distinct);
private CreateUser parseCreateUser() { CreateUser command = new CreateUser(session); command.setIfNotExists(readIfNotExists()); command.setUserName(readUniqueIdentifier()); command.setComment(readCommentIf()); if (readIf("PASSWORD")) { command.setPassword(readExpression()); } else if (readIf("SALT")) { command.setSalt(readExpression()); read("HASH"); command.setHash(readExpression()); } else if (readIf("IDENTIFIED")) { read("BY"); // uppercase if not quoted command.setPassword(ValueExpression.get(ValueString .get(readColumnIdentifier()))); } else { throw getSyntaxError(); } if (readIf("ADMIN")) { command.setAdmin(true); } return command; }
private CreateConstant parseCreateConstant() { boolean ifNotExists = readIfNotExists(); String constantName = readIdentifierWithSchema(); Schema schema = getSchema(); if (isKeyword(constantName)) { throw DbException.get(ErrorCode.CONSTANT_ALREADY_EXISTS_1, constantName); } read("VALUE"); Expression expr = readExpression(); CreateConstant command = new CreateConstant(session, schema); command.setConstantName(constantName); command.setExpression(expr); command.setIfNotExists(ifNotExists); return command; }
values.add(null); } else { values.add(readExpression());
read(")"); read("="); Expression expression = readExpression(); if (columns.size() == 1) { expression = ValueExpression.getDefault(); } else { expression = readExpression(); Expression condition = readExpression(); command.setCondition(condition);
private CreateUserDataType parseCreateUserDataType() { boolean ifNotExists = readIfNotExists(); CreateUserDataType command = new CreateUserDataType(session); command.setTypeName(readUniqueIdentifier()); read("AS"); Column col = parseColumnForTable("VALUE", true); if (readIf("CHECK")) { Expression expr = readExpression(); col.addCheckConstraint(session, expr); } col.rename(null); command.setColumn(col); command.setIfNotExists(ifNotExists); return command; }
Expression condition = readExpression(); command.addCondition(condition); ArrayList<Expression> list = New.arrayList(); do { Expression expr = readExpression(); list.add(expr); } while (readIf(",")); if (readIf("HAVING")) { command.setGroupQuery(); Expression condition = readExpression(); command.setHaving(condition);
values.add(null); } else { values.add(readExpression()); expression = ValueExpression.getDefault(); } else { expression = readExpression(); expression = ValueExpression.getDefault(); } else { expression = readExpression();
if (readIf("RESTART")) { read("WITH"); command.setStartWith(readExpression()); } else if (readIf("INCREMENT")) { read("BY"); command.setIncrement(readExpression()); } else if (readIf("MINVALUE")) { command.setMinValue(readExpression()); } else if (readIf("NOMINVALUE")) { command.setMinValue(null); } else if (readIf("MAXVALUE")) { command.setMaxValue(readExpression()); } else if (readIf("NOMAXVALUE")) { command.setMaxValue(null); command.setCacheSize(readExpression()); } else if (readIf("NOCACHE")) { command.setCacheSize(ValueExpression.get(ValueLong.get(1)));
values.add(null); } else { values.add(readExpression());
if (readIf("START")) { readIf("WITH"); command.setStartWith(readExpression()); } else if (readIf("INCREMENT")) { readIf("BY"); command.setIncrement(readExpression()); } else if (readIf("MINVALUE")) { command.setMinValue(readExpression()); } else if (readIf("NOMINVALUE")) { command.setMinValue(null); } else if (readIf("MAXVALUE")) { command.setMaxValue(readExpression()); } else if (readIf("NOMAXVALUE")) { command.setMaxValue(null); command.setCacheSize(readExpression()); } else if (readIf("NOCACHE")) { command.setCacheSize(ValueExpression.get(ValueLong.get(1)));
command.setUser(database.getUser(userName)); if (readIf("PASSWORD")) { command.setPassword(readExpression()); } else if (readIf("SALT")) { command.setSalt(readExpression()); read("HASH"); command.setHash(readExpression()); } else { throw getSyntaxError();
private Delete parseDelete() { Delete command = new Delete(session); Expression limit = null; if (readIf("TOP")) { limit = readTerm().optimize(session); } currentPrepared = command; int start = lastParseIndex; readIf("FROM"); TableFilter filter = readSimpleTableFilter(); command.setTableFilter(filter); if (readIf("WHERE")) { Expression condition = readExpression(); command.setCondition(condition); } if (readIf("LIMIT") && limit == null) { limit = readTerm().optimize(session); } command.setLimit(limit); setSQL(command, "DELETE", start); return command; }
expressions.add(new Wildcard(null, null)); } else { Expression expr = readExpression(); if (readIf("AS") || currentTokenType == IDENTIFIER) { String alias = readAliasIdentifier();