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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations