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