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

Updatable result sets: the key columns can now be updated.

上级 789b03b1
......@@ -2827,7 +2827,10 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
checkOnValidRow();
if (updateRow != null) {
UpdatableRow row = getUpdatableRow();
Value[] current = result.currentRow();
Value[] current = new Value[columnCount];
for (int i = 0; i < updateRow.length; i++) {
current[i] = get(i + 1);
}
row.updateRow(current, updateRow);
for (int i = 0; i < updateRow.length; i++) {
if (updateRow[i] == null) {
......
......@@ -55,6 +55,7 @@ public class TestResultSet extends TestBase {
testAbsolute();
testFetchSize();
testOwnUpdates();
testUpdatePrimaryKey();
testFindColumn();
testSubstringPrecision();
testColumnLength();
......@@ -130,6 +131,20 @@ public class TestResultSet extends TestBase {
stat.execute("DROP TABLE TEST");
}
private void testUpdatePrimaryKey() throws SQLException {
Statement stat = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))");
stat.execute("INSERT INTO TEST VALUES(1, 'Hello')");
ResultSet rs = stat.executeQuery("SELECT * FROM TEST");
rs.next();
rs.updateInt(1, 2);
rs.updateRow();
rs.updateInt(1, 3);
rs.updateRow();
stat.execute("DROP TABLE TEST");
}
private void checkPrecision(int expected, String sql) throws SQLException {
ResultSetMetaData meta = stat.executeQuery(sql).getMetaData();
assertEquals(expected, meta.getPrecision(1));
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论