private Call parseCall() { Call command = new Call(session); currentPrepared = command; command.setExpression(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 Prepared parseBackup() { BackupCommand command = new BackupCommand(session); read("TO"); command.setFileName(readExpression()); return command; }
private JavaAggregate readJavaAggregate(UserAggregate aggregate) { ArrayList<Expression> params = New.arrayList(); do { params.add(readExpression()); } while (readIfMore(true)); Expression filterCondition; if (readIf("FILTER")) { read("("); read("WHERE"); filterCondition = readExpression(); read(")"); } else { filterCondition = null; } Expression[] list = params.toArray(new Expression[0]); JavaAggregate agg = new JavaAggregate(aggregate, list, currentSelect, filterCondition); currentSelect.setGroupQuery(); return agg; }
private ArrayList<SelectOrderBy> parseSimpleOrderList() { ArrayList<SelectOrderBy> orderList = New.arrayList(); do { SelectOrderBy order = new SelectOrderBy(); order.expression = readExpression(); if (readIf("DESC")) { order.descending = true; } else { readIf("ASC"); } orderList.add(order); } while (readIf(",")); return orderList; }
private String readString() { Expression expr = readExpression().optimize(session); if (!(expr instanceof ValueExpression)) { throw DbException.getSyntaxError(sqlCommand, parseIndex, "string"); } return expr.getValue(session).getString(); }
private JavaFunction readJavaFunction(Schema schema, String functionName) { FunctionAlias functionAlias = null; if (schema != null) { functionAlias = schema.findFunction(functionName); } else { functionAlias = findFunctionAlias(session.getCurrentSchemaName(), functionName); } if (functionAlias == null) { throw DbException.get(ErrorCode.FUNCTION_NOT_FOUND_1, functionName); } Expression[] args; ArrayList<Expression> argList = New.arrayList(); int numArgs = 0; while (!readIf(")")) { if (numArgs++ > 0) { read(","); } argList.add(readExpression()); } args = argList.toArray(new Expression[0]); return new JavaFunction(functionAlias, args); }
private void parseDeleteGivenTable(Delete command, Expression limit, int start) { 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); }
private RunScriptCommand parseRunScript() { RunScriptCommand command = new RunScriptCommand(session); read("FROM"); command.setFileNameExpr(readExpression()); if (readIf("COMPRESSION")) { command.setCompressionAlgorithm(readUniqueIdentifier()); } if (readIf("CIPHER")) { command.setCipher(readUniqueIdentifier()); if (readIf("PASSWORD")) { command.setPassword(readExpression()); } } if (readIf("CHARSET")) { command.setCharset(Charset.forName(readString())); } return command; }
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 Prepared parseExecute() { ExecuteProcedure command = new ExecuteProcedure(session); String procedureName = readAliasIdentifier(); Procedure p = session.getProcedure(procedureName); if (p == null) { throw DbException.get(ErrorCode.FUNCTION_ALIAS_NOT_FOUND_1, procedureName); } command.setProcedure(p); if (readIf("(")) { for (int i = 0;; i++) { command.setExpression(i, readExpression()); if (readIf(")")) { break; } read(","); } } 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; }
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; }
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)));
values.add(null); } else { values.add(readExpression());
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();
expressions.add(new Wildcard(null, null)); } else { Expression expr = readExpression(); if (readIf("AS") || currentTokenType == IDENTIFIER) { String alias = readAliasIdentifier();
expression = ValueExpression.getDefault(); } else { expression = readExpression();