mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql parser.
This commit is contained in:
@@ -284,6 +284,11 @@ public class SQLSelectParser extends SQLParser {
|
||||
accept(Token.LPAREN);
|
||||
groupBy.setWithRollUp(true);
|
||||
}
|
||||
if (identifierEquals("CUBE")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.LPAREN);
|
||||
groupBy.setWithCube(true);
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
SQLExpr item = parseGroupByItem();
|
||||
@@ -297,7 +302,7 @@ public class SQLSelectParser extends SQLParser {
|
||||
|
||||
lexer.nextToken();
|
||||
}
|
||||
if (groupBy.isWithRollUp()) {
|
||||
if (groupBy.isWithRollUp() || groupBy.isWithCube()) {
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
|
||||
|
||||
@@ -1310,12 +1310,15 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
|
||||
boolean oracle = JdbcConstants.ORACLE.equals(dbType);
|
||||
boolean rollup = x.isWithRollUp();
|
||||
boolean cube = x.isWithCube();
|
||||
|
||||
int itemSize = x.getItems().size();
|
||||
if (itemSize > 0) {
|
||||
print0(ucase ? "GROUP BY " : "group by ");
|
||||
if (oracle && rollup) {
|
||||
print0(ucase ? "ROLLUP (" : "rollup (");
|
||||
} else if (oracle && cube) {
|
||||
print0(ucase ? "CUBE (" : "cube (");
|
||||
}
|
||||
incrementIndent();
|
||||
for (int i = 0; i < itemSize; ++i) {
|
||||
@@ -1344,7 +1347,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
print0(ucase ? " WITH ROLLUP" : " with rollup");
|
||||
}
|
||||
|
||||
if (x.isWithCube()) {
|
||||
if (x.isWithCube() && !oracle) {
|
||||
print0(ucase ? " WITH CUBE" : " with cube");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user