use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlCreateTableTest51 method test_0.
public void test_0() throws Exception {
String sql = //
"CREATE TABLE `test` (" + //
"`Id` int(11) NOT NULL," + //
"`text` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=gbk";
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());
// System.out.println("orderBy : " + visitor.getOrderByColumns());
Assert.assertEquals(1, visitor.getTables().size());
Assert.assertEquals(2, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("test")));
String output = SQLUtils.toMySqlString(stmt);
// System.out.println(output);
Assert.assertEquals(//
"CREATE TABLE `test` (" + //
"\n\t`Id` int(11) NOT NULL, " + //
"\n\t`text` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL" + //
"\n) ENGINE = InnoDB CHARSET = gbk", output);
}
use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlCreateTableTest52 method test_0.
public void test_0() throws Exception {
String sql = //
"CREATE TABLE `ins_ebay_auth` (" + //
"`auth_id` int(10) NOT NULL AUTO_INCREMENT COMMENT '主键id'," + //
"`usr_id` int(10) NOT NULL COMMENT '外键,用户表'," + //
"`status` char(1) COLLATE utf8_bin NOT NULL COMMENT '状态 0.有效?1.无效'," + //
"`ebay_token` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'eBay授权码'," + //
"`ebay_name` varchar(50) NOT NULL COMMENT 'eBay唯一名'," + //
"`create_time` datetime NOT NULL COMMENT '授权时间'," + "`invalid_time` datetime NOT NULL COMMENT '授权失效时间'," + //
"PRIMARY KEY (`auth_id`)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='INS_EBAY_AUTH';";
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());
// System.out.println("orderBy : " + visitor.getOrderByColumns());
Assert.assertEquals(1, visitor.getTables().size());
Assert.assertEquals(7, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("ins_ebay_auth")));
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals(//
"CREATE TABLE `ins_ebay_auth` (" + //
"\n\t`auth_id` int(10) NOT NULL AUTO_INCREMENT COMMENT '主键id', " + //
"\n\t`usr_id` int(10) NOT NULL COMMENT '外键,用户表', " + //
"\n\t`status` char(1) COLLATE utf8_bin NOT NULL COMMENT '状态 0.有效?1.无效', " + //
"\n\t`ebay_token` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'eBay授权码', " + //
"\n\t`ebay_name` varchar(50) NOT NULL COMMENT 'eBay唯一名', " + //
"\n\t`create_time` datetime NOT NULL COMMENT '授权时间', " + //
"\n\t`invalid_time` datetime NOT NULL COMMENT '授权失效时间', " + "\n\tPRIMARY KEY (`auth_id`)" + "\n) ENGINE = InnoDB CHARSET = utf8 COLLATE utf8_bin COMMENT = 'INS_EBAY_AUTH'", output);
}
use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlCreateTableTest53 method test_index_using_btree.
@Test
public void test_index_using_btree() throws Exception {
String sql = //
"CREATE TABLE `ins_ebay_auth` (" + //
"`auth_id` int(10) NOT NULL AUTO_INCREMENT COMMENT '主键id'," + //
"`usr_id` int(10) NOT NULL COMMENT '外键,用户表'," + //
"`status` char(1) COLLATE utf8_bin NOT NULL COMMENT '状态 0.有效?1.无效'," + //
"`ebay_token` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'eBay授权码'," + //
"`ebay_name` varchar(50) NOT NULL COMMENT 'eBay唯一名'," + //
"`create_time` datetime NOT NULL COMMENT '授权时间'," + "`invalid_time` datetime NOT NULL COMMENT '授权失效时间'," + //
"PRIMARY KEY USING BTREE (`auth_id`), INDEX `ind_usr_id` USING BTREE(`usr_id`)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='INS_EBAY_AUTH';";
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());
// System.out.println("orderBy : " + visitor.getOrderByColumns());
Assert.assertEquals(1, visitor.getTables().size());
Assert.assertEquals(7, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("ins_ebay_auth")));
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals(//
"CREATE TABLE `ins_ebay_auth` (" + //
"\n\t`auth_id` int(10) NOT NULL AUTO_INCREMENT COMMENT '主键id', " + //
"\n\t`usr_id` int(10) NOT NULL COMMENT '外键,用户表', " + //
"\n\t`status` char(1) COLLATE utf8_bin NOT NULL COMMENT '状态 0.有效?1.无效', " + //
"\n\t`ebay_token` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'eBay授权码', " + //
"\n\t`ebay_name` varchar(50) NOT NULL COMMENT 'eBay唯一名', " + //
"\n\t`create_time` datetime NOT NULL COMMENT '授权时间', " + //
"\n\t`invalid_time` datetime NOT NULL COMMENT '授权失效时间', " + "\n\tPRIMARY KEY USING BTREE (`auth_id`), " + "\n\tINDEX `ind_usr_id` USING BTREE(`usr_id`)" + "\n) ENGINE = InnoDB CHARSET = utf8 COLLATE utf8_bin COMMENT = 'INS_EBAY_AUTH'", output);
}
use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlCreateTableTest1 method test_0.
public void test_0() throws Exception {
String sql = //
"CREATE TABLE lookup" + //
" (id INT, INDEX USING BTREE (id))" + " ENGINE = MEMORY;";
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement statemen = statementList.get(0);
// print(statementList);
Assert.assertEquals(1, statementList.size());
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
statemen.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());
Assert.assertEquals(1, visitor.getTables().size());
Assert.assertEquals(1, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("lookup")));
Assert.assertTrue(visitor.getColumns().contains(new Column("lookup", "id")));
}
use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlCreateTableTest11 method test_0.
public void test_0() throws Exception {
String sql = //
"CREATE TABLE `tmall_campaign` (" + //
"`id` int(11) NOT NULL AUTO_INCREMENT," + //
"`campaign_name` varchar(200) NOT NULL COMMENT '活动名称'," + //
"`create_date` datetime DEFAULT NULL COMMENT '活动创建时间'," + //
"`delete_flag` int(11) DEFAULT '0' COMMENT '活动删除标识'," + //
"PRIMARY KEY (`id`)" + ") ENGINE=InnoDB DEFAULT CHARSET=gbk;";
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLCreateTableStatement stmt = (SQLCreateTableStatement) statementList.get(0);
// print(statementList);
Assert.assertEquals(1, statementList.size());
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());
Assert.assertEquals(1, visitor.getTables().size());
Assert.assertEquals(4, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("tmall_campaign")));
Assert.assertTrue(visitor.getColumns().contains(new Column("tmall_campaign", "id")));
Assert.assertTrue(visitor.getColumns().contains(new Column("tmall_campaign", "campaign_name")));
Assert.assertTrue(visitor.getColumns().contains(new Column("tmall_campaign", "create_date")));
Assert.assertTrue(visitor.getColumns().contains(new Column("tmall_campaign", "delete_flag")));
}
Aggregations