bug fixed for mysql create table parser, for issue #2999

This commit is contained in:
shaojin.wensj
2019-01-04 21:54:06 +08:00
parent 4903a9ad3a
commit 74e265aa27
3 changed files with 64 additions and 0 deletions
@@ -0,0 +1,47 @@
package com.alibaba.druid.bvt.sql.mysql.createTable;
import com.alibaba.druid.sql.MysqlTest;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement;
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
import java.util.List;
public class MySqlCreateTableTest134 extends MysqlTest {
public void test_0() throws Exception {
String sql = "create table xuhan3(\n" +
"id int not null AUTO_INCREMENT primary key, \n" +
"name char(40), SimpleDate date, \n" +
"SimpleDate_dayofweek tinyint(4) GENERATED ALWAYS AS (dayofweek(SimpleDate)) VIRTUAL, \n" +
"KEY SimpleDate_dayofweek (SimpleDate_dayofweek));";
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
MySqlCreateTableStatement stmt = (MySqlCreateTableStatement)statementList.get(0);
assertEquals(1, statementList.size());
assertEquals("CREATE TABLE xuhan3 (\n" +
"\tid int NOT NULL PRIMARY KEY AUTO_INCREMENT,\n" +
"\tname char(40),\n" +
"\tSimpleDate date,\n" +
"\tSimpleDate_dayofweek tinyint(4) GENERATED ALWAYS AS (dayofweek(SimpleDate)),\n" +
"\tKEY SimpleDate_dayofweek (SimpleDate_dayofweek)\n" +
");", stmt.toString());
assertEquals("create table xuhan3 (\n" +
"\tid int not null primary key auto_increment,\n" +
"\tname char(40),\n" +
"\tSimpleDate date,\n" +
"\tSimpleDate_dayofweek tinyint(4) generated always as (dayofweek(SimpleDate)),\n" +
"\tkey SimpleDate_dayofweek (SimpleDate_dayofweek)\n" +
");", stmt.toLowerCaseString());
}
}