Search in sources :

Example 1 with SQLDropIndexStatement

use of com.alibaba.druid.sql.ast.statement.SQLDropIndexStatement in project druid by alibaba.

the class MySqlDropIndexTest method test_0.

public void test_0() throws Exception {
    String sql = "drop index index_name on table_name ";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLDropIndexStatement stmt = (SQLDropIndexStatement) 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(0, visitor.getColumns().size());
    Assert.assertEquals(0, visitor.getConditions().size());
    Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("table_name")));
    TableStat tableStat = visitor.getTables().get(new TableStat.Name("table_name"));
    Assert.assertEquals(1, tableStat.getDropIndexCount());
}
Also used : MySqlSchemaStatVisitor(com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor) TableStat(com.alibaba.druid.stat.TableStat) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) SQLDropIndexStatement(com.alibaba.druid.sql.ast.statement.SQLDropIndexStatement)

Aggregations

SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)1 SQLDropIndexStatement (com.alibaba.druid.sql.ast.statement.SQLDropIndexStatement)1 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)1 MySqlSchemaStatVisitor (com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor)1 TableStat (com.alibaba.druid.stat.TableStat)1