use of com.alibaba.druid.sql.SQLUtils in project druid by alibaba.
the class MySqlAlterTableAddIndex_10 method test_alter_table_add_constraint_primary_key_with_options.
public void test_alter_table_add_constraint_primary_key_with_options() throws Exception {
String sql = "alter table test001 add constraint primary key using btree (b) key_block_size=32 comment 'hehe' using btree;";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
Assert.assertEquals("ALTER TABLE test001\n" + "\tADD PRIMARY KEY USING btree (b) KEY_BLOCK_SIZE = 32 COMMENT 'hehe';", SQLUtils.toMySqlString(stmt));
Assert.assertEquals("alter table test001\n" + "\tadd primary key using btree (b) key_block_size = 32 comment 'hehe';", SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
SchemaStatVisitor visitor = new SQLUtils().createSchemaStatVisitor(JdbcConstants.MYSQL);
stmt.accept(visitor);
TableStat tableStat = visitor.getTableStat("test001");
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_10 method test_alter_table_add_index_multi_type.
public void test_alter_table_add_index_multi_type() throws Exception {
String sql = "ALTER TABLE test001 ADD INDEX `i2` using btree (`b`) key_block_size=32 comment 'hehe' using hash;";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
Assert.assertEquals("ALTER TABLE test001\n" + "\tADD INDEX `i2` USING hash (`b`) KEY_BLOCK_SIZE = 32 COMMENT 'hehe';", SQLUtils.toMySqlString(stmt));
Assert.assertEquals("alter table test001\n" + "\tadd index `i2` using hash (`b`) key_block_size = 32 comment 'hehe';", SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
SchemaStatVisitor visitor = new SQLUtils().createSchemaStatVisitor(JdbcConstants.MYSQL);
stmt.accept(visitor);
TableStat tableStat = visitor.getTableStat("test001");
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_6 method test_alter_first.
public void test_alter_first() throws Exception {
String sql = "ALTER TABLE t_order ADD UNIQUE GLOBAL INDEX `g_i_buyer` (`buyer_id`) COVERING (order_snapshot) dbpartition by hash(`buyer_id`) tbpartition by hash(`buyer_id`) COMMENT \"CREATE GSI TEST\";";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
Assert.assertEquals("ALTER TABLE t_order\n" + "\tADD UNIQUE GLOBAL INDEX `g_i_buyer` (`buyer_id`) COVERING (order_snapshot) DBPARTITION BY hash(`buyer_id`) TBPARTITION BY hash(`buyer_id`) COMMENT 'CREATE GSI TEST';", SQLUtils.toMySqlString(stmt));
Assert.assertEquals("alter table t_order\n" + "\tadd unique global index `g_i_buyer` (`buyer_id`) covering (order_snapshot) dbpartition by hash(`buyer_id`) tbpartition by hash(`buyer_id`) comment 'CREATE GSI TEST';", 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 MySqlAlterTableAddIndex_8 method test_alter_first.
public void test_alter_first() throws Exception {
String sql = "alter table `seller_table2` rename `seller_table3` , add key `idx_create`(`gmt_create`)";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
Assert.assertEquals("ALTER TABLE `seller_table2`\n" + "\tRENAME TO `seller_table3`,\n" + "\tADD KEY `idx_create` (`gmt_create`)", SQLUtils.toMySqlString(stmt));
Assert.assertEquals("alter table `seller_table2`\n" + "\trename to `seller_table3`,\n" + "\tadd key `idx_create` (`gmt_create`)", SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
SchemaStatVisitor visitor = new SQLUtils().createSchemaStatVisitor(JdbcConstants.MYSQL);
stmt.accept(visitor);
TableStat tableStat = visitor.getTableStat("seller_table2");
assertNotNull(tableStat);
assertEquals(1, tableStat.getAlterCount());
assertEquals(1, tableStat.getCreateIndexCount());
}
use of com.alibaba.druid.sql.SQLUtils in project druid by alibaba.
the class MySqlAlterTableAddPrimaryKey method test_alter_first.
public void test_alter_first() throws Exception {
String sql = "ALTER TABLE `test`.`tb1` CHANGE COLUMN `fid` `fid` INT(11) NOT NULL DEFAULT NULL, ADD PRIMARY KEY (`fid`) ;";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
Assert.assertEquals(//
"ALTER TABLE `test`.`tb1`" + //
"\n\tCHANGE COLUMN `fid` `fid` INT(11) NOT NULL DEFAULT NULL,\n\t" + "ADD PRIMARY KEY (`fid`);", SQLUtils.toMySqlString(stmt));
Assert.assertEquals(//
"alter table `test`.`tb1`" + //
"\n\tchange column `fid` `fid` INT(11) not null default null,\n\t" + "add primary key (`fid`);", 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.getCreateIndexCount());
}
Aggregations