use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlCreateProcedureTest4 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;" + " repeat" + " insert into test values(id,age);" + " until x>10" + " end repeat;" + " 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.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlCreateProcedureTest4 method test_1.
public void test_1() throws Exception {
String sql = "create or replace procedure sp_name(level int,age int)" + " begin" + " declare x,y,z int;" + " lable_1: repeat" + " insert into test values(id,age);" + " until x>10" + " end repeat 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")));
}
use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlCreateProcedureTest6 method test_1.
public void test_1() throws Exception {
String sql = "create or replace procedure sp_name(in level int,in age int)" + " begin" + " insert into test values(id,age);" + " 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.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlCreateTableTest28 method test_0.
public void test_0() throws Exception {
String sql = //
"CREATE TABLE lookup" + //
" (id INT, INDEX USING BTREE (id))" + //
" MIN_ROWS = 1024;";
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = 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(1, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("lookup")));
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals(//
"CREATE TABLE lookup (" + //
"\n\tid INT, " + //
"\n\tINDEX USING BTREE(id)" + "\n) MIN_ROWS = 1024", output);
}
use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlCreateTableTest29 method test_0.
public void test_0() throws Exception {
String sql = //
"CREATE TABLE user" + //
" (id INT, INDEX USING BTREE (id))" + //
" MIN_ROWS 1024;";
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = 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(1, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("user")));
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals(//
"CREATE TABLE user (" + //
"\n\tid INT, " + //
"\n\tINDEX USING BTREE(id)" + "\n) MIN_ROWS = 1024", output);
}
Aggregations