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

The data type JAVA_OBJECT could not be used in updatable result sets.

上级 9a2a9124
......@@ -6,7 +6,12 @@
*/
package org.h2.value;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
import org.h2.constant.SysProperties;
import org.h2.util.ObjectUtils;
/**
* Implementation of the OBJECT data type.
......@@ -40,5 +45,10 @@ public class ValueJavaObject extends ValueBytesBase {
public int getType() {
return Value.JAVA_OBJECT;
}
public void set(PreparedStatement prep, int parameterIndex) throws SQLException {
Object obj = ObjectUtils.deserialize(getBytesNoCopy());
prep.setObject(parameterIndex, obj, Types.JAVA_OBJECT);
}
}
......@@ -18,6 +18,7 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types;
import org.h2.test.TestBase;
......@@ -27,12 +28,40 @@ import org.h2.test.TestBase;
public class TestUpdatableResultSet extends TestBase {
public void test() throws Exception {
testUpdateLob();
testScroll();
testUpdateDeleteInsert();
testUpdateDataType();
testUpdateResetRead();
}
private void testUpdateLob() throws Exception {
deleteDb("updatableResultSet");
Connection conn = getConnection("updatableResultSet");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE object_index (id integer primary key, object other, number integer)");
PreparedStatement prep = conn.prepareStatement("INSERT INTO object_index (id,object) VALUES (1,?)");
prep.setObject(1, "hello", Types.JAVA_OBJECT);
prep.execute();
ResultSet rs = stat.executeQuery("SELECT object,id,number FROM object_index WHERE id =1");
rs.next();
assertEquals("hello", rs.getObject(1).toString());
stat = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
rs = stat.executeQuery("SELECT object,id,number FROM object_index WHERE id =1");
rs.next();
assertEquals("hello", rs.getObject(1).toString());
rs.updateInt(2, 1);
rs.updateRow();
rs.close();
stat = conn.createStatement();
rs = stat.executeQuery("SELECT object,id,number FROM object_index WHERE id =1");
rs.next();
assertEquals("hello", rs.getObject(1).toString());
conn.close();
}
private void testUpdateResetRead() throws Exception {
deleteDb("updatableResultSet");
Connection conn = getConnection("updatableResultSet");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论