Skip to content

Fix issue with cast exception from sql_variant#1320

Merged
peterbae merged 8 commits intomicrosoft:devfrom
peterbae:github-1302
May 12, 2020
Merged

Fix issue with cast exception from sql_variant#1320
peterbae merged 8 commits intomicrosoft:devfrom
peterbae:github-1302

Conversation

@peterbae
Copy link
Copy Markdown
Contributor

Fixes issue #1302.

Even though the code has remained this way for a long time, I think the current behavior of sql_variant is incorrect. The jdbcType variable in dtv.java is the JDBC type that the user specifies when they try to retrieve the data. This variable is telling the driver what the user wants to retrieve the data as, but this variable was getting modified to become the base type of the server's column type when retrieving sql_variant data, causing this issue (this effectively ignores the data type that the user was asking to retrieve sql_variant as). Leaving jdbcType as it is (which we should, since that's what the user wants) solves the issue.

However, when the driver performs bulk copy on a sql_variant column, the driver does need to designate jdbcType as the underlying data type to perform datatype-specific conversions. This made it difficult for applying my changes to all datatypes (for the scope of this PR), and for now only the datatypes that do not require any specific conversions from going from one another (for example, numeric values and String values) have the fixes applied.

@ulvii ulvii added this to the 8.3.1 milestone Apr 28, 2020
Comment thread src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLVariantResultSetTest.java Outdated
Comment thread src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLVariantResultSetTest.java Outdated
@rene-ye
Copy link
Copy Markdown
Member

rene-ye commented May 7, 2020

Can we document the "supported" sql variant datatype casts for now and the ones that aren't? Just so users have a reference in case they notice inconsistencies.

Comment thread src/main/java/com/microsoft/sqlserver/jdbc/DDC.java
Comment thread src/main/java/com/microsoft/sqlserver/jdbc/DDC.java
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.

4 participants