提交 fe3c26a0 authored 作者: Hendrik Schreiber's avatar Hendrik Schreiber

Support for BEFORE and AFTER clauses when using multiple columns in ALTER TABLE ADD.

上级 61b93a60
......@@ -226,8 +226,8 @@ ALTER SEQUENCE SEQ_ID RESTART WITH 1000
"Commands (DDL)","ALTER TABLE ADD","
ALTER TABLE [ IF EXISTS ] tableName ADD [ COLUMN ]
{ [ IF NOT EXISTS ] columnDefinition [ { BEFORE | AFTER } columnName ]
| ( { columnDefinition } [,...] ) }
{ [ IF NOT EXISTS ] columnDefinition | ( { columnDefinition } [,...] ) }
[ { BEFORE | AFTER } columnName ]
","
Adds a new column to a table.
This command commits an open transaction in this connection.
......
......@@ -5719,7 +5719,11 @@ public class Parser {
columnsToAdd.add(column);
} while (readIf(","));
read(")");
command.setNewColumns(columnsToAdd);
if (readIf("BEFORE")) {
command.setAddBefore(readColumnIdentifier());
} else if (readIf("AFTER")) {
command.setAddAfter(readColumnIdentifier());
}
} else {
boolean ifNotExists = readIfNotExists();
command.setIfNotExists(ifNotExists);
......
......@@ -84,8 +84,8 @@ ALTER SEQUENCE [ IF EXISTS ] sequenceName [ RESTART WITH long ] [ INCREMENT BY l
Changes the parameters of a sequence."
"Commands (DDL)","ALTER TABLE ADD","
ALTER TABLE [ IF EXISTS ] tableName ADD [ COLUMN ]
{ [ IF NOT EXISTS ] columnDefinition [ { BEFORE | AFTER } columnName ]
| ( { columnDefinition } [,...] ) }
{ [ IF NOT EXISTS ] columnDefinition | ( { columnDefinition } [,...] ) }
[ { BEFORE | AFTER } columnName ]
","
Adds a new column to a table."
"Commands (DDL)","ALTER TABLE ADD CONSTRAINT","
......
......@@ -48,6 +48,8 @@ public class TestAlter extends TestBase {
testAlterTableAlterColumn2();
testAlterTableAddColumnBefore();
testAlterTableAddColumnAfter();
testAlterTableAddMultipleColumnsBefore();
testAlterTableAddMultipleColumnsAfter();
testAlterTableModifyColumn();
conn.close();
deleteDb(getTestName());
......@@ -206,6 +208,38 @@ 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)");
stat.execute("alter table T add (Y int, Z int) before X");
DatabaseMetaData dbMeta = conn.getMetaData();
ResultSet rs = dbMeta.getColumns(null, null, "T", null);
assertTrue(rs.next());
assertEquals("Y", rs.getString("COLUMN_NAME"));
assertTrue(rs.next());
assertEquals("Z", rs.getString("COLUMN_NAME"));
assertTrue(rs.next());
assertEquals("X", rs.getString("COLUMN_NAME"));
assertFalse(rs.next());
stat.execute("drop table T");
}
// column and field names must be upper-case due to getMetaData sensitivity
private void testAlterTableAddMultipleColumnsAfter() throws SQLException {
stat.execute("create table T(X varchar)");
stat.execute("alter table T add (Y int, Z int) after X");
DatabaseMetaData dbMeta = conn.getMetaData();
ResultSet rs = dbMeta.getColumns(null, null, "T", null);
assertTrue(rs.next());
assertEquals("X", rs.getString("COLUMN_NAME"));
assertTrue(rs.next());
assertEquals("Y", rs.getString("COLUMN_NAME"));
assertTrue(rs.next());
assertEquals("Z", rs.getString("COLUMN_NAME"));
assertFalse(rs.next());
stat.execute("drop table T");
}
// column and field names must be upper-case due to getMetaData sensitivity
private void testAlterTableAddColumnBefore() throws SQLException {
stat.execute("create table T(X varchar)");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论