mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved mysql ddl support, fix #4039
This commit is contained in:
@@ -8005,6 +8005,16 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
|
||||
SQLCreateDatabaseStatement stmt = new SQLCreateDatabaseStatement(dbType);
|
||||
|
||||
if (lexer.token() == Token.HINT) {
|
||||
List<SQLCommentHint> hints = this.exprParser.parseHints();
|
||||
if (hints.size() == 1) {
|
||||
String text = hints.get(0).getText();
|
||||
if (text.endsWith(" IF NOT EXISTS") && text.charAt(0) == '!') {
|
||||
stmt.setIfNotExists(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.IF) {
|
||||
lexer.nextToken();
|
||||
accept(Token.NOT);
|
||||
|
||||
@@ -50,6 +50,10 @@ public class MySqlResourceTest extends TestCase {
|
||||
exec_test("bvt/parser/mysql-14.txt");
|
||||
}
|
||||
|
||||
public void test_16() throws Exception {
|
||||
exec_test("bvt/parser/mysql-16.txt");
|
||||
}
|
||||
|
||||
public void exec_test(String resource) throws Exception {
|
||||
// System.out.println(resource);
|
||||
InputStream is = null;
|
||||
@@ -64,12 +68,12 @@ public class MySqlResourceTest extends TestCase {
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement statemen = statementList.get(0);
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
statemen.accept(visitor);
|
||||
stmt.accept(visitor);
|
||||
|
||||
// System.out.println(sql);
|
||||
// System.out.println("Tables : " + visitor.getTables());
|
||||
@@ -77,6 +81,10 @@ public class MySqlResourceTest extends TestCase {
|
||||
//
|
||||
// System.out.println();
|
||||
// System.out.println();
|
||||
|
||||
if (expect != null && !expect.isEmpty()) {
|
||||
assertEquals(expect, stmt.toString());
|
||||
}
|
||||
}
|
||||
|
||||
void mergValidate(String sql, String expect) {
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `druidtestdb` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_bin */;
|
||||
---------------------------
|
||||
CREATE DATABASE IF NOT EXISTS `druidtestdb`;
|
||||
Reference in New Issue
Block a user