提交 2ec10192 authored 作者: Thomas Mueller's avatar Thomas Mueller

ALTER TABLE ALTER COLUMN: changing the data type of a column no longer makes it nullable.

上级 e166ac36
...@@ -557,7 +557,7 @@ public class Parser { ...@@ -557,7 +557,7 @@ public class Parser {
if (readIf("(")) { if (readIf("(")) {
ArrayList<Column> list = New.arrayList(); ArrayList<Column> list = New.arrayList();
for (int i = 0;; i++) { for (int i = 0;; i++) {
Column column = parseColumnForTable("C" + i); Column column = parseColumnForTable("C" + i, true);
list.add(column); list.add(column);
if (readIf(")")) { if (readIf(")")) {
break; break;
...@@ -3253,7 +3253,7 @@ public class Parser { ...@@ -3253,7 +3253,7 @@ public class Parser {
return IDENTIFIER; return IDENTIFIER;
} }
private Column parseColumnForTable(String columnName) { private Column parseColumnForTable(String columnName, boolean defaultNullable) {
Column column; Column column;
boolean isIdentity = false; boolean isIdentity = false;
if (readIf("IDENTITY") || readIf("SERIAL")) { if (readIf("IDENTITY") || readIf("SERIAL")) {
...@@ -3267,9 +3267,10 @@ public class Parser { ...@@ -3267,9 +3267,10 @@ public class Parser {
if (readIf("NOT")) { if (readIf("NOT")) {
read("NULL"); read("NULL");
column.setNullable(false); column.setNullable(false);
} else { } else if (readIf("NULL")) {
readIf("NULL");
column.setNullable(true); column.setNullable(true);
} else {
column.setNullable(defaultNullable);
} }
if (readIf("AS")) { if (readIf("AS")) {
if (isIdentity) { if (isIdentity) {
...@@ -3743,7 +3744,7 @@ public class Parser { ...@@ -3743,7 +3744,7 @@ public class Parser {
CreateUserDataType command = new CreateUserDataType(session); CreateUserDataType command = new CreateUserDataType(session);
command.setTypeName(readUniqueIdentifier()); command.setTypeName(readUniqueIdentifier());
read("AS"); read("AS");
Column col = parseColumnForTable("VALUE"); Column col = parseColumnForTable("VALUE", true);
if (readIf("CHECK")) { if (readIf("CHECK")) {
Expression expr = readExpression(); Expression expr = readExpression();
col.addCheckConstraint(session, expr); col.addCheckConstraint(session, expr);
...@@ -4453,7 +4454,7 @@ public class Parser { ...@@ -4453,7 +4454,7 @@ public class Parser {
if (readIf("DATA")) { if (readIf("DATA")) {
// Derby compatibility // Derby compatibility
read("TYPE"); read("TYPE");
Column newColumn = parseColumnForTable(columnName); Column newColumn = parseColumnForTable(columnName, column.isNullable());
AlterTableAlterColumn command = new AlterTableAlterColumn(session, table.getSchema()); AlterTableAlterColumn command = new AlterTableAlterColumn(session, table.getSchema());
command.setTable(table); command.setTable(table);
command.setType(AlterTableAlterColumn.CHANGE_TYPE); command.setType(AlterTableAlterColumn.CHANGE_TYPE);
...@@ -4492,7 +4493,7 @@ public class Parser { ...@@ -4492,7 +4493,7 @@ public class Parser {
command.setSelectivity(readExpression()); command.setSelectivity(readExpression());
return command; return command;
} else { } else {
Column newColumn = parseColumnForTable(columnName); Column newColumn = parseColumnForTable(columnName, column.isNullable());
AlterTableAlterColumn command = new AlterTableAlterColumn(session, table.getSchema()); AlterTableAlterColumn command = new AlterTableAlterColumn(session, table.getSchema());
command.setTable(table); command.setTable(table);
command.setType(AlterTableAlterColumn.CHANGE_TYPE); command.setType(AlterTableAlterColumn.CHANGE_TYPE);
...@@ -4511,7 +4512,7 @@ public class Parser { ...@@ -4511,7 +4512,7 @@ public class Parser {
command.setType(AlterTableAlterColumn.ADD); command.setType(AlterTableAlterColumn.ADD);
command.setTable(table); command.setTable(table);
String columnName = readColumnIdentifier(); String columnName = readColumnIdentifier();
Column column = parseColumnForTable(columnName); Column column = parseColumnForTable(columnName, true);
command.setNewColumn(column); command.setNewColumn(column);
if (readIf("BEFORE")) { if (readIf("BEFORE")) {
command.setAddBefore(readColumnIdentifier()); command.setAddBefore(readColumnIdentifier());
...@@ -4721,7 +4722,7 @@ public class Parser { ...@@ -4721,7 +4722,7 @@ public class Parser {
command.addConstraintCommand(c); command.addConstraintCommand(c);
} else { } else {
String columnName = readColumnIdentifier(); String columnName = readColumnIdentifier();
Column column = parseColumnForTable(columnName); Column column = parseColumnForTable(columnName, true);
if (column.isAutoIncrement() && column.isPrimaryKey()) { if (column.isAutoIncrement() && column.isPrimaryKey()) {
column.setPrimaryKey(false); column.setPrimaryKey(false);
IndexColumn[] cols = { new IndexColumn() }; IndexColumn[] cols = { new IndexColumn() };
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论