提交 30b11955 authored 作者: Thomas Mueller's avatar Thomas Mueller

Updateable result sets: if the value is not set when inserting a new row, the…

Updateable result sets: if the value is not set when inserting a new row, the default value is now used (the same behavior as MySQL, PostgreSQL, and Apache Derby) instead of NULL.
上级 83ffe3f8
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- <!--
Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License, Version 1.0, Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License, Version 1.0,
...@@ -18,7 +19,12 @@ Change Log ...@@ -18,7 +19,12 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>Issue 347: the RunScript and Shell tools now ignore empty statements. <ul><li>Updateable result sets: if the value is not set when inserting a new row,
the default value is now used (the same behavior as MySQL, PostgreSQL, and Apache Derby)
instead of NULL.
</li><li>Conditions of the form IN(SELECT ...) where slow and increased the database size
if the subquery result size was larger then the configured MAX_MEMORY_ROWS.
</li><li>Issue 347: the RunScript and Shell tools now ignore empty statements.
</li><li>Issue 246: improved error message for data conversion problems. </li><li>Issue 246: improved error message for data conversion problems.
</li><li>Issue 344: the build now supports a custom Maven repository location. </li><li>Issue 344: the build now supports a custom Maven repository location.
</li><li>Issue 334: Java functions that return CLOB or BLOB objects could not be used as tables. </li><li>Issue 334: Java functions that return CLOB or BLOB objects could not be used as tables.
......
...@@ -304,16 +304,20 @@ public class UpdatableRow { ...@@ -304,16 +304,20 @@ public class UpdatableRow {
buff.resetCount(); buff.resetCount();
for (int i = 0; i < columnCount; i++) { for (int i = 0; i < columnCount; i++) {
buff.appendExceptFirst(","); buff.appendExceptFirst(",");
buff.append('?'); Value v = row[i];
if (v == null) {
buff.append("DEFAULT");
} else {
buff.append('?');
}
} }
buff.append(')'); buff.append(')');
PreparedStatement prep = conn.prepareStatement(buff.toString()); PreparedStatement prep = conn.prepareStatement(buff.toString());
for (int i = 0; i < columnCount; i++) { for (int i = 0, j = 0; i < columnCount; i++) {
Value v = row[i]; Value v = row[i];
if (v == null) { if (v != null) {
v = ValueNull.INSTANCE; v.set(prep, j++ + 1);
} }
v.set(prep, i + 1);
} }
int count = prep.executeUpdate(); int count = prep.executeUpdate();
if (count != 1) { if (count != 1) {
......
...@@ -55,6 +55,7 @@ public class TestResultSet extends TestBase { ...@@ -55,6 +55,7 @@ public class TestResultSet extends TestBase {
stat = conn.createStatement(); stat = conn.createStatement();
testInsertRowWithUpdateableResultSetDefault();
testBeforeFirstAfterLast(); testBeforeFirstAfterLast();
testParseSpecialValues(); testParseSpecialValues();
testSpecialLocale(); testSpecialLocale();
...@@ -90,6 +91,21 @@ public class TestResultSet extends TestBase { ...@@ -90,6 +91,21 @@ public class TestResultSet extends TestBase {
} }
private void testInsertRowWithUpdateableResultSetDefault() throws SQLException {
stat.execute("create table test(id int primary key, data varchar(255) default 'Hello')");
PreparedStatement prep = conn.prepareStatement("select * from test",
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = prep.executeQuery();
rs.moveToInsertRow();
rs.updateInt(1, 1);
rs.insertRow();
rs.close();
rs = stat.executeQuery("select * from test");
assertTrue(rs.next());
assertEquals("Hello", rs.getString(2));
stat.execute("drop table test");
}
private void testBeforeFirstAfterLast() throws SQLException { private void testBeforeFirstAfterLast() throws SQLException {
stat.executeUpdate("create table test(id int)"); stat.executeUpdate("create table test(id int)");
stat.executeUpdate("insert into test values(1)"); stat.executeUpdate("insert into test values(1)");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论