use of com.alibaba.druid.stat.TableStat.Column in project druid by alibaba.
the class MySqlCreateTableTest16 method test_0.
public void test_0() throws Exception {
String sql = //
"CREATE TABLE `xxx` (" + //
" `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID'," + //
" `create_date` datetime DEFAULT NULL," + //
" `update_date` datetime DEFAULT NULL," + //
" `product_id` int(11) NOT NULL COMMENT '产品ID'," + //
" `memeber_id` int(11) NOT NULL COMMENT '用户ID'," + //
" `name` varchar(50) DEFAULT NULL COMMENT '姓名'," + //
" `address` varchar(500) DEFAULT NULL COMMENT '地址'," + //
" `mobile` varchar(50) DEFAULT NULL COMMENT '手机'," + //
" `amount` int(11) DEFAULT NULL COMMENT '兑换数量'," + //
" PRIMARY KEY (`id`)" + //
" ) ENGINE=InnoDB DEFAULT CHARSET=gbk;" + "";
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(9, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("xxx")));
Assert.assertTrue(visitor.getColumns().contains(new Column("xxx", "id")));
Assert.assertTrue(visitor.getColumns().contains(new Column("xxx", "amount")));
}
use of com.alibaba.druid.stat.TableStat.Column in project druid by alibaba.
the class MySqlCreateTableTest17 method test_0.
public void test_0() throws Exception {
String sql = //
"CREATE TABLE t1 (" + //
" ts TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6)" + ");";
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("t1")));
Assert.assertTrue(visitor.getColumns().contains(new Column("t1", "ts")));
}
use of com.alibaba.druid.stat.TableStat.Column in project druid by alibaba.
the class MySqlCreateProcedureTest method test_0.
public void test_0() throws Exception {
String sql = "create or replace procedure sp_name(level int,age int)" + " begin" + " declare x,y,z int;" + " select id into x,y,z from test;" + " insert into test values(id,age);" + " while x do" + " insert into test values(id,age);" + " end while;" + " if x then" + " insert into test values(id,age);" + " insert into test values(id,age);" + " else if y then" + " insert into test values(id,age);" + " while x do" + " insert into test values(id,age);" + " end while;" + " else" + " insert into test values(id,age);" + " end if;" + " case x" + " when x>10 then" + " insert into test values(id,age);" + " insert into test values(id,age);" + " when x>20 then" + " insert into test values(id,age);" + " insert into test values(id,age);" + " else" + " insert into test values(id,age);" + " end case;" + " end";
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(2, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("test")));
Assert.assertTrue(visitor.getColumns().contains(new Column("test", "id")));
Assert.assertTrue(visitor.getColumns().contains(new Column("test", "age")));
}
use of com.alibaba.druid.stat.TableStat.Column in project druid by alibaba.
the class MySqlCreateProcedureTest1 method test_0.
public void test_0() throws Exception {
String sql = "create or replace procedure sp_name(level int,age int)" + " begin" + " declare x,y,z int;" + " begin" + " insert into test values(id,age);" + " end" + " end";
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(2, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("test")));
Assert.assertTrue(visitor.getColumns().contains(new Column("test", "id")));
Assert.assertTrue(visitor.getColumns().contains(new Column("test", "age")));
}
use of com.alibaba.druid.stat.TableStat.Column in project druid by alibaba.
the class MySqlCreateProcedureTest2 method test_0.
public void test_0() throws Exception {
String sql = "create or replace procedure sp_name(level int,age int)" + " begin" + " declare x,y,z int;" + " lable_1: while x do" + " insert into test values(id,age);" + " end while lable_1;" + " end";
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(2, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("test")));
Assert.assertTrue(visitor.getColumns().contains(new Column("test", "id")));
Assert.assertTrue(visitor.getColumns().contains(new Column("test", "age")));
}
Aggregations