Search in sources :

Example 16 with SQLUtils

use of com.alibaba.druid.sql.SQLUtils in project druid by alibaba.

the class MySqlAlterTableAddIndex_9 method test_5.

public void test_5() throws Exception {
    String sql = "alter table xxx add key `idx_001`(`current_timestamp`,`curdate`,`LOCALTIME`, `LOCALTIMESTAMP`)";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    Assert.assertEquals("ALTER TABLE xxx\n" + "\tADD KEY `idx_001` (`current_timestamp`, `curdate`, `LOCALTIME`, `LOCALTIMESTAMP`)", SQLUtils.toMySqlString(stmt));
    Assert.assertEquals("alter table xxx\n" + "\tadd key `idx_001` (`current_timestamp`, `curdate`, `LOCALTIME`, `LOCALTIMESTAMP`)", SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
    SchemaStatVisitor visitor = new SQLUtils().createSchemaStatVisitor(JdbcConstants.MYSQL);
    stmt.accept(visitor);
    TableStat tableStat = visitor.getTableStat("xxx");
    assertNotNull(tableStat);
    assertEquals(1, tableStat.getAlterCount());
    assertEquals(1, tableStat.getCreateIndexCount());
}
Also used : TableStat(com.alibaba.druid.stat.TableStat) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) SQLUtils(com.alibaba.druid.sql.SQLUtils) SchemaStatVisitor(com.alibaba.druid.sql.visitor.SchemaStatVisitor)

Example 17 with SQLUtils

use of com.alibaba.druid.sql.SQLUtils in project druid by alibaba.

the class MySqlAlterTableAddIndex_9 method test_4.

public void test_4() throws Exception {
    String sql = "alter table xxx add key `idx_001`(`col1`,`current_time`,`col2`)";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    Assert.assertEquals("ALTER TABLE xxx\n" + "\tADD KEY `idx_001` (`col1`, `current_time`, `col2`)", SQLUtils.toMySqlString(stmt));
    Assert.assertEquals("alter table xxx\n" + "\tadd key `idx_001` (`col1`, `current_time`, `col2`)", SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
    SchemaStatVisitor visitor = new SQLUtils().createSchemaStatVisitor(JdbcConstants.MYSQL);
    stmt.accept(visitor);
    TableStat tableStat = visitor.getTableStat("xxx");
    assertNotNull(tableStat);
    assertEquals(1, tableStat.getAlterCount());
    assertEquals(1, tableStat.getCreateIndexCount());
}
Also used : TableStat(com.alibaba.druid.stat.TableStat) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) SQLUtils(com.alibaba.druid.sql.SQLUtils) SchemaStatVisitor(com.alibaba.druid.sql.visitor.SchemaStatVisitor)

Example 18 with SQLUtils

use of com.alibaba.druid.sql.SQLUtils in project druid by alibaba.

the class MySqlAlterTableAddIndex_9 method test_3.

public void test_3() throws Exception {
    String sql = "alter table xxx add key `idx_001`(`col1`,`current_date`,`col2`)";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    Assert.assertEquals("ALTER TABLE xxx\n" + "\tADD KEY `idx_001` (`col1`, `current_date`, `col2`)", SQLUtils.toMySqlString(stmt));
    Assert.assertEquals("alter table xxx\n" + "\tadd key `idx_001` (`col1`, `current_date`, `col2`)", SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
    SchemaStatVisitor visitor = new SQLUtils().createSchemaStatVisitor(JdbcConstants.MYSQL);
    stmt.accept(visitor);
    TableStat tableStat = visitor.getTableStat("xxx");
    assertNotNull(tableStat);
    assertEquals(1, tableStat.getAlterCount());
    assertEquals(1, tableStat.getCreateIndexCount());
}
Also used : TableStat(com.alibaba.druid.stat.TableStat) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) SQLUtils(com.alibaba.druid.sql.SQLUtils) SchemaStatVisitor(com.alibaba.druid.sql.visitor.SchemaStatVisitor)

Example 19 with SQLUtils

use of com.alibaba.druid.sql.SQLUtils in project druid by alibaba.

the class MySqlAlterTableAddIndex_9 method test_2.

public void test_2() throws Exception {
    String sql = "ALTER TABLE t_order ADD CLUSTERED KEY `g_i_buyer` (`buyer_id`);";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    Assert.assertEquals("ALTER TABLE t_order\n" + "\tADD CLUSTERED KEY `g_i_buyer` (`buyer_id`);", SQLUtils.toMySqlString(stmt));
    Assert.assertEquals("alter table t_order\n" + "\tadd clustered key `g_i_buyer` (`buyer_id`);", SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
    SchemaStatVisitor visitor = new SQLUtils().createSchemaStatVisitor(JdbcConstants.MYSQL);
    stmt.accept(visitor);
    TableStat tableStat = visitor.getTableStat("t_order");
    assertNotNull(tableStat);
    assertEquals(1, tableStat.getAlterCount());
    assertEquals(1, tableStat.getCreateIndexCount());
}
Also used : TableStat(com.alibaba.druid.stat.TableStat) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) SQLUtils(com.alibaba.druid.sql.SQLUtils) SchemaStatVisitor(com.alibaba.druid.sql.visitor.SchemaStatVisitor)

Example 20 with SQLUtils

use of com.alibaba.druid.sql.SQLUtils in project druid by alibaba.

the class MySqlAlterTableDropIndex_0 method test_alter_first.

public void test_alter_first() throws Exception {
    String sql = "ALTER TABLE `test`.`tb1` DROP INDEX `ix` ;";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    assertEquals(// 
    "ALTER TABLE `test`.`tb1`" + "\n\tDROP INDEX `ix`;", SQLUtils.toMySqlString(stmt));
    assertEquals(// 
    "alter table `test`.`tb1`" + "\n\tdrop index `ix`;", SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
    SchemaStatVisitor visitor = new SQLUtils().createSchemaStatVisitor(JdbcConstants.MYSQL);
    stmt.accept(visitor);
    TableStat tableStat = visitor.getTableStat("test.tb1");
    assertNotNull(tableStat);
    assertEquals(1, tableStat.getAlterCount());
    assertEquals(1, tableStat.getDropIndexCount());
}
Also used : TableStat(com.alibaba.druid.stat.TableStat) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) SQLUtils(com.alibaba.druid.sql.SQLUtils) SchemaStatVisitor(com.alibaba.druid.sql.visitor.SchemaStatVisitor)

Aggregations

SQLUtils (com.alibaba.druid.sql.SQLUtils)35 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)35 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)35 SchemaStatVisitor (com.alibaba.druid.sql.visitor.SchemaStatVisitor)35 TableStat (com.alibaba.druid.stat.TableStat)35 MySqlSchemaStatVisitor (com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor)1