use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlAlterTableTest12 method test_alter_first.
public void test_alter_first() throws Exception {
String sql = "ALTER TABLE tbl_name DROP FOREIGN KEY fk_symbol;";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
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());
// System.out.println("orderBy : " + visitor.getOrderByColumns());
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals(//
"ALTER TABLE tbl_name" + "\n\tDROP FOREIGN KEY fk_symbol", output);
Assert.assertEquals(1, visitor.getTables().size());
Assert.assertEquals(0, visitor.getColumns().size());
}
use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlAlterTableTest14 method test_alter_first.
public void test_alter_first() throws Exception {
String sql = "ALTER TABLE tbl_name IMPORT TABLESPACE;";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
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());
// System.out.println("orderBy : " + visitor.getOrderByColumns());
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals(//
"ALTER TABLE tbl_name" + "\n\tIMPORT TABLESPACE", output);
Assert.assertEquals(1, visitor.getTables().size());
Assert.assertEquals(0, visitor.getColumns().size());
}
use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlCreateTableTest54 method test_FOREIGN_KEY.
@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) DEFAULT 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) NOT NULL DEFAULT '0' COMMENT '页面的显示状态', " + "\n\t`update_status` int(11) DEFAULT NULL COMMENT '节点创建后的修改状态', " + "\n\t`execute_status` int(11) DEFAULT NULL COMMENT '节点当前的执行状态', " + "\n\t`start_time` datetime DEFAULT NULL COMMENT '该节点活动的开始时间', " + "\n\t`end_time` datetime DEFAULT NULL COMMENT '该节点活动的结束时间', " + "\n\t`activity_start_time` datetime DEFAULT NULL COMMENT '营销活动的开始时间', " + "\n\t`activity_end_time` datetime DEFAULT NULL COMMENT '营销活动的结束时间', " + "\n\t`report_start_time` datetime DEFAULT NULL COMMENT '该节点活动效果报告的开始时间', " + "\n\t`report_end_time` datetime DEFAULT NULL COMMENT '该节点活动效果报告的结束时间', " + "\n\t`cron_rule` varchar(100) DEFAULT NULL COMMENT '周期性营销的时间表达式', " + "\n\t`split_rule` varchar(1000) DEFAULT NULL COMMENT '节点拆分规则', " + "\n\t`search_json` varchar(5000) DEFAULT NULL COMMENT '索引查找的条件字符串', " + "\n\t`filter_json` varchar(1000) DEFAULT NULL COMMENT '各种过滤条件的设置', " + "\n\t`buyer_count` int(11) DEFAULT 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 ON UPDATE CASCADE" + "\n) ENGINE = InnoDB CHARSET = utf8", output);
}
{
String output = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
Assert.assertEquals("create table `t_activity_node` (" + "\n\t`id` bigint(20) not null, " + "\n\t`sellerId` bigint(20) default 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) not null default '0' comment '页面的显示状态', " + "\n\t`update_status` int(11) default null comment '节点创建后的修改状态', " + "\n\t`execute_status` int(11) default null comment '节点当前的执行状态', " + "\n\t`start_time` datetime default null comment '该节点活动的开始时间', " + "\n\t`end_time` datetime default null comment '该节点活动的结束时间', " + "\n\t`activity_start_time` datetime default null comment '营销活动的开始时间', " + "\n\t`activity_end_time` datetime default null comment '营销活动的结束时间', " + "\n\t`report_start_time` datetime default null comment '该节点活动效果报告的开始时间', " + "\n\t`report_end_time` datetime default null comment '该节点活动效果报告的结束时间', " + "\n\t`cron_rule` varchar(100) default null comment '周期性营销的时间表达式', " + "\n\t`split_rule` varchar(1000) default null comment '节点拆分规则', " + "\n\t`search_json` varchar(5000) default null comment '索引查找的条件字符串', " + "\n\t`filter_json` varchar(1000) default null comment '各种过滤条件的设置', " + "\n\t`buyer_count` int(11) default 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 on update cascade" + "\n) engine = InnoDB charset = utf8", output);
}
}
use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlCreateTableTest55 method test_union.
@Test
public void test_union() throws Exception {
String sql = "CREATE TABLE tableA (datasn varchar(100) NOT NULL,PRIMARY KEY(datasn)) ENGINE=MRG_MyISAM DEFAULT CHARSET=utf8 UNION=(tableB)";
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(1, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals(//
"CREATE TABLE tableA (" + //
"\n\tdatasn varchar(100) NOT NULL, " + //
"\n\tPRIMARY KEY (datasn)" + "\n) ENGINE = MRG_MyISAM CHARSET = utf8 UNION = (tableB)", output);
}
use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlCreateTableTest56 method test_union.
@Test
public void test_union() throws Exception {
String sql = "CREATE TABLE tableA (datasn varchar(100) NOT NULL,PRIMARY KEY(datasn)) ENGINE=MRG_MyISAM DEFAULT CHARSET=utf8 UNION=(tableB,tableC)";
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(3, visitor.getTables().size());
Assert.assertEquals(1, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
{
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals(//
"CREATE TABLE tableA (" + //
"\n\tdatasn varchar(100) NOT NULL, " + //
"\n\tPRIMARY KEY (datasn)" + "\n) ENGINE = MRG_MyISAM CHARSET = utf8 UNION = (tableB, tableC)", output);
}
{
String output = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
Assert.assertEquals(//
"create table tableA (" + //
"\n\tdatasn varchar(100) not null, " + //
"\n\tprimary key (datasn)" + "\n) engine = MRG_MyISAM charset = utf8 union = (tableB, tableC)", output);
}
}
Aggregations