added test for the fix.
@@ -9,6 +9,7 @@ package com.microsoft.sqlserver.jdbc.datatypes;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.IOException;
import java.math.BigDecimal;
@@ -804,6 +805,42 @@ public class SQLVariantResultSetTest extends AbstractTest {
}
+ /**
+ * Tests unsupported type
+ *
+ * @throws SQLException
+ */
+ @Test
+ public void testUnsupportedDatatype() throws SQLException {
+ 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("Should have thrown unssuported tds type exception");
+ }
+ catch (Exception e) {
+ assertTrue(e.getMessage().equalsIgnoreCase("Unexpected TDS type DATETIMEOFFSETN in SQL_VARIANT."));
+ }
+ if (null != rs) {
+ rs.close();
+ }
+ }
+
+ /**
+ * Tests that the returning class of base type time in sql_variant is correct.
+ *
+ * @throws SQLException
+ *
+ */
+ @Test
+ public void testTimeClassAsSqlVariant() throws SQLException {
+ rs = (SQLServerResultSet) stmt.executeQuery("select cast(cast('17:31:09.995' as time(3)) as sql_variant)");
+ rs.next();
+ Object object = rs.getObject(1);
+ assertEquals(object.getClass(), java.sql.Time.class);
+ ;
+ }
+
private boolean parseByte(byte[] expectedData,
byte[] retrieved) {
assertTrue(Arrays.equals(expectedData, Arrays.copyOf(retrieved, expectedData.length)), " unexpected BINARY value, expected");
