mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bugfix of mysql parser for #comment
This commit is contained in:
@@ -16,13 +16,13 @@
|
||||
package com.alibaba.druid.sql.dialect.mysql.parser;
|
||||
|
||||
import static com.alibaba.druid.sql.parser.CharTypes.isFirstIdentifierChar;
|
||||
import static com.alibaba.druid.sql.parser.CharTypes.isIdentifierChar;
|
||||
import static com.alibaba.druid.sql.parser.LayoutCharacters.EOI;
|
||||
import static com.alibaba.druid.sql.parser.Token.LITERAL_CHARS;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.druid.sql.parser.CharTypes;
|
||||
import com.alibaba.druid.sql.parser.Keywords;
|
||||
import com.alibaba.druid.sql.parser.Lexer;
|
||||
import com.alibaba.druid.sql.parser.NotAllowCommentException;
|
||||
@@ -523,4 +523,8 @@ public class MySqlLexer extends Lexer {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isIdentifierChar(char c) {
|
||||
return c != '#' && CharTypes.isIdentifierChar(c);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,4 +29,14 @@ public class SQLUtilsTest extends TestCase {
|
||||
String sql = "begin\n" + " if (a=10) then\n" + " null;\n" + " else\n" + " null;\n" + " end if;\n" + "end;";
|
||||
System.out.println(SQLUtils.formatOracle(sql));
|
||||
}
|
||||
|
||||
public void test_format_3() throws Exception {
|
||||
String sql = "select lottery_notice_issue,lottery_notice_date,lottery_notice_result from tb_lottery_notice where lottery_type_id=8 and lottery_notice_issue<=2014066 UNION ALL SELECT NULL, NULL, NULL, NULL, NULL, NULL# and lottery_notice_issue>=2014062 order by lottery_notice_issue desc";
|
||||
String formattedSql = SQLUtils.formatMySql(sql);
|
||||
String expected = "SELECT lottery_notice_issue, lottery_notice_date, lottery_notice_result"
|
||||
+ "\nFROM tb_lottery_notice" + "\nWHERE lottery_type_id = 8"
|
||||
+ "\n\tAND lottery_notice_issue <= 2014066" + "\nUNION ALL"
|
||||
+ "\nSELECT NULL, NULL, NULL, NULL, NULL" + "\n\t, NULL";
|
||||
Assert.assertEquals(expected, formattedSql);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user