-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support FLOAT data type for bulk copy operation using RowSet (#986)
Fix | Support FLOAT data type for bulk copy operation using RowSet (#986)
- Loading branch information
Showing
2 changed files
with
100 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyRowSetTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.microsoft.sqlserver.jdbc.bulkCopy; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
|
||
import javax.sql.RowSetMetaData; | ||
import javax.sql.rowset.CachedRowSet; | ||
import javax.sql.rowset.RowSetFactory; | ||
import javax.sql.rowset.RowSetMetaDataImpl; | ||
import javax.sql.rowset.RowSetProvider; | ||
|
||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.opentest4j.TestAbortedException; | ||
|
||
import com.microsoft.sqlserver.jdbc.RandomData; | ||
import com.microsoft.sqlserver.jdbc.RandomUtil; | ||
import com.microsoft.sqlserver.jdbc.SQLServerBulkCopy; | ||
import com.microsoft.sqlserver.jdbc.TestUtils; | ||
import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; | ||
import com.microsoft.sqlserver.testframework.AbstractTest; | ||
|
||
public class BulkCopyRowSetTest extends AbstractTest { | ||
|
||
private static String tableName = AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("BulkCopyFloatTest")); | ||
|
||
@Test | ||
public void testBulkCopyFloatRowSet() throws SQLException { | ||
try (Connection con = DriverManager.getConnection(connectionString); | ||
Statement stmt = connection.createStatement()) { | ||
RowSetFactory rsf = RowSetProvider.newFactory(); | ||
CachedRowSet crs = rsf.createCachedRowSet(); | ||
RowSetMetaData rsmd = new RowSetMetaDataImpl(); | ||
rsmd.setColumnCount(2); | ||
rsmd.setColumnName(1, "c1"); | ||
rsmd.setColumnName(2, "c2"); | ||
rsmd.setColumnType(1, java.sql.Types.FLOAT); | ||
rsmd.setColumnType(2, java.sql.Types.FLOAT); | ||
|
||
Float floatData = RandomData.generateReal(false); | ||
|
||
crs.setMetaData(rsmd); | ||
crs.moveToInsertRow(); | ||
crs.updateFloat(1, floatData); | ||
crs.updateFloat(2, floatData); | ||
crs.insertRow(); | ||
crs.moveToCurrentRow(); | ||
|
||
try (SQLServerBulkCopy bcOperation = new SQLServerBulkCopy(con)) { | ||
bcOperation.setDestinationTableName(tableName); | ||
bcOperation.writeToServer(crs); | ||
} | ||
|
||
ResultSet rs = stmt.executeQuery("select * from " + tableName); | ||
rs.next(); | ||
assertEquals(floatData, (Float) rs.getFloat(1)); | ||
assertEquals(floatData, (Float) rs.getFloat(2)); | ||
} | ||
} | ||
|
||
@BeforeAll | ||
public static void testSetup() throws TestAbortedException, Exception { | ||
try (Connection connection = DriverManager.getConnection(connectionString); | ||
Statement stmt = connection.createStatement()) { | ||
String sql1 = "create table " + tableName + " (c1 float, c2 real)"; | ||
stmt.execute(sql1); | ||
} | ||
} | ||
|
||
@AfterAll | ||
public static void terminateVariation() throws SQLException { | ||
try (Connection connection = DriverManager.getConnection(connectionString); | ||
Statement stmt = connection.createStatement()) { | ||
TestUtils.dropTableIfExists(tableName, stmt); | ||
} | ||
} | ||
} |