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

Statement.getGeneratedKeys() returned the wrong value sometimes.

上级 68c89a0e
......@@ -20,7 +20,7 @@ import java.sql.Statement;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.UUID;
import org.h2.api.Trigger;
import org.h2.test.TestBase;
/**
......@@ -44,6 +44,7 @@ public class TestPreparedStatement extends TestBase {
deleteDb("preparedStatement");
Connection conn = getConnection("preparedStatement");
testUUID(conn);
testScopedGeneratedKey(conn);
testLobTempFiles(conn);
testExecuteErrorTwice(conn);
testTempView(conn);
......@@ -330,6 +331,37 @@ public class TestPreparedStatement extends TestBase {
stat.execute("DROP TABLE TEST_UUID");
}
/**
* A trigger that creates a sequence value.
*/
public static class SequenceTrigger implements Trigger {
public void fire(Connection conn, Object[] oldRow, Object[] newRow) throws SQLException {
conn.setAutoCommit(false);
conn.createStatement().execute("call next value for seq");
}
public void init(Connection conn, String schemaName, String triggerName, String tableName, boolean before,
int type) {
// ignore
}
}
private void testScopedGeneratedKey(Connection conn) throws SQLException {
Statement stat = conn.createStatement();
Trigger t = new SequenceTrigger();
stat.execute("create table test(id identity)");
stat.execute("create sequence seq start with 1000");
stat.execute("create trigger test_ins after insert on test call \"" + t.getClass().getName() + "\"");
stat.execute("insert into test values(null)");
ResultSet rs = stat.getGeneratedKeys();
rs.next();
assertEquals(1, rs.getLong(1));
stat.execute("drop sequence seq");
stat.execute("drop table test");
}
private void testSetObject(Connection conn) throws SQLException {
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(C CHAR(1))");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论