提交 db9406e2 authored 作者: plus33's avatar plus33

Support drop-columns using brackets (Oracle syntax style)

E.g. 
  alter table test drop (a, b) 
works same as  
  alter table test drop column a, b 
上级 6888e92a
......@@ -6073,6 +6073,7 @@ public class Parser {
command.setType(CommandInterface.ALTER_TABLE_DROP_COLUMN);
ArrayList<Column> columnsToRemove = New.arrayList();
Table table = tableIfTableExists(schema, tableName, ifTableExists);
readIf("("); // For Oracle compatibility - open bracket required
do {
String columnName = readColumnIdentifier();
if (table == null) {
......@@ -6084,6 +6085,7 @@ public class Parser {
Column column = table.getColumn(columnName);
columnsToRemove.add(column);
} while (readIf(","));
readIf(")"); // Fro Oracle compatibility - close bracket
command.setTableName(tableName);
command.setIfTableExists(ifTableExists);
command.setColumnsToRemove(columnsToRemove);
......
......@@ -116,7 +116,13 @@ public class TestAlter extends TestBase {
stat.execute("create table test(id int, name varchar, name2 varchar)");
stat.execute("alter table test drop column name, name2");
stat.execute("drop table test");
// Test-Case: Same as above but using brackets (Oracle style)
stat.execute("create table test(id int, name varchar, name2 varchar)");
stat.execute("alter table test drop column (name, name2)");
assertThrows(ErrorCode.COLUMN_NOT_FOUND_1, stat).
execute("alter table test drop column name");
stat.execute("drop table test");
// Test-Case: Error if dropping all columns
stat.execute("create table test(id int, name varchar, name2 varchar)");
assertThrows(ErrorCode.CANNOT_DROP_LAST_COLUMN, stat).
execute("alter table test drop column id, name, name2");
......@@ -209,6 +215,8 @@ public class TestAlter extends TestBase {
stat.execute("drop table t");
}
// column and field names must be upper-case due to getMetaData sensitivity
private void testAlterTableAddMultipleColumnsBefore() throws SQLException {
stat.execute("create table T(X varchar)");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论