提交 dacf564f authored 作者: Thomas Mueller's avatar Thomas Mueller

ALTER TABLE: removing an auto-increment or identity column didn't remove the sequence.

上级 94599e3c
......@@ -18,7 +18,8 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>Creating indexes is now a bit faster.
<ul><li>ALTER TABLE: removing an auto-increment or identity column didn't remove the sequence.
</li><li>Creating indexes is now a bit faster.
</li><li>PG Server: new system property h2.pgClientEncoding to explicitly set the encoding
for clients that don't send the encoding (the default encoding is UTF-8).
Thanks a lot to Sergi Vladykin for the patch!
......
......@@ -303,9 +303,9 @@ public class AlterTableAlterColumn extends SchemaCommand {
}
String tableName = table.getName();
table.setModified();
for (Column col : columns) {
// if we don't do that, the sequence is dropped when the table is
// dropped
// remove the sequences from the columns (except dropped columns)
// otherwise the sequence is dropped if the table is dropped
for (Column col : newColumns) {
Sequence seq = col.getSequence();
if (seq != null) {
table.removeSequence(session, seq);
......
......@@ -7,6 +7,7 @@
package org.h2.test.db;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
......@@ -35,10 +36,25 @@ public class TestAlter extends TestBase {
conn = getConnection("alter");
stat = conn.createStatement();
testAlterTableAlterColumn();
testAlterTableDropIdentityColumn();
conn.close();
deleteDb("alter");
}
private void testAlterTableDropIdentityColumn() throws SQLException {
stat.execute("create table test(id int auto_increment, name varchar)");
stat.execute("alter table test drop column id");
ResultSet rs = stat.executeQuery("select * from INFORMATION_SCHEMA.SEQUENCES");
assertFalse(rs.next());
stat.execute("drop table test");
stat.execute("create table test(id int auto_increment, name varchar)");
stat.execute("alter table test drop column name");
rs = stat.executeQuery("select * from INFORMATION_SCHEMA.SEQUENCES");
assertTrue(rs.next());
stat.execute("drop table test");
}
private void testAlterTableAlterColumn() throws SQLException {
stat.execute("create table t(x varchar) as select 'x'");
try {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论