提交 b8bbe7c1 authored 作者: Noel Grandin's avatar Noel Grandin

#570: MySQL compatibility for ALTER TABLE .. DROP INDEX

上级 949f3afc
......@@ -21,6 +21,8 @@ Change Log
<h2>Next Version (unreleased)</h2>
<ul>
<li>Issue #570: MySQL compatibility for ALTER TABLE .. DROP INDEX
</li>
<li>Issue #537: Include the COLUMN name in message "Numeric value out of range"
</li>
<li>Issue #600: ROW_NUMBER() behaviour change in H2 1.4.195
......
......@@ -64,6 +64,7 @@ import org.h2.command.ddl.DropUserDataType;
import org.h2.command.ddl.DropView;
import org.h2.command.ddl.GrantRevoke;
import org.h2.command.ddl.PrepareProcedure;
import org.h2.command.ddl.SchemaCommand;
import org.h2.command.ddl.SetComment;
import org.h2.command.ddl.TruncateTable;
import org.h2.command.dml.AlterSequence;
......@@ -5791,9 +5792,18 @@ public class Parser {
return commandIfTableExists(schema, tableName, ifTableExists, command);
} else if (readIf("INDEX")) {
// MySQL compatibility
String indexName = readIdentifierWithSchema();
DropIndex command = new DropIndex(session, getSchema());
command.setIndexName(indexName);
String indexOrConstraintName = readIdentifierWithSchema();
final SchemaCommand command;
if (schema.findIndex(session, indexOrConstraintName) != null) {
DropIndex dropIndexCommand = new DropIndex(session, getSchema());
dropIndexCommand.setIndexName(indexOrConstraintName);
command = dropIndexCommand;
} else {
AlterTableDropConstraint dropCommand = new AlterTableDropConstraint(
session, getSchema(), false/*ifExists*/);
dropCommand.setConstraintName(indexOrConstraintName);
command = dropCommand;
}
return commandIfTableExists(schema, tableName, ifTableExists, command);
} else if (readIf("PRIMARY")) {
read("KEY");
......
......@@ -395,6 +395,10 @@ public class TestCompatibility extends TestBase {
stat.execute("CREATE TABLE TEST2(ID INT) ROW_FORMAT=DYNAMIC");
// check the MySQL index dropping syntax
stat.execute("ALTER TABLE TEST_COMMENT_ENGINE ADD CONSTRAINT CommentUnique UNIQUE (SOME_ITEM_ID)");
stat.execute("ALTER TABLE TEST_COMMENT_ENGINE DROP INDEX CommentUnique");
conn.close();
conn = getConnection("compatibility");
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论