diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/dtv.java b/src/main/java/com/microsoft/sqlserver/jdbc/dtv.java index 5030c22c9..f9d245dbf 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/dtv.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/dtv.java @@ -3104,7 +3104,7 @@ public void apply(TypeInfo typeInfo, */ public void apply(TypeInfo typeInfo, TDSReader tdsReader) throws SQLServerException { - typeInfo.ssLenType = SSLenType.LONGLENTYPE; //Variant type should be LONGLENTYPE length. + typeInfo.ssLenType = SSLenType.LONGLENTYPE; //sql_variant type should be LONGLENTYPE length. typeInfo.maxLength = tdsReader.readInt(); typeInfo.ssType = SSType.SQL_VARIANT; } @@ -4115,7 +4115,6 @@ else if (TDSType.NUMERICN == baseType) case MONEY4: jdbcType = JDBCType.SMALLMONEY; - typeInfo.setMaxLength(4); precision = Long.toString(Long.MAX_VALUE).length(); typeInfo.setPrecision(precision); scale = 4; @@ -4128,7 +4127,6 @@ else if (TDSType.NUMERICN == baseType) case MONEY8: jdbcType = JDBCType.MONEY; - typeInfo.setMaxLength(8); precision = Long.toString(Long.MAX_VALUE).length(); scale = 4; typeInfo.setPrecision(precision); @@ -4179,9 +4177,7 @@ else if (TDSType.BIGCHAR == baseType) jdbcType = JDBCType.CHAR; collation = tdsReader.readCollation(); typeInfo.setSQLCollation(collation); - typeInfo.setSSLenType(SSLenType.USHORTLENTYPE); maxLength = tdsReader.readUnsignedShort(); - typeInfo.setMaxLength(maxLength); if (maxLength > DataTypes.SHORT_VARTYPE_MAX_BYTES) tdsReader.throwInvalidTDS(); typeInfo.setDisplaySize(maxLength); @@ -4205,7 +4201,6 @@ else if (TDSType.NVARCHAR == baseType) jdbcType = JDBCType.NVARCHAR; collation = tdsReader.readCollation(); typeInfo.setSQLCollation(collation); - typeInfo.setSSLenType(SSLenType.USHORTLENTYPE); maxLength = tdsReader.readUnsignedShort(); if (maxLength > DataTypes.SHORT_VARTYPE_MAX_BYTES || 0 != maxLength % 2) tdsReader.throwInvalidTDS(); @@ -4272,7 +4267,6 @@ else if (TDSType.BIGVARBINARY == baseType) jdbcType = JDBCType.VARBINARY; maxLength = tdsReader.readUnsignedShort(); internalVariant.setMaxLength(maxLength); - typeInfo.setMaxLength(maxLength); if (maxLength > DataTypes.SHORT_VARTYPE_MAX_BYTES) tdsReader.throwInvalidTDS(); typeInfo.setDisplaySize(2 * maxLength); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLVariantResultSetTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLVariantResultSetTest.java index bf14063a2..dc076f9de 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLVariantResultSetTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLVariantResultSetTest.java @@ -803,6 +803,20 @@ public void readSeveralRows() throws SQLException { } } + + /** + * Test retrieving values with varchar and integer as basetype + * @throws SQLException + */ + @Test + public void readVarcharInteger() throws SQLException { + Object expected[] = {"abc", 42}; + int index = 0; + rs = (SQLServerResultSet) stmt.executeQuery("SELECT cast('abc' as sql_variant) UNION ALL SELECT cast(42 as sql_variant)"); + while (rs.next()) { + assertEquals(rs.getObject(1), expected[index++]); + } + } private boolean parseByte(byte[] expectedData, byte[] retrieved) {