Skip to content
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

Fix to ensure metadata returned follows JDBC data type specs #2326

Merged
merged 10 commits into from
Mar 5, 2024

Conversation

barryw-mssql
Copy link
Contributor

ResultSetMetadata of the ResultSet from DatabaseMetadata.getColumns() is Incorrect for Some Columns (1751)

Fix ensures the correct data types for each metadata column by mapping the data type from the SQL Server to the type specified in the JDBC spec

… is Incorrect for Some Columns (1751)

Fix ensures the correct data types for each metadata column match the data type from the SQL Server and the JDBC spec
@Jeffery-Wasty Jeffery-Wasty added this to In progress in MSSQL JDBC via automation Feb 9, 2024
@Jeffery-Wasty Jeffery-Wasty added this to the 12.7.0 milestone Feb 9, 2024
@Jeffery-Wasty Jeffery-Wasty moved this from In progress to Under Peer Review in MSSQL JDBC Feb 9, 2024
TestResource.getResource("R_classLoaderNotFoundForColumnType"));
Object[] msgArgs = {columnClassName, columnLabel};
fail(form.format(msgArgs));
}
Copy link
Member

Choose a reason for hiding this comment

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

I think we just need to assertTrue or assertEqual that the expectedClass.getName().equals(columnClassName) as per repro in the issue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed the logic for checking the returned column data type matches the expected data type to simplify the logic. The new logic removes this Class Loader test. There is a new tests that actually compares the actual and expected class name for each column but does not use an assert. Instead a R_expectedClassDoesNotMatchActualClass message is used which includes the actual and expected data types as well as the column. This was done because if just an assert was used it would not show which column was generating the issue in the metadata result set.

Copy link
Member

@lilgreenbird lilgreenbird left a comment

Choose a reason for hiding this comment

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

pls run formatter on all files.

MSSQL JDBC automation moved this from Under Peer Review to In progress Feb 22, 2024
Copy link
Member

@lilgreenbird lilgreenbird left a comment

Choose a reason for hiding this comment

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

there should be a test case to cover the error msg R_colCountNotMatchColTypeCount path

@lilgreenbird lilgreenbird moved this from In progress to Under Peer Review in MSSQL JDBC Feb 22, 2024
Copy link

codecov bot commented Feb 27, 2024

Codecov Report

Attention: Patch coverage is 33.33333% with 70 lines in your changes are missing coverage. Please review.

❗ No coverage uploaded for pull request base (main@9b5036d). Click here to learn what that means.

❗ Current head 61ae9b6 differs from pull request most recent head 0ce310e. Consider uploading reports for the commit 0ce310e to get more accurate results

Files Patch % Lines
...soft/sqlserver/jdbc/SQLServerDatabaseMetaData.java 8.62% 53 Missing ⚠️
.../microsoft/sqlserver/jdbc/SQLServerConnection.java 59.37% 5 Missing and 8 partials ⚠️
...m/microsoft/sqlserver/jdbc/SQLServerException.java 50.00% 0 Missing and 3 partials ⚠️
...oft/sqlserver/jdbc/SQLServerPreparedStatement.java 87.50% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2326   +/-   ##
=======================================
  Coverage        ?   50.04%           
  Complexity      ?     3793           
=======================================
  Files           ?      143           
  Lines           ?    33179           
  Branches        ?     5631           
=======================================
  Hits            ?    16605           
  Misses          ?    14191           
  Partials        ?     2383           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Class<?> expectedClass = getColumnMetaDataClass.get(columnLabel);

// Ensure the metadata column is in the metadata column class map
assertNotNull(expectedClass);
Copy link
Member

Choose a reason for hiding this comment

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

This was mentioned in a previous comment above, but ensure that expectedClass is not null, don't assert.

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
assertNotNull(expectedClass);
if (null != expectedClass) {

Copy link
Member

Choose a reason for hiding this comment

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

this really shouldn't even be necessary, we just defined this above, this would never be null

Copy link
Member

Choose a reason for hiding this comment

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

did we accidentally remove the check for isAssignableFrom that was in previous commit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The expected class can be null if the the column label/name in the expected class lookup table does not match the actual column label from the result set (i.e. the lookup by column name will fail). This shouldn't happen but it is possible if there was a future code change or perhaps the returned metadata columns change.

Yes the IsAssignableFrom() is no longer used as I changed the BUFFER_LENGTH metadata class from Object to Integer. It was because of this generic Object class that we needed to use the IsAssignableFrom() check. Is The reason why it was originally specified as a generic Object was that the JDBC spec does not use the BUFFER_LENGTH column and so I reflected that as a generic Object being the expected data type. But in the code I have always ensured that BUFFER_LENGTH was an Integer. Therefore to simplify the logic and remove the IsAssignableFrom() check, I switched the expected class for the BUFFER_LENGTH column from Object to Integer.

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 have kept the check but no longer use an assert to perform the check. I found that in the unlikely event there was an issue, a more detail error message was required that would include not just the actual and expected types but the column as well. Without the column name/label, it would initially be difficult t determine what the problem column was in the metadata

@tkyc tkyc dismissed lilgreenbird’s stale review March 4, 2024 18:33

Changes are addressed

MSSQL JDBC automation moved this from Under Peer Review to In progress Mar 4, 2024
@barryw-mssql barryw-mssql merged commit eae6d7b into main Mar 5, 2024
17 checks passed
MSSQL JDBC automation moved this from In progress to Closed/Merged PRs Mar 5, 2024
@Jeffery-Wasty Jeffery-Wasty deleted the barry_test branch March 11, 2024 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
MSSQL JDBC
  
Closed/Merged PRs
Development

Successfully merging this pull request may close these issues.

ResultSetMetadata of the ResultSet from DatabaseMetadata.getColumns() is Incorrect for Some Columns
5 participants