diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/dtv.java b/src/main/java/com/microsoft/sqlserver/jdbc/dtv.java index 9c5c7f735..1d2882c4f 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/dtv.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/dtv.java @@ -4082,6 +4082,14 @@ private Object readSqlVariant(int intbaseType, int cbPropsActual, int valueLengt convertedValue = tdsReader.readDateTime2(expectedValueLength, typeInfo, cal, jdbcType); break; + case DATETIMEOFFSETN: + jdbcType = JDBCType.DATETIMEOFFSET; + scale = tdsReader.readUnsignedByte(); + typeInfo.setScale(scale); + internalVariant.setScale(scale); + convertedValue = tdsReader.readDateTimeOffset(expectedValueLength, typeInfo, jdbcType); + break; + case BIGBINARY: // e.g binary20, binary 512, binary 8000 -> reads as bigbinary case BIGVARBINARY: if (cbPropsActual != sqlVariantProbBytes.BIGBINARY.getIntValue()) { 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 ec60dc18e..214f67e21 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLVariantResultSetTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLVariantResultSetTest.java @@ -17,6 +17,7 @@ import java.sql.Statement; import java.util.Arrays; +import microsoft.sql.DateTimeOffset; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Tag; @@ -1026,22 +1027,18 @@ public void readVarcharInteger() throws SQLException { } /** - * Tests unsupported type + * Tests returning class of base type datetimeoffset in sql_variant is correct * * @throws SQLException */ @Test - public void testUnsupportedDatatype() throws SQLException { + public void testDateTimeOffsetAsSqlVariant() throws SQLException { try (Connection con = getConnection(); Statement stmt = con.createStatement(); SQLServerResultSet rs = (SQLServerResultSet) stmt.executeQuery( "select cast(cast('2017-08-16 17:31:09.995 +07:00' as datetimeoffset) as sql_variant)")) { rs.next(); - try { - rs.getObject(1); - fail(TestResource.getResource("R_expectedExceptionNotThrown")); - } catch (Exception e) { - assertTrue(e.getMessage().equalsIgnoreCase("Unexpected TDS type DATETIMEOFFSETN in SQL_VARIANT.")); - } + Object object = rs.getObject(1); + assertEquals(object.getClass(), DateTimeOffset.class); } }