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 SQLDeleteBuilderImpl method whereAnd.
@Override
public SQLDeleteBuilder whereAnd(String expr) {
SQLDeleteStatement delete = getSQLDeleteStatement();
SQLExpr exprObj = SQLUtils.toSQLExpr(expr, dbType);
SQLExpr newCondition = SQLUtils.buildCondition(SQLBinaryOperator.BooleanAnd, exprObj, false, delete.getWhere());
delete.setWhere(newCondition);
return this;
}
use of com.alibaba.druid.sql.ast.SQLExpr in project druid by alibaba.
the class SQLSelectBuilderImpl method groupBy.
@Override
public SQLSelectBuilderImpl groupBy(String expr) {
SQLSelectQueryBlock queryBlock = getQueryBlock();
SQLSelectGroupByClause groupBy = queryBlock.getGroupBy();
if (groupBy == null) {
groupBy = createGroupBy();
queryBlock.setGroupBy(groupBy);
}
SQLExpr exprObj = SQLUtils.toSQLExpr(expr, dbType);
groupBy.addItem(exprObj);
return this;
}
use of com.alibaba.druid.sql.ast.SQLExpr in project druid by alibaba.
the class SQLSelectBuilderImpl method having.
@Override
public SQLSelectBuilderImpl having(String expr) {
SQLSelectQueryBlock queryBlock = getQueryBlock();
SQLSelectGroupByClause groupBy = queryBlock.getGroupBy();
if (groupBy == null) {
groupBy = createGroupBy();
queryBlock.setGroupBy(groupBy);
}
SQLExpr exprObj = SQLUtils.toSQLExpr(expr, dbType);
groupBy.setHaving(exprObj);
return this;
}
Aggregations