Skip to content

Commit

Permalink
Fix | Fix random issues for SQLFloat type and improved TVPAllTypesTes…
Browse files Browse the repository at this point in the history
…t for possible errors. (#888)
  • Loading branch information
cheenamalhotra authored and ulvii committed Nov 30, 2018
1 parent f041460 commit 7b1ca05
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
28 changes: 15 additions & 13 deletions src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPAllTypesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ private void testTVPResultSet(boolean setSelectMethod, Integer resultSetType,
} catch (Exception e) {
fail(TestResource.getResource("R_unexpectedErrorMessage") + e.toString());
} finally {
terminateVariation(stmt);
stmt.close();
}
} finally {
stmt.close();
terminateVariation();
}
}

Expand Down Expand Up @@ -133,10 +133,10 @@ private void testTVPStoredProcedureResultSet(boolean setSelectMethod, Integer re
ComparisonUtil.compareSrcTableAndDestTableIgnoreRowOrder(new DBConnection(connectionString), tableSrc,
tableDest);
} finally {
terminateVariation(stmt);
stmt.close();
}
} finally {
stmt.close();
terminateVariation();
}
}

Expand Down Expand Up @@ -169,13 +169,13 @@ public void testTVPDataTable() throws SQLException {
.prepareStatement("INSERT INTO " + tableDest.getEscapedTableName() + " select * from ? ;")) {
pstmt.setStructured(1, tvpName, dt);
pstmt.execute();
} finally {
terminateVariation(stmt);
}
} finally {
terminateVariation();
}
}

private static void createPreocedure(String procedureName, String destTable, Statement stmt) throws SQLException {
private static void createProcedure(String procedureName, String destTable, Statement stmt) throws SQLException {
String sql = "CREATE PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(procedureName) + " @InputData "
+ AbstractSQLGenerator.escapeIdentifier(tvpName) + " READONLY " + " AS " + " BEGIN " + " INSERT INTO "
+ destTable + " SELECT * FROM @InputData" + " END";
Expand Down Expand Up @@ -207,16 +207,18 @@ private void setupVariation(boolean setSelectMethod, Statement stmt) throws SQLE
dbStmt.createTable(tableDest);

createTVPS(tvpName, tableSrc.getDefinitionOfColumns(), stmt);
createPreocedure(procedureName, tableDest.getEscapedTableName(), stmt);
createProcedure(procedureName, tableDest.getEscapedTableName(), stmt);

dbStmt.populateTable(tableSrc);
}
}

private void terminateVariation(Statement stmt) throws SQLException {
TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(procedureName), stmt);
TestUtils.dropTableIfExists(tableSrc.getEscapedTableName(), stmt);
TestUtils.dropTableIfExists(tableDest.getEscapedTableName(), stmt);
TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tvpName), stmt);
private void terminateVariation() throws SQLException {
try (Connection conn = DriverManager.getConnection(connectionString); Statement stmt = conn.createStatement()) {
TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(procedureName), stmt);
TestUtils.dropTableIfExists(tableSrc.getEscapedTableName(), stmt);
TestUtils.dropTableIfExists(tableDest.getEscapedTableName(), stmt);
TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tvpName), stmt);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ public SqlFloat() {
public Object createdata() {
// for float in SQL Server, any precision <=24 is considered as real so the value must be within
// SqlTypeValue.REAL.minValue/maxValue
if (precision > 24)
return Double.longBitsToDouble(ThreadLocalRandom.current().nextLong(((Double) minvalue).longValue(),
((Double) maxvalue).longValue()));
else {
if (precision > 24) {
return ThreadLocalRandom.current().nextDouble(((Double) minvalue), ((Double) maxvalue));
} else {
return ThreadLocalRandom.current().nextDouble((Float) SqlTypeValue.REAL.minValue,
(Float) SqlTypeValue.REAL.maxValue);
}
Expand Down

0 comments on commit 7b1ca05

Please sign in to comment.