use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlCreateTableTest59 method test_one.
@Test
public void test_one() throws Exception {
String sql = "create table t3 (a long, b long byte);";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseCreateTable();
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
stmt.accept(visitor);
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals(//
"CREATE TABLE t3 (" + //
"\n\ta long, " + //
"\n\tb long byte" + "\n)", output);
}
use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlCreateTableTest6 method test_0.
public void test_0() throws Exception {
String sql = //
"CREATE TABLE Persons\n" + //
"(\n" + //
"Id_P int NOT NULL,\n" + //
"LastName varchar(255) NOT NULL,\n" + //
"FirstName varchar(255),\n" + //
"Address varchar(255),\n" + //
"City varchar(255),\n" + //
"UNIQUE (Id_P)\n" + ")";
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
MySqlCreateTableStatement stmt = (MySqlCreateTableStatement) 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(5, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("Persons")));
Assert.assertTrue(visitor.getColumns().contains(new Column("Persons", "Id_P")));
Assert.assertTrue(visitor.getColumns().contains(new Column("Persons", "LastName")));
}
use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlCreateTableTest48 method test_0.
public void test_0() throws Exception {
String sql = //
"CREATE TABLE AO_E8B6CC_REPO_TO_CHANGESET (" + //
" CHANGESET_ID INTEGER," + //
" ID INTEGER AUTO_INCREMENT NOT NULL," + //
" REPOSITORY_ID INTEGER," + //
" CONSTRAINT fk_ao_e8b6cc_repo_to_changeset_repository_id FOREIGN KEY (REPOSITORY_ID) REFERENCES AO_E8B6CC_REPOSITORY_MAPPING(ID)," + //
" CONSTRAINT fk_ao_e8b6cc_repo_to_changeset_changeset_id FOREIGN KEY (CHANGESET_ID) REFERENCES AO_E8B6CC_CHANGESET_MAPPING(ID)," + //
" PRIMARY KEY(ID)" + //
") ENGINE=InnoDB";
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(3, visitor.getTables().size());
Assert.assertEquals(6, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("AO_E8B6CC_REPO_TO_CHANGESET")));
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals(//
"CREATE TABLE AO_E8B6CC_REPO_TO_CHANGESET (" + //
"\n\tCHANGESET_ID INTEGER, " + //
"\n\tID INTEGER NOT NULL AUTO_INCREMENT, " + //
"\n\tREPOSITORY_ID INTEGER, " + //
"\n\tCONSTRAINT fk_ao_e8b6cc_repo_to_changeset_repository_id FOREIGN KEY (REPOSITORY_ID) REFERENCES AO_E8B6CC_REPOSITORY_MAPPING (ID), " + //
"\n\tCONSTRAINT fk_ao_e8b6cc_repo_to_changeset_changeset_id FOREIGN KEY (CHANGESET_ID) REFERENCES AO_E8B6CC_CHANGESET_MAPPING (ID), " + //
"\n\tPRIMARY KEY (ID)" + //
"\n) ENGINE = InnoDB", output);
}
use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlCreateTableTest5 method test_0.
public void test_0() throws Exception {
String sql = //
"CREATE TABLE `test` (" + //
" `id` bigint(20) NOT NULL AUTO_INCREMENT," + //
" `dspcode` char(200) DEFAULT NULL," + //
" PRIMARY KEY (`id`)," + //
" KEY `index_name` (`dspcode`)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
MySqlCreateTableStatement stmt = (MySqlCreateTableStatement) statementList.get(0);
// print(statementList);
Assert.assertEquals(1, statementList.size());
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
stmt.accept(visitor);
Assert.assertEquals("utf8", stmt.getTableOptions().get("CHARSET").toString());
// 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", "dspcode")));
}
use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlCreateTableTest50 method test_0.
public void test_0() throws Exception {
String sql = //
"CREATE TABLE `test`.`a` (" + //
" `ida` INT NOT NULL COMMENT 'aaa' ," + //
" PRIMARY KEY (`ida`) )" + //
" COMMENT = 'bb';";
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(1, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("test.a")));
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals(//
"CREATE TABLE `test`.`a` (" + //
"\n\t`ida` INT NOT NULL COMMENT 'aaa', " + //
"\n\tPRIMARY KEY (`ida`)" + //
"\n) COMMENT = 'bb'", output);
}
Aggregations