提交 fb37cc7c authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Implement JdbcResultSet.updateArray(*)

上级 299f82eb
...@@ -2489,19 +2489,57 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS ...@@ -2489,19 +2489,57 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS
} }
/** /**
* [Not supported] * Updates a column in the current or insert row.
*
* @param columnIndex (1,2,...)
* @param x the value
* @param length the length
* @throws SQLException if the result set is closed or not updatable
*/ */
@Override @Override
public void updateArray(int columnIndex, Array x) throws SQLException { public void updateArray(int columnIndex, Array x) throws SQLException {
throw unsupported("setArray"); try {
if (isDebugEnabled()) {
debugCode("updateArray(" + columnIndex + ", x);");
}
checkClosed();
Value v;
if (x == null) {
v = ValueNull.INSTANCE;
} else {
v = DataType.convertToValue(stat.session, x.getArray(), Value.ARRAY);
}
update(columnIndex, v);
} catch (Exception e) {
throw logAndConvert(e);
}
} }
/** /**
* [Not supported] * Updates a column in the current or insert row.
*
* @param columnLabel the column label
* @param x the value
* @param length the length
* @throws SQLException if the result set is closed or not updatable
*/ */
@Override @Override
public void updateArray(String columnLabel, Array x) throws SQLException { public void updateArray(String columnLabel, Array x) throws SQLException {
throw unsupported("setArray"); try {
if (isDebugEnabled()) {
debugCode("updateArray(" + quote(columnLabel) + ", x);");
}
checkClosed();
Value v;
if (x == null) {
v = ValueNull.INSTANCE;
} else {
v = DataType.convertToValue(stat.session, x.getArray(), Value.ARRAY);
}
update(columnLabel, v);
} catch (Exception e) {
throw logAndConvert(e);
}
} }
/** /**
......
...@@ -7,6 +7,7 @@ package org.h2.value; ...@@ -7,6 +7,7 @@ package org.h2.value;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Arrays; import java.util.Arrays;
import org.h2.engine.Constants; import org.h2.engine.Constants;
...@@ -135,8 +136,8 @@ public class ValueArray extends Value { ...@@ -135,8 +136,8 @@ public class ValueArray extends Value {
} }
@Override @Override
public void set(PreparedStatement prep, int parameterIndex) { public void set(PreparedStatement prep, int parameterIndex) throws SQLException {
throw throwUnsupportedExceptionForType("PreparedStatement.set"); prep.setArray(parameterIndex, prep.getConnection().createArrayOf("NULL", (Object[]) getObject()));
} }
@Override @Override
......
...@@ -165,10 +165,6 @@ public class TestResultSet extends TestDb { ...@@ -165,10 +165,6 @@ public class TestResultSet extends TestDb {
updateRef(1, (Ref) null); updateRef(1, (Ref) null);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs). assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).
updateRef("x", (Ref) null); updateRef("x", (Ref) null);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).
updateArray(1, (Array) null);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).
updateArray("x", (Array) null);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs). assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).
updateRowId(1, (RowId) null); updateRowId(1, (RowId) null);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs). assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).
...@@ -1807,6 +1803,35 @@ public class TestResultSet extends TestDb { ...@@ -1807,6 +1803,35 @@ public class TestResultSet extends TestDb {
assertThrows(ErrorCode.OBJECT_CLOSED, array).getResultSet(); assertThrows(ErrorCode.OBJECT_CLOSED, array).getResultSet();
assertFalse(rs.next()); assertFalse(rs.next());
try (Statement s = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE)) {
rs = s.executeQuery("SELECT * FROM TEST ORDER BY ID");
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
rs.updateArray(2, conn.createArrayOf("INT", new Object[] {10, 20}));
rs.updateRow();
assertTrue(rs.next());
rs.updateArray("VALUE", conn.createArrayOf("INT", new Object[] {11, 22}));
rs.updateRow();
assertFalse(rs.next());
rs.moveToInsertRow();
rs.updateInt(1, 3);
rs.updateArray(2, null);
rs.insertRow();
}
rs = stat.executeQuery("SELECT * FROM TEST ORDER BY ID");
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
assertEquals(new Object[] {10, 20}, (Object[]) rs.getObject(2));
assertTrue(rs.next());
assertEquals(2, rs.getInt(1));
assertEquals(new Object[] {11, 22}, (Object[]) rs.getObject(2));
assertTrue(rs.next());
assertEquals(3, rs.getInt(1));
assertNull(rs.getObject(2));
assertFalse(rs.next());
stat.execute("DROP TABLE TEST"); stat.execute("DROP TABLE TEST");
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论