Search in sources :

Example 11 with SQLAlterTableStatement

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

the class MySqlAlterTableTest_40_change method test_alter_constraint.

public void test_alter_constraint() throws Exception {
    String sql = "alter table sdfwef change column a c int";
    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());
    Assert.assertEquals("ALTER TABLE sdfwef\n" + "\tCHANGE COLUMN a c int", SQLUtils.toMySqlString(stmt));
    Assert.assertEquals("alter table sdfwef\n" + "\tchange column a c int", SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
    Assert.assertEquals(1, visitor.getTables().size());
    Assert.assertEquals(1, visitor.getColumns().size());
    assertTrue(isRenameColumn((SQLAlterTableStatement) stmt));
}
Also used : MySqlSchemaStatVisitor(com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor) SQLAlterTableStatement(com.alibaba.druid.sql.ast.statement.SQLAlterTableStatement) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Aggregations

SQLAlterTableStatement (com.alibaba.druid.sql.ast.statement.SQLAlterTableStatement)11 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)6 SQLCreateTableStatement (com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement)3 ParserException (com.alibaba.druid.sql.parser.ParserException)3 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)2 SQLAlterTableDropConstraint (com.alibaba.druid.sql.ast.statement.SQLAlterTableDropConstraint)2 SQLAlterTableDropIndex (com.alibaba.druid.sql.ast.statement.SQLAlterTableDropIndex)2 SQLCreateDatabaseStatement (com.alibaba.druid.sql.ast.statement.SQLCreateDatabaseStatement)2 SQLDeleteStatement (com.alibaba.druid.sql.ast.statement.SQLDeleteStatement)2 SQLDropTableStatement (com.alibaba.druid.sql.ast.statement.SQLDropTableStatement)2 SQLInsertStatement (com.alibaba.druid.sql.ast.statement.SQLInsertStatement)2 SQLUpdateStatement (com.alibaba.druid.sql.ast.statement.SQLUpdateStatement)2 SQLOver (com.alibaba.druid.sql.ast.SQLOver)1 SQLAllExpr (com.alibaba.druid.sql.ast.expr.SQLAllExpr)1 SQLAnyExpr (com.alibaba.druid.sql.ast.expr.SQLAnyExpr)1 SQLBinaryOpExpr (com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr)1 SQLCurrentOfCursorExpr (com.alibaba.druid.sql.ast.expr.SQLCurrentOfCursorExpr)1 SQLDefaultExpr (com.alibaba.druid.sql.ast.expr.SQLDefaultExpr)1 SQLInListExpr (com.alibaba.druid.sql.ast.expr.SQLInListExpr)1 SQLMethodInvokeExpr (com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr)1