提交 f67093b9 authored 作者: noelgrandin's avatar noelgrandin

Support some more DDL syntax for MySQL, patch from Peter Jentsch.

上级 aab911e5
......@@ -5302,6 +5302,22 @@ public class Parser {
session, getSchema(), ifExists);
command.setConstraintName(constraintName);
return command;
} else if (readIf("FOREIGN")) {
// MySQL compatibility
read("KEY");
String constraintName = readIdentifierWithSchema(table
.getSchema().getName());
checkSchema(table.getSchema());
AlterTableDropConstraint command = new AlterTableDropConstraint(
session, getSchema(), false);
command.setConstraintName(constraintName);
return command;
} else if (readIf("INDEX")) {
// MySQL compatibility
String indexName = readIdentifierWithSchema();
DropIndex command = new DropIndex(session, getSchema());
command.setIndexName(indexName);
return command;
} else if (readIf("PRIMARY")) {
read("KEY");
Index idx = table.getPrimaryKey();
......@@ -5322,6 +5338,20 @@ public class Parser {
command.setOldColumn(table.getColumn(columnName));
return command;
}
} else if (readIf("CHANGE")) {
// MySQL compatibility
readIf("COLUMN");
String columnName = readColumnIdentifier();
Column column = table.getColumn(columnName);
String newColumnName = readColumnIdentifier();
// new column type ignored. RENAME and MODIFY are
// a single command in MySQL but two different commands in H2.
parseColumnForTable(newColumnName, column.isNullable());
AlterTableRenameColumn command = new AlterTableRenameColumn(session);
command.setTable(table);
command.setColumn(column);
command.setNewColumnName(newColumnName);
return command;
} else if (readIf("MODIFY")) {
// MySQL compatibility
readIf("COLUMN");
......
......@@ -828,6 +828,35 @@ create table test(id int primary key, name varchar);
alter table test alter column id int auto_increment;
> ok
create table othertest(id int primary key, name varchar);
> ok
alter table othertest add constraint fk foreign key(id) references test(id);
> ok
alter table othertest drop foreign key fk;
> ok
create unique index idx on othertest(name);
> ok
alter table othertest drop index idx;
> ok
drop table othertest;
> ok
insert into test(id) values(1);
> update count: 1
alter table test change column id id2 int;
> ok
select id2 from test;
> ID2
> ---
> 1
drop table test;
> ok
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论