use of com.alibaba.druid.stat.TableStat.Column in project druid by alibaba.
the class MySqlCreateTableTest73 method test_one.
@Test
public void test_one() throws Exception {
String sql = "CREATE TABLE total (" + " id INT NOT NULL AUTO_INCREMENT," + " message CHAR(20), INDEX(a))" + " ENGINE=MERGE UNION=(t1,t2) INSERT_METHOD=LAST;";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseCreateTable();
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
stmt.accept(visitor);
Column column = visitor.getColumn("total", "id");
Assert.assertNotNull(column);
Assert.assertEquals("INT", column.getDataType());
{
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("CREATE TABLE total (" + "\n\tid INT NOT NULL AUTO_INCREMENT, " + "\n\tmessage CHAR(20), " + "\n\tINDEX(a)" + "\n) ENGINE = MERGE UNION = (t1, t2) INSERT_METHOD = LAST", output);
}
{
String output = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
Assert.assertEquals("create table total (" + "\n\tid INT not null auto_increment, " + "\n\tmessage CHAR(20), " + "\n\tindex(a)" + "\n) engine = MERGE union = (t1, t2) insert_method = LAST", output);
}
}
use of com.alibaba.druid.stat.TableStat.Column in project druid by alibaba.
the class MySqlCreateTableTest8 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" + //
"CHECK (Id_P>0)\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(1, 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")));
Assert.assertTrue(visitor.getColumns().contains(new Column("Persons", "FirstName")));
Assert.assertTrue(visitor.getColumns().contains(new Column("Persons", "Address")));
Assert.assertTrue(visitor.getColumns().contains(new Column("Persons", "City")));
}
use of com.alibaba.druid.stat.TableStat.Column in project druid by alibaba.
the class MySqlCreateTableTest9 method test_0.
public void test_0() throws Exception {
String sql = //
"CREATE VIEW v AS\n" + //
"SELECT ProductID,ProductName\n" + //
"FROM Products\n" + "WHERE Discontinued=No";
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLCreateViewStatement stmt = (SQLCreateViewStatement) 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(2, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("Products")));
Assert.assertTrue(visitor.getColumns().contains(new Column("Products", "ProductID")));
Assert.assertTrue(visitor.getColumns().contains(new Column("Products", "ProductName")));
Assert.assertTrue(visitor.getColumns().contains(new Column("Products", "Discontinued")));
Assert.assertTrue(visitor.getColumns().contains(new Column("Products", "No")));
}
use of com.alibaba.druid.stat.TableStat.Column in project druid by alibaba.
the class MySqlSelectTest_18 method test_0.
public void test_0() throws Exception {
String sql = //
"SELECT host.id as id" + //
", host.item_id as itemId" + //
", host.node_id as nodeId" + //
", host.node_type as nodeType" + //
", host.begin_time as beginTime" + //
", host.end_time as endTime" + //
", host.gmt_create as gmtCreate" + //
", host.gmt_modify as gmtModify" + //
", host.reason as reason" + //
", host.creator_id as creatorId" + //
", host.modifier_id as modifierId" + //
", user.name as creator" + //
", user.name as modifier" + //
", user.nick_name as nickName " + " FROM notice_close_node host left join sys_user user on user.id = host.modifier_id";
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(2, visitor.getTables().size());
Assert.assertEquals(15, visitor.getColumns().size());
Assert.assertEquals(2, visitor.getConditions().size());
Assert.assertTrue(visitor.getColumns().contains(new Column("sys_user", "id")));
Assert.assertTrue(visitor.getColumns().contains(new Column("notice_close_node", "modifier_id")));
}
use of com.alibaba.druid.stat.TableStat.Column in project druid by alibaba.
the class MySqlSelectTest_20 method test_0.
public void test_0() throws Exception {
String sql = "select bsvariety, max(bsh) as bsh, min(bsl) as bsl " + " from exchange_market_info " + " where bsdate>date_sub(now(),interval 1 day)" + " group by bsvariety desc;";
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.assertTrue(visitor.getColumns().contains(new Column("exchange_market_info", "bsvariety")));
Assert.assertTrue(visitor.getColumns().contains(new Column("exchange_market_info", "bsh")));
Assert.assertTrue(visitor.getColumns().contains(new Column("exchange_market_info", "bsl")));
Assert.assertTrue(visitor.getColumns().contains(new Column("exchange_market_info", "bsdate")));
Assert.assertEquals(1, visitor.getTables().size());
Assert.assertEquals(4, visitor.getColumns().size());
Assert.assertEquals(1, visitor.getConditions().size());
Assert.assertEquals(0, visitor.getOrderByColumns().size());
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("SELECT bsvariety, MAX(bsh) AS bsh, MIN(bsl) AS bsl" + "\nFROM exchange_market_info" + "\nWHERE bsdate > date_sub(now(), INTERVAL 1 DAY)" + "\nGROUP BY bsvariety DESC", output);
}
Aggregations