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

When enabling autocommit, the transaction is now committed (as required by the JDBC API).

上级 2084943f
......@@ -18,7 +18,8 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>The shell script <code>h2.sh</code> did not work with spaces in the path.
<ul><li>When enabling autocommit, the transaction is now committed (as required by the JDBC API).
</li><li>The shell script <code>h2.sh</code> did not work with spaces in the path.
It also works now with quoted spaces in the argument list.
Thanks a lot to Shimizu Fumiyuki for the patch!
</li><li>If the transaction log could not be truncated because of an uncommitted transaction,
......
......@@ -349,7 +349,10 @@ public class Session extends SessionWithState {
}
public void setAutoCommit(boolean b) {
autoCommit = b;
if (autoCommit != b) {
commit(false);
autoCommit = b;
}
}
public int getLockTimeout() {
......
......@@ -36,6 +36,7 @@ public class TestTransaction extends TestBase {
}
public void test() throws SQLException {
testCommitOnAutoCommitChange();
testConcurrentSelectForUpdate();
testLogMode();
testRollback();
......@@ -48,6 +49,36 @@ public class TestTransaction extends TestBase {
deleteDb("transaction");
}
private void testCommitOnAutoCommitChange() throws SQLException {
deleteDb("transaction");
Connection conn = getConnection("transaction");
Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key)");
Connection conn2 = getConnection("transaction");
Statement stat2 = conn2.createStatement();
conn.setAutoCommit(false);
stat.execute("insert into test values(1)");
// should have no effect
conn.setAutoCommit(false);
assertThrows(ErrorCode.LOCK_TIMEOUT_1, stat2).
executeQuery("select count(*) from test");
// should commit
conn.setAutoCommit(true);
ResultSet rs = stat2.executeQuery("select * from test");
assertTrue(rs.next());
stat.execute("drop table test");
conn2.close();
conn.close();
}
private void testLogMode() throws SQLException {
if (config.memory) {
return;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论