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

There was a bug in DataType.convertToValue when reading a ResultSet from a ResultSet.

上级 7c1c0f36
......@@ -20,7 +20,8 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>Pull request #116: Improved concurrency in the trace system.
<ul><li>There was a bug in DataType.convertToValue when reading a ResultSet from a ResultSet.
</li><li>Pull request #116: Improved concurrency in the trace system.
</li><li>Issue 609: the spatial index did not support NULL.
</li><li>Granting a schema is now supported.
</li><li>Linked tables did not work when a function-based index is present (Oracle).
......
......@@ -595,8 +595,9 @@ public class DataType {
}
case Value.CLOB: {
if (session == null) {
v = ValueLobDb.createSmallLob(
Value.CLOB, rs.getString(columnIndex).getBytes(Constants.UTF8));
String s = rs.getString(columnIndex);
v = s == null ? ValueNull.INSTANCE :
ValueLobDb.createSmallLob(Value.CLOB, s.getBytes(Constants.UTF8));
} else {
Reader in = rs.getCharacterStream(columnIndex);
if (in == null) {
......@@ -610,13 +611,13 @@ public class DataType {
}
case Value.BLOB: {
if (session == null) {
v = ValueLobDb.createSmallLob(
Value.BLOB, rs.getBytes(columnIndex));
} else {
InputStream in = rs.getBinaryStream(columnIndex);
v = (in == null) ? (Value) ValueNull.INSTANCE :
session.getDataHandler().getLobStorage().createBlob(in, -1);
byte[] buff = rs.getBytes(columnIndex);
return buff == null ? ValueNull.INSTANCE :
ValueLobDb.createSmallLob(Value.BLOB, buff);
}
InputStream in = rs.getBinaryStream(columnIndex);
v = (in == null) ? (Value) ValueNull.INSTANCE :
session.getDataHandler().getLobStorage().createBlob(in, -1);
break;
}
case Value.JAVA_OBJECT: {
......@@ -653,7 +654,7 @@ public class DataType {
if (x == null) {
return ValueNull.INSTANCE;
}
return ValueResultSet.get(rs);
return ValueResultSet.get(x);
}
case Value.GEOMETRY: {
Object x = rs.getObject(columnIndex);
......
......@@ -27,6 +27,7 @@ import org.h2.value.ValueDecimal;
import org.h2.value.ValueDouble;
import org.h2.value.ValueFloat;
import org.h2.value.ValueLobDb;
import org.h2.value.ValueNull;
import org.h2.value.ValueResultSet;
import org.h2.value.ValueString;
import org.h2.value.ValueUuid;
......@@ -47,6 +48,7 @@ public class TestValue extends TestBase {
@Override
public void test() throws SQLException {
testResultSetOperations();
testCastTrim();
testValueResultSet();
testDataType();
......@@ -58,6 +60,55 @@ public class TestValue extends TestBase {
testModulusOperator();
}
private void testResultSetOperations() throws SQLException {
SimpleResultSet rs = new SimpleResultSet();
rs.setAutoClose(false);
rs.addColumn("X", Types.INTEGER, 10, 0);
rs.addRow(new Object[]{null});
rs.next();
for (int type = Value.NULL; type < Value.TYPE_COUNT; type++) {
Value v = DataType.readValue(null, rs, 1, type);
assertTrue(v == ValueNull.INSTANCE);
}
testResultSetOperation(new byte[0]);
testResultSetOperation(1);
testResultSetOperation(Boolean.TRUE);
testResultSetOperation((byte) 1);
testResultSetOperation((short) 2);
testResultSetOperation((long) 3);
testResultSetOperation(4.0f);
testResultSetOperation(5.0d);
testResultSetOperation(new Date(6));
testResultSetOperation(new Time(7));
testResultSetOperation(new Timestamp(8));
testResultSetOperation(new BigDecimal("9"));
SimpleResultSet rs2 = new SimpleResultSet();
rs2.setAutoClose(false);
rs2.addColumn("X", Types.INTEGER, 10, 0);
rs2.addRow(new Object[]{1});
rs2.next();
testResultSetOperation(rs2);
}
private void testResultSetOperation(Object obj) throws SQLException {
SimpleResultSet rs = new SimpleResultSet();
rs.setAutoClose(false);
int valueType = DataType.getTypeFromClass(obj.getClass());
int sqlType = DataType.convertTypeToSQLType(valueType);
rs.addColumn("X", sqlType, 10, 0);
rs.addRow(new Object[]{obj});
rs.next();
Value v = DataType.readValue(null, rs, 1, valueType);
Value v2 = DataType.convertToValue(null, obj, valueType);
if (v.getType() == Value.RESULT_SET) {
assertEquals(v.toString(), v2.toString());
} else {
assertTrue(v.equals(v2));
}
}
private void testCastTrim() {
Value v;
String spaces = new String(new char[100]).replace((char) 0, ' ');
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论