Search in sources :

Example 6 with SQLAlterTableStatement

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

the class CreateCompareTest_cycle method test_0.

public void test_0() throws Exception {
    String sql = "CREATE TABLE t0 (\n" + "\tint bigint\n" + ");\n" + "\n" + "CREATE TABLE t1 (\n" + "\tint bigint\n" + ");\n" + "CREATE TABLE t2 (\n" + "\tint bigint,\n" + "\tFOREIGN KEY (id)\n" + "\t\tREFERENCES t1 (id)\n" + ");\n" + "\n" + "CREATE TABLE t3 (\n" + "\tint bigint,\n" + "\tFOREIGN KEY (id)\n" + "\t\tREFERENCES t2 (id)\n" + ");\n" + "\n" + "CREATE TABLE t4 (\n" + "\tint bigint,\n" + "\tFOREIGN KEY (id)\n" + "\t\tREFERENCES t3 (id),\n" + "\tFOREIGN KEY (id)\n" + "\t\tREFERENCES t4 (id)\n" + ");\n" + "\n" + "CREATE TABLE t5 (\n" + "\tint bigint,\n" + "\tFOREIGN KEY (id)\n" + "\t\tREFERENCES t4 (id)\n" + ");\n" + "\n" + "CREATE TABLE t6 (\n" + "\tint bigint,\n" + "\tFOREIGN KEY (id)\n" + "\t\tREFERENCES t5 (id)\n" + ");\n" + "\n" + "CREATE TABLE t7 (\n" + "\tint bigint,\n" + "\tFOREIGN KEY (id)\n" + "\t\tREFERENCES t6 (id)\n" + ");\n" + "\n" + "\n" + "CREATE TABLE t8 (\n" + "\tint bigint,\n" + "\tFOREIGN KEY (id)\n" + "\t\tREFERENCES t7 (id)\n" + ");\n" + "\n" + "CREATE TABLE t9 (\n" + "\tint bigint,\n" + "\tFOREIGN KEY (id)\n" + "\t\tREFERENCES t8 (id)\n" + ");";
    List stmtList = SQLUtils.parseStatements(sql, JdbcConstants.ORACLE);
    SQLCreateTableStatement.sort(stmtList);
    String sortedSql = SQLUtils.toSQLString(stmtList, JdbcConstants.ORACLE);
    System.out.println(sortedSql);
    assertEquals("t0", ((SQLCreateTableStatement) stmtList.get(9)).getName().getSimpleName());
    assertEquals("t9", ((SQLCreateTableStatement) stmtList.get(8)).getName().getSimpleName());
    assertEquals("t8", ((SQLCreateTableStatement) stmtList.get(7)).getName().getSimpleName());
    assertEquals("t7", ((SQLCreateTableStatement) stmtList.get(6)).getName().getSimpleName());
    assertEquals("t6", ((SQLCreateTableStatement) stmtList.get(5)).getName().getSimpleName());
    assertEquals("t5", ((SQLCreateTableStatement) stmtList.get(4)).getName().getSimpleName());
    assertEquals("t4", ((SQLCreateTableStatement) stmtList.get(3)).getName().getSimpleName());
    assertEquals("t3", ((SQLCreateTableStatement) stmtList.get(2)).getName().getSimpleName());
    assertEquals("t2", ((SQLCreateTableStatement) stmtList.get(1)).getName().getSimpleName());
    assertEquals("t1", ((SQLCreateTableStatement) stmtList.get(0)).getName().getSimpleName());
    assertEquals("t4", ((SQLAlterTableStatement) stmtList.get(10)).getName().getSimpleName());
    assertEquals(11, stmtList.size());
}
Also used : SQLCreateTableStatement(com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement) SQLAlterTableStatement(com.alibaba.druid.sql.ast.statement.SQLAlterTableStatement) List(java.util.List)

Example 7 with SQLAlterTableStatement

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

the class MySqlAlterTableTest54 method test_2.

public void test_2() throws Exception {
    String sql = "alter table event_log storage_policy = 'MIXED' hot_partition_count = 10;";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    SQLAlterTableStatement stmt = (SQLAlterTableStatement) parser.parseStatementList().get(0);
    assertEquals(2, stmt.getTableOptions().size());
    String formatSql = SQLUtils.toSQLString(stmt);
    assertEquals("ALTER TABLE event_log\n" + "\tSTORAGE_POLICY = 'MIXED' HOT_PARTITION_COUNT = 10;", formatSql);
}
Also used : SQLAlterTableStatement(com.alibaba.druid.sql.ast.statement.SQLAlterTableStatement) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)

Example 8 with SQLAlterTableStatement

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

the class MySqlAlterTableTest54 method test_3.

public void test_3() throws Exception {
    String sql = "alter table event_log hot_partition_count = 10;";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    SQLAlterTableStatement stmt = (SQLAlterTableStatement) parser.parseStatementList().get(0);
    assertEquals(1, stmt.getTableOptions().size());
    String formatSql = SQLUtils.toSQLString(stmt);
    assertEquals("ALTER TABLE event_log\n" + "\tHOT_PARTITION_COUNT = 10;", formatSql);
}
Also used : SQLAlterTableStatement(com.alibaba.druid.sql.ast.statement.SQLAlterTableStatement) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)

Example 9 with SQLAlterTableStatement

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

the class MySqlAlterTableTest54 method test_7.

public void test_7() throws Exception {
    String sql = "alter table event_log storage_policy = COLD";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    try {
        SQLAlterTableStatement stmt = (SQLAlterTableStatement) parser.parseStatementList().get(0);
        fail();
    } catch (Exception e) {
    }
}
Also used : SQLAlterTableStatement(com.alibaba.druid.sql.ast.statement.SQLAlterTableStatement) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) ParserException(com.alibaba.druid.sql.parser.ParserException)

Example 10 with SQLAlterTableStatement

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

the class MySqlAlterTableTest54 method test_0.

public void test_0() throws Exception {
    String sql = "alter table event_log storage_policy = 'HOT'";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    SQLAlterTableStatement stmt = (SQLAlterTableStatement) parser.parseStatementList().get(0);
    assertEquals(1, stmt.getTableOptions().size());
    String formatSql = SQLUtils.toSQLString(stmt);
    assertEquals("ALTER TABLE event_log\n" + "\tSTORAGE_POLICY = 'HOT'", formatSql);
}
Also used : SQLAlterTableStatement(com.alibaba.druid.sql.ast.statement.SQLAlterTableStatement) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)

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