bug fixed for exprList

This commit is contained in:
wenshao
2014-06-01 11:36:26 +08:00
parent fc5ecf5de4
commit 4df624ae4b
15 changed files with 78 additions and 65 deletions
@@ -74,4 +74,5 @@ public class SQLOrderBy extends SQLObjectImpl {
return true;
}
}
@@ -21,6 +21,7 @@ import java.util.List;
import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.SQLExprImpl;
import com.alibaba.druid.sql.ast.SQLOrderBy;
import com.alibaba.druid.sql.ast.SQLOver;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
@@ -31,9 +32,9 @@ public class SQLAggregateExpr extends SQLExprImpl implements Serializable {
protected Option option;
protected final List<SQLExpr> arguments = new ArrayList<SQLExpr>();
protected SQLOver over;
protected SQLOrderBy withinGroup;
public SQLAggregateExpr(String methodName){
this.methodName = methodName;
}
@@ -50,6 +51,18 @@ public class SQLAggregateExpr extends SQLExprImpl implements Serializable {
this.methodName = methodName;
}
public SQLOrderBy getWithinGroup() {
return withinGroup;
}
public void setWithinGroup(SQLOrderBy withinGroup) {
if (withinGroup != null) {
withinGroup.setParent(this);
}
this.withinGroup = withinGroup;
}
public Option getOption() {
return this.option;
}
@@ -25,6 +25,7 @@ public class SQLSelectOrderByItem extends SQLObjectImpl {
protected SQLExpr expr;
protected String collate;
protected SQLOrderingSpecification type;
protected NullsOrderType nullsOrderType;
public SQLSelectOrderByItem(){
@@ -60,6 +61,14 @@ public class SQLSelectOrderByItem extends SQLObjectImpl {
public void setType(SQLOrderingSpecification type) {
this.type = type;
}
public NullsOrderType getNullsOrderType() {
return this.nullsOrderType;
}
public void setNullsOrderType(NullsOrderType nullsOrderType) {
this.nullsOrderType = nullsOrderType;
}
protected void accept0(SQLASTVisitor visitor) {
if (visitor.visit(this)) {
@@ -95,4 +104,19 @@ public class SQLSelectOrderByItem extends SQLObjectImpl {
return true;
}
public static enum NullsOrderType {
NullsFirst, NullsLast;
public String toFormalString() {
if (NullsFirst.equals(this)) {
return "NULLS FIRST";
}
if (NullsLast.equals(this)) {
return "NULLS LAST";
}
throw new IllegalArgumentException();
}
}
}
@@ -493,7 +493,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
MySqlPartitioningDef.InValues values = new MySqlPartitioningDef.InValues();
accept(Token.LPAREN);
this.exprParser.exprList(values.getItems());
this.exprParser.exprList(values.getItems(), values);
accept(Token.RPAREN);
partitionDef.setValues(values);
} else {
@@ -503,7 +503,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
MySqlPartitioningDef.LessThanValues values = new MySqlPartitioningDef.LessThanValues();
accept(Token.LPAREN);
this.exprParser.exprList(values.getItems());
this.exprParser.exprList(values.getItems(), values);
accept(Token.RPAREN);
partitionDef.setValues(values);
}
@@ -394,7 +394,7 @@ public class MySqlExprParser extends SQLExprParser {
if (lexer.token() == Token.RPAREN) {
lexer.nextToken();
} else {
exprList(matchAgainstExpr.getColumns());
exprList(matchAgainstExpr.getColumns(), matchAgainstExpr);
accept(Token.RPAREN);
}
@@ -1582,7 +1582,7 @@ public class MySqlStatementParser extends SQLStatementParser {
SQLQueryExpr queryExpr = (SQLQueryExpr) this.exprParser.expr();
stmt.setQuery(queryExpr);
} else {
this.exprParser.exprList(stmt.getColumns());
this.exprParser.exprList(stmt.getColumns(), stmt);
}
accept(Token.RPAREN);
}
@@ -1807,7 +1807,7 @@ public class MySqlStatementParser extends SQLStatementParser {
if (identifierEquals("USING")) {
lexer.nextToken();
exprParser.exprList(stmt.getParameters());
exprParser.exprList(stmt.getParameters(), stmt);
}
return stmt;
@@ -1861,7 +1861,7 @@ public class MySqlStatementParser extends SQLStatementParser {
select.setParent(insertStatement);
insertStatement.setQuery(select);
} else {
this.exprParser.exprList(insertStatement.getColumns());
this.exprParser.exprList(insertStatement.getColumns(), insertStatement);
columnSize = insertStatement.getColumns().size();
}
accept(Token.RPAREN);
@@ -1912,7 +1912,7 @@ public class MySqlStatementParser extends SQLStatementParser {
accept(Token.KEY);
accept(Token.UPDATE);
exprParser.exprList(insertStatement.getDuplicateKeyUpdate());
exprParser.exprList(insertStatement.getDuplicateKeyUpdate(), insertStatement);
}
return insertStatement;
@@ -2520,7 +2520,7 @@ public class MySqlStatementParser extends SQLStatementParser {
if (lexer.token() == (Token.LPAREN)) {
lexer.nextToken();
SQLListExpr list = new SQLListExpr();
this.exprParser.exprList(list.getItems());
this.exprParser.exprList(list.getItems(), list);
accept(Token.RPAREN);
item.setColumn(list);
} else {
@@ -22,20 +22,10 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class OracleOrderByItem extends SQLSelectOrderByItem {
private NullsOrderType nullsOrderType;
public OracleOrderByItem(){
}
public NullsOrderType getNullsOrderType() {
return this.nullsOrderType;
}
public void setNullsOrderType(NullsOrderType nullsOrderType) {
this.nullsOrderType = nullsOrderType;
}
protected void accept0(SQLASTVisitor visitor) {
if (visitor instanceof OracleASTVisitor) {
accept0((OracleASTVisitor) visitor);
@@ -66,20 +56,4 @@ public class OracleOrderByItem extends SQLSelectOrderByItem {
}
}
public static enum NullsOrderType {
NullsFirst, NullsLast;
public String toFormalString() {
if (NullsFirst.equals(this)) {
return "NULLS FIRST";
}
if (NullsLast.equals(this)) {
return "NULLS LAST";
}
throw new IllegalArgumentException();
}
}
}
@@ -760,7 +760,7 @@ public class OracleExprParser extends SQLExprParser {
} else {
aggregateExpr = new OracleAggregateExpr(methodName);
}
exprList(aggregateExpr.getArguments());
exprList(aggregateExpr.getArguments(), aggregateExpr);
if (lexer.stringVal().equalsIgnoreCase("IGNORE")) {
lexer.nextToken();
@@ -782,10 +782,10 @@ public class OracleExprParser extends SQLExprParser {
if (lexer.token() == (Token.LPAREN)) {
lexer.nextToken();
exprList(over.getPartitionBy());
exprList(over.getPartitionBy(), over);
accept(Token.RPAREN);
} else {
exprList(over.getPartitionBy());
exprList(over.getPartitionBy(), over);
}
}
@@ -1024,7 +1024,7 @@ public class OracleExprParser extends SQLExprParser {
OraclePrimaryKey primaryKey = new OraclePrimaryKey();
accept(Token.LPAREN);
exprList(primaryKey.getColumns());
exprList(primaryKey.getColumns(), primaryKey);
accept(Token.RPAREN);
@@ -96,7 +96,7 @@ public class OracleSelectParser extends SQLSelectParser {
if (lexer.token() == Token.OF) {
lexer.nextToken();
this.exprParser.exprList(forUpdate.getOf());
this.exprParser.exprList(forUpdate.getOf(), forUpdate);
}
if (lexer.token() == Token.NOWAIT) {
@@ -207,7 +207,7 @@ public class OracleSelectParser extends SQLSelectParser {
if (identifierEquals("CYCLE")) {
lexer.nextToken();
CycleClause cycleClause = new CycleClause();
exprParser.exprList(cycleClause.getAliases());
exprParser.exprList(cycleClause.getAliases(), cycleClause);
accept(Token.SET);
cycleClause.setMark(exprParser.expr());
accept(Token.TO);
@@ -510,7 +510,7 @@ public class OracleSelectParser extends SQLSelectParser {
cellAssignment.setMeasureColumn(expr());
accept(Token.LBRACKET);
this.exprParser.exprList(cellAssignment.getConditions());
this.exprParser.exprList(cellAssignment.getConditions(), cellAssignment);
accept(Token.RBRACKET);
return cellAssignment;
@@ -524,10 +524,10 @@ public class OracleSelectParser extends SQLSelectParser {
accept(Token.BY);
if (lexer.token() == Token.LPAREN) {
lexer.nextToken();
exprParser.exprList(queryPartitionClause.getExprList());
exprParser.exprList(queryPartitionClause.getExprList(), queryPartitionClause);
accept(Token.RPAREN);
} else {
exprParser.exprList(queryPartitionClause.getExprList());
exprParser.exprList(queryPartitionClause.getExprList(), queryPartitionClause);
}
modelColumnClause.setQueryPartitionClause(queryPartitionClause);
}
@@ -573,7 +573,7 @@ public class OracleSelectParser extends SQLSelectParser {
lexer.nextToken();
acceptIdentifier("SETS");
accept(Token.LPAREN);
exprParser.exprList(groupingSet.getParameters());
exprParser.exprList(groupingSet.getParameters(), groupingSet);
accept(Token.RPAREN);
groupBy.addItem(groupingSet);
} else {
@@ -610,7 +610,7 @@ public class OracleSelectParser extends SQLSelectParser {
lexer.nextToken();
acceptIdentifier("SETS");
accept(Token.LPAREN);
exprParser.exprList(groupingSet.getParameters());
exprParser.exprList(groupingSet.getParameters(), groupingSet);
accept(Token.RPAREN);
groupBy.addItem(groupingSet);
} else {
@@ -760,7 +760,7 @@ public class OracleSelectParser extends SQLSelectParser {
}
accept(Token.LPAREN);
this.exprParser.exprList(sample.getPercent());
this.exprParser.exprList(sample.getPercent(), sample);
accept(Token.RPAREN);
if (identifierEquals("SEED")) {
@@ -959,7 +959,7 @@ public class OracleSelectParser extends SQLSelectParser {
} else if (lexer.token() == Token.USING) {
lexer.nextToken();
accept(Token.LPAREN);
this.exprParser.exprList(join.getUsing());
this.exprParser.exprList(join.getUsing(), join);
accept(Token.RPAREN);
}
@@ -1060,7 +1060,7 @@ public class OracleSelectParser extends SQLSelectParser {
if (lexer.token() == (Token.LPAREN)) {
lexer.nextToken();
this.exprParser.exprList(unPivot.getItems());
this.exprParser.exprList(unPivot.getItems(), unPivot);
accept(Token.RPAREN);
} else {
unPivot.getItems().add(this.exprParser.expr());
@@ -965,7 +965,7 @@ public class OracleStatementParser extends SQLStatementParser {
if (identifierEquals("AT")) {
lexer.nextToken();
accept(Token.LPAREN);
this.exprParser.exprList(item.getAt());
this.exprParser.exprList(item.getAt(), item);
accept(Token.RPAREN);
} else {
throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
@@ -1206,12 +1206,12 @@ public class OracleStatementParser extends SQLStatementParser {
if (lexer.token() == Token.LPAREN) {
accept(Token.LPAREN);
exprParser.exprList(insertClause.getColumns());
exprParser.exprList(insertClause.getColumns(), insertClause);
accept(Token.RPAREN);
}
accept(Token.VALUES);
accept(Token.LPAREN);
exprParser.exprList(insertClause.getValues());
exprParser.exprList(insertClause.getValues(), insertClause);
accept(Token.RPAREN);
if (lexer.token() == Token.WHERE) {
@@ -100,7 +100,7 @@ public class PGSQLStatementParser extends SQLStatementParser {
if (lexer.token() == (Token.LPAREN)) {
lexer.nextToken();
this.exprParser.exprList(stmt.getColumns());
this.exprParser.exprList(stmt.getColumns(), stmt);
accept(Token.RPAREN);
}
@@ -110,7 +110,7 @@ public class PGSQLStatementParser extends SQLStatementParser {
for (;;) {
accept(Token.LPAREN);
SQLInsertStatement.ValuesClause valuesCaluse = new SQLInsertStatement.ValuesClause();
this.exprParser.exprList(valuesCaluse.getValues());
this.exprParser.exprList(valuesCaluse.getValues(), valuesCaluse);
stmt.addValueCause(valuesCaluse);
accept(Token.RPAREN);
@@ -109,7 +109,7 @@ public class SQLServerStatementParser extends SQLStatementParser {
if (lexer.token() == (Token.LPAREN)) {
lexer.nextToken();
this.exprParser.exprList(insertStatement.getColumns());
this.exprParser.exprList(insertStatement.getColumns(), insertStatement);
accept(Token.RPAREN);
}
@@ -714,6 +714,7 @@ public class SQLExprParser extends SQLParser {
}
}
@Deprecated
public final void exprList(Collection<SQLExpr> exprCol) {
exprList(exprCol, null);
}
@@ -878,10 +879,10 @@ public class SQLExprParser extends SQLParser {
if (lexer.token() == (Token.LPAREN)) {
lexer.nextToken();
exprList(over.getPartitionBy());
exprList(over.getPartitionBy(), over);
accept(Token.RPAREN);
} else {
exprList(over.getPartitionBy());
exprList(over.getPartitionBy(), over);
}
}
@@ -1539,7 +1540,7 @@ public class SQLExprParser extends SQLParser {
SQLPrimaryKeyImpl pk = new SQLPrimaryKeyImpl();
accept(Token.LPAREN);
exprList(pk.getColumns());
exprList(pk.getColumns(), pk);
accept(Token.RPAREN);
return pk;
@@ -1550,7 +1551,7 @@ public class SQLExprParser extends SQLParser {
SQLUnique unique = new SQLUnique();
accept(Token.LPAREN);
exprList(unique.getColumns());
exprList(unique.getColumns(), unique);
accept(Token.RPAREN);
return unique;
@@ -418,7 +418,7 @@ public class SQLSelectParser extends SQLParser {
lexer.nextToken();
if (lexer.token() == Token.LPAREN) {
lexer.nextToken();
this.exprParser.exprList(join.getUsing());
this.exprParser.exprList(join.getUsing(), join);
accept(Token.RPAREN);
} else {
join.getUsing().add(this.expr());
@@ -1060,7 +1060,7 @@ public class SQLStatementParser extends SQLParser {
if (lexer.token() == (Token.LPAREN)) {
lexer.nextToken();
this.exprParser.exprList(insertStatement.getColumns());
this.exprParser.exprList(insertStatement.getColumns(), insertStatement);
accept(Token.RPAREN);
}
@@ -1068,7 +1068,7 @@ public class SQLStatementParser extends SQLParser {
lexer.nextToken();
accept(Token.LPAREN);
SQLInsertStatement.ValuesClause values = new SQLInsertStatement.ValuesClause();
this.exprParser.exprList(values.getValues());
this.exprParser.exprList(values.getValues(), values);
insertStatement.setValues(values);
accept(Token.RPAREN);
} else if (acceptSubQuery && (lexer.token() == Token.SELECT || lexer.token() == Token.LPAREN)) {
@@ -1133,7 +1133,7 @@ public class SQLStatementParser extends SQLParser {
if (lexer.token() == Token.LPAREN) {
lexer.nextToken();
exprParser.exprList(stmt.getParameters());
exprParser.exprList(stmt.getParameters(), stmt);
accept(Token.RPAREN);
}
@@ -1390,7 +1390,7 @@ public class SQLStatementParser extends SQLParser {
if (lexer.token() == (Token.LPAREN)) {
lexer.nextToken();
SQLListExpr list = new SQLListExpr();
this.exprParser.exprList(list.getItems());
this.exprParser.exprList(list.getItems(), list);
accept(Token.RPAREN);
item.setColumn(list);
} else {
@@ -1464,7 +1464,7 @@ public class SQLStatementParser extends SQLParser {
if (lexer.token() == Token.LPAREN) {
lexer.nextToken();
this.exprParser.exprList(createView.getColumns());
this.exprParser.exprList(createView.getColumns(), createView);
accept(Token.RPAREN);
}