Enable verify data
Fix to enable data verification in Junit tests. Also addresses intermittent failures with Time/Timestamp where the precision was being inaccurately judged.
@@ -17,10 +17,7 @@ import java.math.BigDecimal;
import java.sql.JDBCType;
import java.sql.ResultSet;
import java.sql.SQLException;
-import java.sql.Time;
import java.sql.Timestamp;
-import java.time.LocalDateTime;
-import java.time.LocalTime;
import java.util.Arrays;
import java.util.Calendar;
import java.util.logging.Level;
@@ -212,8 +209,7 @@ public class DBResultSet extends AbstractParentWrapper implements AutoCloseable
Object retrieved = this.getXXX(ordinal + 1, coercion);
// Verify
- // TODO: Check the intermittent verification error
- // verifydata(ordinal, coercion, expectedData, retrieved);
+ verifydata(ordinal, coercion, expectedData, retrieved);
}
/**
@@ -268,7 +264,10 @@ public class DBResultSet extends AbstractParentWrapper implements AutoCloseable
break;
case java.sql.Types.REAL:
- assertTrue((((Float) expectedData).floatValue() == ((Float) retrieved).floatValue()),
+ if (expectedData instanceof Double) {
+ expectedData = (Float) (((Double) expectedData).floatValue());
+ }
+ assertTrue(((Float) expectedData).floatValue() == ((Float) retrieved).floatValue(),
"Unexpected real value, expected: " + (Float) expectedData + " received: " + (Float) retrieved);
break;
@@ -297,10 +296,14 @@ public class DBResultSet extends AbstractParentWrapper implements AutoCloseable
+ " ,received: " + (((Timestamp) retrieved).getTime()));
break;
}
- else
- assertTrue(("" + Timestamp.valueOf((LocalDateTime) expectedData)).equalsIgnoreCase("" + retrieved), "Unexpected datetime2 value, "
- + "expected: " + Timestamp.valueOf((LocalDateTime) expectedData) + " ,received: " + retrieved);
+ else {
+ String retrievedTimestamp = retrieved.toString();
+ String expectedTimestamp = expectedData.toString().substring(0,retrievedTimestamp.length());
+ assertTrue(expectedTimestamp.equalsIgnoreCase(retrievedTimestamp), "Unexpected datetime2 value, " + "expected: "
+ + expectedTimestamp + " ,received: " + retrievedTimestamp);
break;
+ }
+
case java.sql.Types.DATE:
assertTrue((("" + expectedData).equalsIgnoreCase("" + retrieved)),
@@ -308,8 +311,10 @@ public class DBResultSet extends AbstractParentWrapper implements AutoCloseable
break;
case java.sql.Types.TIME:
- assertTrue(("" + Time.valueOf((LocalTime) expectedData)).equalsIgnoreCase("" + retrieved),
- "Unexpected time value, exptected: " + Time.valueOf((LocalTime) expectedData) + " ,received: " + retrieved);
+ String retrievedTime = retrieved.toString();
+ String expectedTime = expectedData.toString().substring(0,retrievedTime.length());
+ assertTrue(expectedTime.equalsIgnoreCase(retrievedTime),
+ "Unexpected time value, expected: " + expectedTime + " ,received: " + retrievedTime);
break;
case microsoft.sql.Types.DATETIMEOFFSET:
@@ -446,7 +451,7 @@ public class DBResultSet extends AbstractParentWrapper implements AutoCloseable
cal = (Calendar) value;
}
else {
- ts = (java.sql.Timestamp) value;
+ ts = Timestamp.valueOf((String) value);
cal = Calendar.getInstance();
cal.setTimeInMillis(ts.getTime());
nanos = ts.getNanos();
