mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
mysql sql format support keepComments.
This commit is contained in:
@@ -73,6 +73,11 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
this.lexer.nextToken();
|
||||
}
|
||||
|
||||
public MySqlExprParser(String sql, boolean keepComments){
|
||||
this(new MySqlLexer(sql, keepComments, keepComments));
|
||||
this.lexer.nextToken();
|
||||
}
|
||||
|
||||
public SQLExpr relationalRest(SQLExpr expr) {
|
||||
if (identifierEquals("REGEXP")) {
|
||||
lexer.nextToken();
|
||||
|
||||
@@ -75,6 +75,13 @@ public class MySqlLexer extends Lexer {
|
||||
super.keywods = DEFAULT_MYSQL_KEYWORDS;
|
||||
}
|
||||
|
||||
public MySqlLexer(String input, boolean skipComment, boolean keepComments){
|
||||
super(input, skipComment);
|
||||
this.skipComment = skipComment;
|
||||
this.keepComments = keepComments;
|
||||
super.keywods = DEFAULT_MYSQL_KEYWORDS;
|
||||
}
|
||||
|
||||
public void scanSharp() {
|
||||
if (ch != '#') {
|
||||
throw new ParserException("illegal stat");
|
||||
|
||||
@@ -87,6 +87,10 @@ public class MySqlSelectParser extends SQLSelectParser {
|
||||
|
||||
MySqlSelectQueryBlock queryBlock = new MySqlSelectQueryBlock();
|
||||
|
||||
if (lexer.hasComment() && lexer.isKeepComments()) {
|
||||
queryBlock.addBeforeComment(lexer.readAndResetComments());
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.SELECT) {
|
||||
lexer.nextToken();
|
||||
|
||||
|
||||
@@ -231,6 +231,10 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
super(new MySqlExprParser(sql));
|
||||
}
|
||||
|
||||
public MySqlStatementParser(String sql, boolean keepComments) {
|
||||
super(new MySqlExprParser(sql, keepComments));
|
||||
}
|
||||
|
||||
public MySqlStatementParser(Lexer lexer) {
|
||||
super(new MySqlExprParser(lexer));
|
||||
}
|
||||
|
||||
@@ -206,8 +206,8 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
}
|
||||
|
||||
public boolean visit(MySqlSelectQueryBlock x) {
|
||||
if (x.getOrderBy() != null) {
|
||||
x.getOrderBy().setParent(x);
|
||||
if ((!isParameterized()) && isPrettyFormat() && x.hasBeforeComment()) {
|
||||
printComment(x.getBeforeCommentsDirect(), "\n");
|
||||
}
|
||||
|
||||
print0(ucase ? "SELECT " : "select ");
|
||||
|
||||
Reference in New Issue
Block a user