Skip to content

Commit

Permalink
GH2380
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffery-Wasty committed Apr 16, 2024
1 parent 9d64353 commit 1c8ea9e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.math.BigDecimal;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.sql.Connection;
import java.sql.Date;
import java.sql.ResultSet;
Expand Down Expand Up @@ -692,6 +693,14 @@ final boolean doExecute() throws SQLServerException {
}
}

if (copyOptions.isKeepIdentity()) {
//SQLServerBulkCSVFileRecord bulkRecord = new SQLServerBulkCSVFileRecord("",StandardCharsets.UTF_8.name(), "", false);
copyOptions.setKeepIdentity(false);
setBulkCopyOptions(copyOptions);
//ResultSet rs = statement.executeQuery("SET IDENTITY_INSERT dbo.TEST_IDENTITY_TABLE OFF;");
writeToServer();
}

// It is not a timeout exception. Re-throw.
throw topLevelException;
}
Expand Down
10 changes: 6 additions & 4 deletions src/test/java/com/microsoft/sqlserver/jdbc/issues/GH2380.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public static void main(String args[]) throws Exception {
SQLServerConnection conn = (SQLServerConnection)DriverManager.getConnection(connectionString);
try {
Path csvFile = Files.createTempFile("bulk_csv", ".csv");
Files.writeString(csvFile, "1, 2022/7/28 12:21:00.0000000", StandardCharsets.UTF_8);
Files.writeString(csvFile, "1, 2022/7/28 12:21:00.0000", StandardCharsets.UTF_8);
//Files.writeString(csvFile, "1, 2022/7/28 12:21:00", StandardCharsets.UTF_8);

SQLServerBulkCSVFileRecord bulkRecord = new SQLServerBulkCSVFileRecord(csvFile.toAbsolutePath().toString(),
StandardCharsets.UTF_8.name(), ",", false);
Expand All @@ -39,9 +40,10 @@ public static void main(String args[]) throws Exception {

} catch (IOException | SQLException e) {
e.printStackTrace();
Statement statement = conn.createStatement();
//statement.execute("SET IDENTITY_INSERT dbo.TEST_IDENTITY_TABLE OFF;");
statement.execute("SET IDENTITY_INSERT dbo.TEST_IDENTITY_TABLE2 ON;");
}

Statement statement = conn.createStatement();
//statement.execute("SET IDENTITY_INSERT dbo.TEST_IDENTITY_TABLE OFF;");
statement.execute("SET IDENTITY_INSERT dbo.TEST_IDENTITY_TABLE2 ON;");
}
}

0 comments on commit 1c8ea9e

Please sign in to comment.