mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
support mysql group_concat
This commit is contained in:
@@ -18,6 +18,8 @@ package com.alibaba.druid.sql.dialect.mysql.parser;
|
||||
import com.alibaba.druid.sql.ast.SQLDataType;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLOrderBy;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAggregateExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOperator;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
|
||||
@@ -55,8 +57,11 @@ import com.alibaba.druid.sql.parser.Token;
|
||||
|
||||
public class MySqlExprParser extends SQLExprParser {
|
||||
|
||||
public static String[] AGGREGATE_FUNCTIONS = { "AVG", "COUNT", "GROUP_CONCAT", "MAX", "MIN", "STDDEV", "SUM" };
|
||||
|
||||
public MySqlExprParser(Lexer lexer){
|
||||
super(lexer);
|
||||
this.aggregateFunctions = AGGREGATE_FUNCTIONS;
|
||||
}
|
||||
|
||||
public MySqlExprParser(String sql){
|
||||
@@ -769,4 +774,19 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
accept(Token.RPAREN);
|
||||
return fk;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,9 @@ import com.alibaba.druid.sql.ast.SQLCommentHint;
|
||||
import com.alibaba.druid.sql.ast.SQLDataType;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.SQLOrderBy;
|
||||
import com.alibaba.druid.sql.ast.SQLSetQuantifier;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAggregateExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNullExpr;
|
||||
@@ -594,8 +596,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
&& (!varName.equals("?")) //
|
||||
&& (!varName.startsWith("#")) //
|
||||
&& (!varName.startsWith("$")) //
|
||||
&& (!varName.startsWith(":"))
|
||||
) {
|
||||
&& (!varName.startsWith(":"))) {
|
||||
print("@@");
|
||||
}
|
||||
}
|
||||
@@ -3061,4 +3062,21 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
|
||||
}
|
||||
|
||||
protected void visitAggreateRest(SQLAggregateExpr aggregateExpr) {
|
||||
{
|
||||
SQLOrderBy value = (SQLOrderBy) aggregateExpr.getAttribute("ORDER BY");
|
||||
if (value != null) {
|
||||
print(" ");
|
||||
((SQLObject) value).accept(this);
|
||||
}
|
||||
}
|
||||
{
|
||||
Object value = aggregateExpr.getAttribute("SEPARATOR");
|
||||
if (value != null) {
|
||||
print(" SEPARATOR ");
|
||||
((SQLObject) value).accept(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} //
|
||||
|
||||
Reference in New Issue
Block a user