improved sql parser. fixed issue #1311

This commit is contained in:
高铁
2016-06-29 02:01:22 +08:00
parent 1c1e28e103
commit eb5c8d708e
5 changed files with 100 additions and 10 deletions
@@ -20,6 +20,7 @@ import java.util.List;
import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.SQLObjectImpl;
import com.alibaba.druid.sql.ast.SQLOrderBy;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery {
@@ -31,6 +32,7 @@ public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery
protected SQLExprTableSource into;
protected SQLExpr where;
protected SQLSelectGroupByClause groupBy;
protected SQLOrderBy orderBy;
protected boolean parenthesized = false;
public SQLSelectQueryBlock(){
@@ -70,6 +72,18 @@ public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery
}
this.where = where;
}
public SQLOrderBy getOrderBy() {
return orderBy;
}
public void setOrderBy(SQLOrderBy orderBy) {
if (orderBy != null) {
orderBy.setParent(this);
}
this.orderBy = orderBy;
}
public int getDistionOption() {
return this.distionOption;
@@ -16,6 +16,7 @@
package com.alibaba.druid.sql.dialect.db2.parser;
import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.SQLOrderBy;
import com.alibaba.druid.sql.ast.SQLSetQuantifier;
import com.alibaba.druid.sql.ast.statement.SQLSelectQuery;
import com.alibaba.druid.sql.dialect.db2.ast.stmt.DB2SelectQueryBlock;
@@ -76,6 +77,11 @@ public class DB2SelectParser extends SQLSelectParser {
parseWhere(queryBlock);
parseGroupBy(queryBlock);
if (lexer.token() == Token.ORDER) {
SQLOrderBy orderBy = parseOrderBy();
queryBlock.setOrderBy(orderBy);
}
for (;;) {
@@ -39,8 +39,6 @@ public class MySqlSelectQueryBlock extends SQLSelectQueryBlock implements MySqlO
private Boolean cache;
private boolean calcFoundRows;
private SQLOrderBy orderBy;
private Limit limit;
private SQLName procedureName;
@@ -183,14 +181,6 @@ public class MySqlSelectQueryBlock extends SQLSelectQueryBlock implements MySqlO
this.calcFoundRows = calcFoundRows;
}
public SQLOrderBy getOrderBy() {
return orderBy;
}
public void setOrderBy(SQLOrderBy orderBy) {
this.orderBy = orderBy;
}
public Limit getLimit() {
return limit;
}
@@ -765,6 +765,11 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
println();
x.getGroupBy().accept(this);
}
if (x.getOrderBy() != null) {
println();
x.getOrderBy().accept(this);
}
return false;
}