use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlCreateDatabaseTest2 method test_one.
@Test
public void test_one() throws Exception {
String sql = "CREATE DATABASE testRep CHARACTER SET utf8 COLLATE utf8_general_ci";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseStatement();
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
stmt.accept(visitor);
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("CREATE DATABASE testRep CHARACTER SET utf8 COLLATE utf8_general_ci", output);
}
use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlAlterTableTest16 method test_alter_first.
public void test_alter_first() throws Exception {
String sql = "alter table st_jklsxxb enable constraint FK_ST_xxx_REFERENCE_ST_xxx";
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 st_jklsxxb" + "\n\tENABLE CONSTRAINT FK_ST_xxx_REFERENCE_ST_xxx", 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 MySqlAlterTableTest17 method test_alter_first.
public void test_alter_first() throws Exception {
String sql = "alter table rms.rms_Person_Event drop foreign key FKA382487726D72F65";
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 rms.rms_Person_Event\n" + "\tDROP FOREIGN KEY FKA382487726D72F65", 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 MySqlAlterTableTest4 method test_alter_first.
public void test_alter_first() throws Exception {
String sql = "alter table test add dspcode char(200)";
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 test" + "\n\tADD COLUMN dspcode char(200)", output);
Assert.assertEquals(1, visitor.getTables().size());
Assert.assertEquals(1, visitor.getColumns().size());
Assert.assertTrue(visitor.getColumns().contains(new Column("test", "dspcode")));
}
use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlAlterTableTest10 method test_alter_first.
public void test_alter_first() throws Exception {
String sql = "ALTER TABLE t1 CHANGE a b INTEGER;";
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 t1" + "\n\tCHANGE COLUMN a b INTEGER", output);
Assert.assertEquals(1, visitor.getTables().size());
Assert.assertEquals(1, visitor.getColumns().size());
}
Aggregations