Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,15 @@ 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) {
long longVal = ThreadLocalRandom.current().nextLong(((Double) minvalue).longValue(),
((Double) maxvalue).longValue());
if (Double.isNaN(Double.longBitsToDouble(longVal))) {
// Try again!
return createdata();
} else
return Double.longBitsToDouble(longVal);
} else {
return ThreadLocalRandom.current().nextDouble((Float) SqlTypeValue.REAL.minValue,
(Float) SqlTypeValue.REAL.maxValue);
}
Expand Down