Search in sources :

Example 6 with SQLCreateIndexStatement

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

the class SQLServerCreateIndexTest_2 method test_0.

public void test_0() throws Exception {
    String sql = "CREATE UNIQUE CLUSTERED INDEX Idx1 ON t1(c);";
    SQLServerStatementParser parser = new SQLServerStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLCreateIndexStatement stmt = (SQLCreateIndexStatement) statementList.get(0);
    Assert.assertEquals(1, statementList.size());
    // 
    Assert.assertEquals(// 
    "CREATE UNIQUE CLUSTERED INDEX Idx1 ON t1 (c);", SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
    SQLServerSchemaStatVisitor visitor = new SQLServerSchemaStatVisitor();
    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("t1")));
    Assert.assertTrue(visitor.getColumns().contains(new Column("t1", "c")));
}
Also used : SQLServerSchemaStatVisitor(com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerSchemaStatVisitor) SQLServerStatementParser(com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser) Column(com.alibaba.druid.stat.TableStat.Column) SQLCreateIndexStatement(com.alibaba.druid.sql.ast.statement.SQLCreateIndexStatement) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Aggregations

SQLCreateIndexStatement (com.alibaba.druid.sql.ast.statement.SQLCreateIndexStatement)6 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)5 SQLServerStatementParser (com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser)4 SQLServerSchemaStatVisitor (com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerSchemaStatVisitor)4 Column (com.alibaba.druid.stat.TableStat.Column)3 SQLExprTableSource (com.alibaba.druid.sql.ast.statement.SQLExprTableSource)2 SQLTableSource (com.alibaba.druid.sql.ast.statement.SQLTableSource)2 SchemaInfo (com.actiontech.dble.server.util.SchemaUtil.SchemaInfo)1 SQLAlterTableAddConstraint (com.alibaba.druid.sql.ast.statement.SQLAlterTableAddConstraint)1 SQLAlterTableAddIndex (com.alibaba.druid.sql.ast.statement.SQLAlterTableAddIndex)1 SQLAlterTableDropConstraint (com.alibaba.druid.sql.ast.statement.SQLAlterTableDropConstraint)1 SQLAlterTableDropIndex (com.alibaba.druid.sql.ast.statement.SQLAlterTableDropIndex)1 SQLAlterTableDropKey (com.alibaba.druid.sql.ast.statement.SQLAlterTableDropKey)1 SQLAlterTableItem (com.alibaba.druid.sql.ast.statement.SQLAlterTableItem)1 SQLAlterTableRename (com.alibaba.druid.sql.ast.statement.SQLAlterTableRename)1 SQLAlterTableStatement (com.alibaba.druid.sql.ast.statement.SQLAlterTableStatement)1 SQLConstraint (com.alibaba.druid.sql.ast.statement.SQLConstraint)1 SQLCreateDatabaseStatement (com.alibaba.druid.sql.ast.statement.SQLCreateDatabaseStatement)1 SQLCreateTableStatement (com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement)1 SQLDeleteStatement (com.alibaba.druid.sql.ast.statement.SQLDeleteStatement)1