use of com.alibaba.druid.sql.ast.SQLExpr in project druid by alibaba.
the class MySqlExprParser method parseAggregateExprRest.
protected SQLAggregateExpr parseAggregateExprRest(SQLAggregateExpr aggregateExpr) {
if (lexer.token() == Token.ORDER) {
SQLOrderBy orderBy = this.parseOrderBy();
aggregateExpr.putAttribute("ORDER BY", orderBy);
}
if (identifierEquals("SEPARATOR")) {
lexer.nextToken();
SQLExpr seperator = this.primary();
aggregateExpr.putAttribute("SEPARATOR", seperator);
}
return aggregateExpr;
}
use of com.alibaba.druid.sql.ast.SQLExpr in project druid by alibaba.
the class DB2SelectParser method query.
@Override
public SQLSelectQuery query() {
if (lexer.token() == Token.LPAREN) {
lexer.nextToken();
SQLSelectQuery select = query();
accept(Token.RPAREN);
return queryRest(select);
}
accept(Token.SELECT);
if (lexer.token() == Token.COMMENT) {
lexer.nextToken();
}
DB2SelectQueryBlock queryBlock = new DB2SelectQueryBlock();
if (lexer.token() == Token.DISTINCT) {
queryBlock.setDistionOption(SQLSetQuantifier.DISTINCT);
lexer.nextToken();
} else if (lexer.token() == Token.UNIQUE) {
queryBlock.setDistionOption(SQLSetQuantifier.UNIQUE);
lexer.nextToken();
} else if (lexer.token() == Token.ALL) {
queryBlock.setDistionOption(SQLSetQuantifier.ALL);
lexer.nextToken();
}
parseSelectList(queryBlock);
parseFrom(queryBlock);
parseWhere(queryBlock);
parseGroupBy(queryBlock);
if (lexer.token() == Token.ORDER) {
SQLOrderBy orderBy = parseOrderBy();
queryBlock.setOrderBy(orderBy);
}
for (; ; ) {
if (lexer.token() == Token.FETCH) {
lexer.nextToken();
accept(Token.FIRST);
SQLExpr first = this.exprParser.primary();
queryBlock.setFirst(first);
if (identifierEquals("ROW") || identifierEquals("ROWS")) {
lexer.nextToken();
}
accept(Token.ONLY);
continue;
}
if (lexer.token() == Token.WITH) {
lexer.nextToken();
if (identifierEquals("RR")) {
queryBlock.setIsolation(Isolation.RR);
} else if (identifierEquals("RS")) {
queryBlock.setIsolation(Isolation.RS);
} else if (identifierEquals("CS")) {
queryBlock.setIsolation(Isolation.CS);
} else if (identifierEquals("UR")) {
queryBlock.setIsolation(Isolation.UR);
} else {
throw new ParserException("TODO");
}
lexer.nextToken();
continue;
}
if (lexer.token() == Token.FOR) {
lexer.nextToken();
if (lexer.token() == Token.UPDATE) {
queryBlock.setForUpdate(true);
lexer.nextToken();
} else {
acceptIdentifier("READ");
accept(Token.ONLY);
queryBlock.setForReadOnly(true);
}
}
if (lexer.token() == Token.OPTIMIZE) {
lexer.nextToken();
accept(Token.FOR);
queryBlock.setOptimizeFor(this.expr());
if (identifierEquals("ROW")) {
lexer.nextToken();
} else {
acceptIdentifier("ROWS");
}
}
break;
}
return queryRest(queryBlock);
}
use of com.alibaba.druid.sql.ast.SQLExpr in project druid by alibaba.
the class OracleSelectParser method parseInto.
protected void parseInto(OracleSelectQueryBlock x) {
if (lexer.token() == Token.INTO) {
lexer.nextToken();
SQLExpr expr = expr();
if (lexer.token() != Token.COMMA) {
x.setInto(expr);
return;
}
SQLListExpr list = new SQLListExpr();
list.addItem(expr);
while (lexer.token() == Token.COMMA) {
lexer.nextToken();
list.addItem(expr());
}
x.setInto(list);
}
}
use of com.alibaba.druid.sql.ast.SQLExpr in project druid by alibaba.
the class OracleStatementParser method parserAlter.
public SQLStatement parserAlter() {
accept(Token.ALTER);
if (lexer.token() == Token.SESSION) {
lexer.nextToken();
OracleAlterSessionStatement stmt = new OracleAlterSessionStatement();
if (lexer.token() == Token.SET) {
lexer.nextToken();
parseAssignItems(stmt.getItems(), stmt);
} else {
throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
}
return stmt;
} else if (lexer.token() == Token.PROCEDURE) {
lexer.nextToken();
OracleAlterProcedureStatement stmt = new OracleAlterProcedureStatement();
stmt.setName(this.exprParser.name());
if (identifierEquals("COMPILE")) {
lexer.nextToken();
stmt.setCompile(true);
}
if (identifierEquals("REUSE")) {
lexer.nextToken();
acceptIdentifier("SETTINGS");
stmt.setReuseSettings(true);
}
return stmt;
} else if (lexer.token() == Token.TABLE) {
return parseAlterTable();
} else if (lexer.token() == Token.INDEX) {
lexer.nextToken();
OracleAlterIndexStatement stmt = new OracleAlterIndexStatement();
stmt.setName(this.exprParser.name());
if (identifierEquals("RENAME")) {
lexer.nextToken();
accept(Token.TO);
stmt.setRenameTo(this.exprParser.name());
}
for (; ; ) {
if (identifierEquals("rebuild")) {
lexer.nextToken();
OracleAlterIndexStatement.Rebuild rebuild = new OracleAlterIndexStatement.Rebuild();
stmt.setRebuild(rebuild);
continue;
} else if (identifierEquals("MONITORING")) {
lexer.nextToken();
acceptIdentifier("USAGE");
stmt.setMonitoringUsage(Boolean.TRUE);
continue;
} else if (identifierEquals("PARALLEL")) {
lexer.nextToken();
stmt.setParallel(this.exprParser.expr());
}
break;
}
return stmt;
} else if (lexer.token() == Token.TRIGGER) {
lexer.nextToken();
OracleAlterTriggerStatement stmt = new OracleAlterTriggerStatement();
stmt.setName(this.exprParser.name());
for (; ; ) {
if (lexer.token() == Token.ENABLE) {
lexer.nextToken();
stmt.setEnable(Boolean.TRUE);
continue;
} else if (lexer.token() == Token.DISABLE) {
lexer.nextToken();
stmt.setEnable(Boolean.FALSE);
continue;
} else if (identifierEquals("COMPILE")) {
lexer.nextToken();
stmt.setCompile(true);
continue;
}
break;
}
return stmt;
} else if (identifierEquals("SYNONYM")) {
lexer.nextToken();
OracleAlterSynonymStatement stmt = new OracleAlterSynonymStatement();
stmt.setName(this.exprParser.name());
for (; ; ) {
if (lexer.token() == Token.ENABLE) {
lexer.nextToken();
stmt.setEnable(Boolean.TRUE);
continue;
} else if (lexer.token() == Token.DISABLE) {
lexer.nextToken();
stmt.setEnable(Boolean.FALSE);
continue;
} else if (identifierEquals("COMPILE")) {
lexer.nextToken();
stmt.setCompile(true);
continue;
}
break;
}
return stmt;
} else if (lexer.token() == Token.VIEW) {
lexer.nextToken();
OracleAlterViewStatement stmt = new OracleAlterViewStatement();
stmt.setName(this.exprParser.name());
for (; ; ) {
if (lexer.token() == Token.ENABLE) {
lexer.nextToken();
stmt.setEnable(Boolean.TRUE);
continue;
} else if (lexer.token() == Token.DISABLE) {
lexer.nextToken();
stmt.setEnable(Boolean.FALSE);
continue;
} else if (identifierEquals("COMPILE")) {
lexer.nextToken();
stmt.setCompile(true);
continue;
}
break;
}
return stmt;
} else if (lexer.token() == Token.TABLESPACE) {
lexer.nextToken();
OracleAlterTablespaceStatement stmt = new OracleAlterTablespaceStatement();
stmt.setName(this.exprParser.name());
if (identifierEquals("ADD")) {
lexer.nextToken();
if (identifierEquals("DATAFILE")) {
lexer.nextToken();
OracleAlterTablespaceAddDataFile item = new OracleAlterTablespaceAddDataFile();
for (; ; ) {
OracleFileSpecification file = new OracleFileSpecification();
for (; ; ) {
SQLExpr fileName = this.exprParser.expr();
file.getFileNames().add(fileName);
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
}
break;
}
if (identifierEquals("SIZE")) {
lexer.nextToken();
file.setSize(this.exprParser.expr());
}
if (identifierEquals("AUTOEXTEND")) {
lexer.nextToken();
if (identifierEquals("OFF")) {
lexer.nextToken();
file.setAutoExtendOff(true);
} else if (identifierEquals("ON")) {
lexer.nextToken();
file.setAutoExtendOn(this.exprParser.expr());
} else {
throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
}
}
item.getFiles().add(file);
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
}
break;
}
stmt.setItem(item);
} else {
throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
}
} else {
throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
}
return stmt;
}
throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
}
use of com.alibaba.druid.sql.ast.SQLExpr in project druid by alibaba.
the class OracleCreateTableParser method subPartitionBy.
protected SQLSubPartitionBy subPartitionBy() {
lexer.nextToken();
accept(Token.BY);
if (identifierEquals("HASH")) {
lexer.nextToken();
accept(Token.LPAREN);
SQLSubPartitionByHash byHash = new SQLSubPartitionByHash();
SQLExpr expr = this.exprParser.expr();
byHash.setExpr(expr);
accept(Token.RPAREN);
return byHash;
} else if (identifierEquals("LIST")) {
lexer.nextToken();
accept(Token.LPAREN);
SQLSubPartitionByList byList = new SQLSubPartitionByList();
SQLName column = this.exprParser.name();
byList.setColumn(column);
accept(Token.RPAREN);
if (identifierEquals("SUBPARTITION")) {
lexer.nextToken();
acceptIdentifier("TEMPLATE");
accept(Token.LPAREN);
for (; ; ) {
SQLSubPartition subPartition = parseSubPartition();
subPartition.setParent(byList);
byList.getSubPartitionTemplate().add(subPartition);
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
}
break;
}
accept(Token.RPAREN);
}
return byList;
}
throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
}
Aggregations