mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bugfix for 'FOREIGN KEY reference'
This commit is contained in:
@@ -28,7 +28,7 @@ public class MySqlCreateTableTest54 extends MysqlTest {
|
||||
|
||||
@Test
|
||||
public void test_UNSIGNED_ZEROFILL() throws Exception {
|
||||
String sql = "CREATE TABLE t1 (year YEAR(4), month INT(2) UNSIGNED ZEROFILL, day INT(2) UNSIGNED ZEROFILL);';";
|
||||
String sql = "CREATE TABLE t1 (year YEAR(4), month INT(2) UNSIGNED ZEROFILL, day INT(2) UNSIGNED ZEROFILL);";
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
SQLStatement stmt = parser.parseCreateTable();
|
||||
@@ -50,4 +50,83 @@ public class MySqlCreateTableTest54 extends MysqlTest {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_FOREIGN_KEY() throws Exception {
|
||||
String sql = "CREATE TABLE `t_activity_node` ("
|
||||
+ "\n`id` bigint(20) NOT NULL,"
|
||||
+ "\n`sellerId` bigint(20) DEFAULT NULL,"
|
||||
+ "\n`canvas_id` bigint(20) NOT NULL COMMENT '画布ID',"
|
||||
+ "\n`view_node_id` bigint(20) NOT NULL COMMENT '对应显示的节点id',"
|
||||
+ "\n`activity_type` int(11) NOT NULL COMMENT '活动类型',"
|
||||
+ "\n`node_type` int(11) NOT NULL COMMENT '节点类型',"
|
||||
+ "\n`node_title` varchar(200) NOT NULL COMMENT '节点标题',"
|
||||
+ "\n`status` int(11) NOT NULL DEFAULT '0' COMMENT '页面的显示状态',"
|
||||
+ "\n`update_status` int(11) DEFAULT NULL COMMENT '节点创建后的修改状态',"
|
||||
+ "\n`execute_status` int(11) DEFAULT NULL COMMENT '节点当前的执行状态',"
|
||||
+ "\n`start_time` datetime DEFAULT NULL COMMENT '该节点活动的开始时间',"
|
||||
+ "\n`end_time` datetime DEFAULT NULL COMMENT '该节点活动的结束时间',"
|
||||
+ "\n`activity_start_time` datetime DEFAULT NULL COMMENT '营销活动的开始时间',"
|
||||
+ "\n`activity_end_time` datetime DEFAULT NULL COMMENT '营销活动的结束时间',"
|
||||
+ "\n`report_start_time` datetime DEFAULT NULL COMMENT '该节点活动效果报告的开始时间',"
|
||||
+ "\n`report_end_time` datetime DEFAULT NULL COMMENT '该节点活动效果报告的结束时间',"
|
||||
+ "\n`cron_rule` varchar(100) DEFAULT NULL COMMENT '周期性营销的时间表达式',"
|
||||
+ "\n`split_rule` varchar(1000) DEFAULT NULL COMMENT '节点拆分规则',"
|
||||
+ "\n`search_json` varchar(5000) DEFAULT NULL COMMENT '索引查找的条件字符串',"
|
||||
+ "\n`filter_json` varchar(1000) DEFAULT NULL COMMENT '各种过滤条件的设置',"
|
||||
+ "\n`buyer_count` int(11) DEFAULT NULL COMMENT '营销的会员数量',"
|
||||
+ "\n`gmt_modified` datetime NOT NULL COMMENT '活动最后修改时间',"
|
||||
+ "\n`gmt_create` datetime NOT NULL COMMENT '活动创建时间',"
|
||||
+ "\nPRIMARY KEY (`id`),"
|
||||
+ "\nKEY `canvas_id` (`canvas_id`),"
|
||||
+ "\nKEY `sid_ty_time` (`sellerId`,`node_type`,`start_time`),"
|
||||
+ "\nCONSTRAINT `t_activity_node_ibfk_1` FOREIGN KEY (`canvas_id`) REFERENCES `t_activity_canvas` (`id`) ON DELETE CASCADE"
|
||||
+ "\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
SQLStatement stmt = parser.parseCreateTable();
|
||||
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
System.out.println("coditions : " + visitor.getConditions());
|
||||
|
||||
Assert.assertEquals(2, visitor.getTables().size());
|
||||
Assert.assertEquals(24, visitor.getColumns().size());
|
||||
Assert.assertEquals(0, visitor.getConditions().size());
|
||||
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("CREATE TABLE `t_activity_node` ("
|
||||
+ "\n\t`id` bigint(20) NOT NULL, "
|
||||
+ "\n\t`sellerId` bigint(20) NULL, "
|
||||
+ "\n\t`canvas_id` bigint(20) NOT NULL COMMENT '画布ID', "
|
||||
+ "\n\t`view_node_id` bigint(20) NOT NULL COMMENT '对应显示的节点id', "
|
||||
+ "\n\t`activity_type` int(11) NOT NULL COMMENT '活动类型', "
|
||||
+ "\n\t`node_type` int(11) NOT NULL COMMENT '节点类型', "
|
||||
+ "\n\t`node_title` varchar(200) NOT NULL COMMENT '节点标题', "
|
||||
+ "\n\t`status` int(11) DEFAULT '0' NOT NULL COMMENT '页面的显示状态', "
|
||||
+ "\n\t`update_status` int(11) NULL COMMENT '节点创建后的修改状态', "
|
||||
+ "\n\t`execute_status` int(11) NULL COMMENT '节点当前的执行状态', "
|
||||
+ "\n\t`start_time` datetime NULL COMMENT '该节点活动的开始时间', "
|
||||
+ "\n\t`end_time` datetime NULL COMMENT '该节点活动的结束时间', "
|
||||
+ "\n\t`activity_start_time` datetime NULL COMMENT '营销活动的开始时间', "
|
||||
+ "\n\t`activity_end_time` datetime NULL COMMENT '营销活动的结束时间', "
|
||||
+ "\n\t`report_start_time` datetime NULL COMMENT '该节点活动效果报告的开始时间', "
|
||||
+ "\n\t`report_end_time` datetime NULL COMMENT '该节点活动效果报告的结束时间', "
|
||||
+ "\n\t`cron_rule` varchar(100) NULL COMMENT '周期性营销的时间表达式', "
|
||||
+ "\n\t`split_rule` varchar(1000) NULL COMMENT '节点拆分规则', "
|
||||
+ "\n\t`search_json` varchar(5000) NULL COMMENT '索引查找的条件字符串', "
|
||||
+ "\n\t`filter_json` varchar(1000) NULL COMMENT '各种过滤条件的设置', "
|
||||
+ "\n\t`buyer_count` int(11) NULL COMMENT '营销的会员数量', "
|
||||
+ "\n\t`gmt_modified` datetime NOT NULL COMMENT '活动最后修改时间', "
|
||||
+ "\n\t`gmt_create` datetime NOT NULL COMMENT '活动创建时间', "
|
||||
+ "\n\tPRIMARY KEY (`id`), "
|
||||
+ "\n\tKEY `canvas_id` (`canvas_id`), "
|
||||
+ "\n\tKEY `sid_ty_time` (`sellerId`, `node_type`, `start_time`), "
|
||||
+ "\n\tCONSTRAINT `t_activity_node_ibfk_1` FOREIGN KEY (`canvas_id`) REFERENCES `t_activity_canvas` (`id`) ON DELETE CASCADE"
|
||||
+ "\n) ENGINE = InnoDB CHARSET = utf8", output);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user