mysql sql format support keepComments.

This commit is contained in:
wenshao
2017-05-14 10:14:34 +08:00
parent 2c26d3623f
commit 5706f65fcf
9 changed files with 187 additions and 5 deletions
@@ -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 ");