提交 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 ...@@ -18,7 +18,8 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <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. It also works now with quoted spaces in the argument list.
Thanks a lot to Shimizu Fumiyuki for the patch! Thanks a lot to Shimizu Fumiyuki for the patch!
</li><li>If the transaction log could not be truncated because of an uncommitted transaction, </li><li>If the transaction log could not be truncated because of an uncommitted transaction,
......
...@@ -349,8 +349,11 @@ public class Session extends SessionWithState { ...@@ -349,8 +349,11 @@ public class Session extends SessionWithState {
} }
public void setAutoCommit(boolean b) { public void setAutoCommit(boolean b) {
if (autoCommit != b) {
commit(false);
autoCommit = b; autoCommit = b;
} }
}
public int getLockTimeout() { public int getLockTimeout() {
return lockTimeout; return lockTimeout;
......
...@@ -36,6 +36,7 @@ public class TestTransaction extends TestBase { ...@@ -36,6 +36,7 @@ public class TestTransaction extends TestBase {
} }
public void test() throws SQLException { public void test() throws SQLException {
testCommitOnAutoCommitChange();
testConcurrentSelectForUpdate(); testConcurrentSelectForUpdate();
testLogMode(); testLogMode();
testRollback(); testRollback();
...@@ -48,6 +49,36 @@ public class TestTransaction extends TestBase { ...@@ -48,6 +49,36 @@ public class TestTransaction extends TestBase {
deleteDb("transaction"); 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 { private void testLogMode() throws SQLException {
if (config.memory) { if (config.memory) {
return; return;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论