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

Fix getColumnClassName() for -Dh2.oldResultSetGetObject=false

上级 cb57df57
......@@ -178,7 +178,7 @@ public class JdbcParameterMetaData extends TraceObject implements
if (type == Value.UNKNOWN) {
type = Value.STRING;
}
return DataType.getTypeClassName(type);
return DataType.getTypeClassName(type, false);
} catch (Exception e) {
throw logAndConvert(e);
}
......
......@@ -371,7 +371,7 @@ public class JdbcResultSetMetaData extends TraceObject implements
debugCodeCall("getColumnClassName", column);
checkColumnIndex(column);
int type = result.getColumnType(--column);
return DataType.getTypeClassName(type);
return DataType.getTypeClassName(type, true);
} catch (Exception e) {
throw logAndConvert(e);
}
......
......@@ -2003,7 +2003,7 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData,
@Override
public String getColumnClassName(int columnIndex) throws SQLException {
int type = DataType.getValueTypeFromResultSet(this, columnIndex);
return DataType.getTypeClassName(type);
return DataType.getTypeClassName(type, true);
}
/**
......
......@@ -747,17 +747,26 @@ public class DataType {
* Get the name of the Java class for the given value type.
*
* @param type the value type
* @param forResultSet return mapping for result set
* @return the class name
*/
public static String getTypeClassName(int type) {
public static String getTypeClassName(int type, boolean forResultSet) {
switch (type) {
case Value.BOOLEAN:
// "java.lang.Boolean";
return Boolean.class.getName();
case Value.BYTE:
if (forResultSet && !SysProperties.OLD_RESULT_SET_GET_OBJECT) {
// "java.lang.Integer";
return Integer.class.getName();
}
// "java.lang.Byte";
return Byte.class.getName();
case Value.SHORT:
if (forResultSet && !SysProperties.OLD_RESULT_SET_GET_OBJECT) {
// "java.lang.Integer";
return Integer.class.getName();
}
// "java.lang.Short";
return Short.class.getName();
case Value.INT:
......
......@@ -35,6 +35,7 @@ import java.util.Objects;
import java.util.SimpleTimeZone;
import java.util.concurrent.TimeUnit;
import org.h2.engine.SysProperties;
import org.h2.jdbc.JdbcConnection;
import org.h2.message.DbException;
import org.h2.store.fs.FilePath;
......@@ -1028,7 +1029,8 @@ public abstract class TestBase {
break;
case Types.SMALLINT:
assertEquals("SMALLINT", typeName);
assertEquals("java.lang.Short", className);
assertEquals(SysProperties.OLD_RESULT_SET_GET_OBJECT ? "java.lang.Short" : "java.lang.Integer",
className);
break;
case Types.TIMESTAMP:
assertEquals("TIMESTAMP", typeName);
......
......@@ -22,6 +22,7 @@ import java.sql.Timestamp;
import java.sql.Types;
import org.h2.api.ErrorCode;
import org.h2.engine.SysProperties;
import org.h2.test.TestBase;
import org.h2.test.TestDb;
......@@ -305,7 +306,8 @@ public class TestUpdatableResultSet extends TestDb {
assertEquals("java.lang.String", meta.getColumnClassName(2));
assertEquals("java.math.BigDecimal", meta.getColumnClassName(3));
assertEquals("java.lang.Boolean", meta.getColumnClassName(4));
assertEquals("java.lang.Byte", meta.getColumnClassName(5));
assertEquals(SysProperties.OLD_RESULT_SET_GET_OBJECT ? "java.lang.Byte" : "java.lang.Integer",
meta.getColumnClassName(5));
assertEquals("[B", meta.getColumnClassName(6));
assertEquals("java.sql.Date", meta.getColumnClassName(7));
assertEquals("java.sql.Time", meta.getColumnClassName(8));
......@@ -314,7 +316,8 @@ public class TestUpdatableResultSet extends TestDb {
assertEquals("java.lang.Float", meta.getColumnClassName(11));
assertEquals("java.lang.Long", meta.getColumnClassName(12));
assertEquals("java.lang.Integer", meta.getColumnClassName(13));
assertEquals("java.lang.Short", meta.getColumnClassName(14));
assertEquals(SysProperties.OLD_RESULT_SET_GET_OBJECT ? "java.lang.Short" : "java.lang.Integer",
meta.getColumnClassName(14));
assertEquals("java.sql.Clob", meta.getColumnClassName(15));
assertEquals("java.sql.Blob", meta.getColumnClassName(16));
rs.moveToInsertRow();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论