Skip to content

correct processing of OffsetDateTime in SQLServerDataTable #2651

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

Closed
wants to merge 2 commits into from

Conversation

LeosBitto
Copy link
Contributor

When OffsetDateTime contains zero seconds, calling toString() produces the following format: 2025-04-26T19:42+02:00 (without seconds) which is rejected by the server with the message "Conversion failed when converting date and/or time from character string." (SQL Error: 241, SQLState: S0001)

@@ -275,8 +276,12 @@ private void internalAddrow(JDBCType jdbcType, Object val, Object[] rowValues,

// java.sql.Date, java.sql.Time and java.sql.Timestamp are subclass of java.util.Date
if (val instanceof java.util.Date || val instanceof microsoft.sql.DateTimeOffset
|| val instanceof OffsetDateTime || val instanceof OffsetTime)
|| val instanceof OffsetTime)
rowValues[key] = val.toString();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a unit test for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to ammend an existing unit test with OffsetDateTime and SQLServerDataTable, but I was not able to find any. Could you please point me?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you consider adding one in SQLServerDataTableTest.java ?

Copy link
Contributor Author

@LeosBitto LeosBitto Apr 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing, I will add a column of type TIMESTAMP_WITH_TIMEZONE there and fill it with OffsetDateTime - that's exactly what I do in my application where I have found this bug (and have solved it with this change to the JDBC driver).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@machavan is the unit test now OK, or is anything else needed before merge?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LeosBitto it looks fine. We will run our ADO tests on this PR and then move ahead for merging it.

@LeosBitto
Copy link
Contributor Author

@microsoft-github-policy-service agree

@muskan124947
Copy link
Contributor

@muskan124947
Copy link
Contributor

@LeosBitto, You can close this PR.
It has been merged as part of #2652

@muskan124947
Copy link
Contributor

Closing the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants