-
Notifications
You must be signed in to change notification settings - Fork 426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apply timezone to Timestamp when using bulkcopy for batch insert #2291
Conversation
c79b068
to
0861bc5
Compare
Hi @tkyc I appreciate you making the changes. I observed that the fix had the following problems:
May I ask if the changes need to be done at SQLServerBulkCopy ? |
@PriyadharshiniP Thanks for the feedback. I'll do more investigating and I'll look into correcting the implementation.
That was my initial thought also, but when I looked over SQLServerBulkCopy it doesn't look like I'm able to apply the timezone in the TDS request for bulkcopy. For example, I sort of expected code like this in SQLServerBulkCopy, which is part of the normal and regular batch insert code path. The code below takes into consideration the the timezone by sending the timezone info in the TDS request. So the timezone is applied during insertion by the server:
But I'm guessing because we're doing a bulkcopy, it has to send the timestamp value as is. And so, either the user or driver needs to apply the timezone conversion beforehand. |
src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecutionTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecutionTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecutionTest.java
Show resolved
Hide resolved
src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecutionTest.java
Show resolved
Hide resolved
src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecutionTest.java
Outdated
Show resolved
Hide resolved
src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java
Outdated
Show resolved
Hide resolved
src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java
Outdated
Show resolved
Hide resolved
Thanks for fixing the issue.
This time "GMT: Sunday, October 1, 2023 2:30:00 AM" doesn't exist in my local time zone. The non bulk version correctly inserts the date as
Could you see if we can accomplish something along these lines? |
@PriyadharshiniP Thanks for collaborating.
Yeah, I struggled with getting that working as well when I initially looked at the code. In
In the above call path, I expected to end up somewhere where the timestamp value is written to the TDS request (something/somewhere where the logic
Thanks for the help on testing. I'll see what I can do here... |
@PriyadharshiniP What's your exact local time zone? I've switched my PC's time zone setting to various different time zones that doesn't have day light savings and wasn't able to repro the issue with Maybe I need to do something like below explicitly to repro your issue?
|
My local timezone is Australia/Sydney
…On Wed, 17 Jan 2024, 8:11 am Terry Chow, ***@***.***> wrote:
@PriyadharshiniP <https://github.com/PriyadharshiniP> What's your exact
local time zone? I've switched my PC's time zone setting to various
different time zones that doesn't have day light savings and wasn't able to
repro the issue. I double checked the local time zone used in my JDK and it
matches my PC time zone.
—
Reply to this email directly, view it on GitHub
<#2291 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABXI4WXKWWK5KQJQM6BSDXLYO3UHDAVCNFSM6AAAAABBVM2HUSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOJUGUYTQOBUGY>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I guess you could do something like this in your unit test : |
@PriyadharshiniP I've just pushed a new fix implementation. I did some testing of it and it seem to have addressed all your concerns so far. Let me know if there's any additional problems. Thanks again for the collab. |
src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java
Outdated
Show resolved
Hide resolved
src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecutionTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecutionTest.java
Outdated
Show resolved
Hide resolved
Hi @tkyc |
3fcb1e0
to
d162dcc
Compare
@PriyadharshiniP Oops, my mistake. Calling valueOf will cause a conversion. Fixed. |
Thanks @tkyc : Regards |
@PriyadharshiniP this will make it in the release that's on the 31st of this month. |
Correctly applies the timezone to Timestamps when inserted using batch insert with bulkcopy.
Fixes #2271