Fix getParameterMetaData crash with table-valued parameters #2746
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix getParameterMetaData() crash with table-valued parameters (#2744)
Problem:
• PreparedStatement.getParameterMetaData() was crashing with SQLServerException when table-valued parameters (TVP) were used
• Error: "A metadata error for the parameter {0} occurred" when calling getParameterMetaData() on statements with TVP
Root Cause:
• The parseQueryMeta() method in SQLServerParameterMetaData assumed all user-defined types (when suggested_system_type_name is null) were assembly types
• For table-valued parameters, suggested_system_type_name is null but suggested_user_type_name contains the table type name
• The code incorrectly queried sys.assembly_types for TVP types, which are actually table types with system_type_id = 243
Solution:
• Added STRUCTURED_TYPE constant (243) to identify SQL Server structured/table types
• Enhanced parseQueryMeta() to check suggested_system_type_id before determining type handling
• For TVP (system_type_id = 243):
• Maintained backward compatibility with existing assembly type handling
Testing:
• Added comprehensive test cases in ParameterMetaDataTest for TVP scenarios
• Validates getParameterMetaData() works correctly with table-valued parameters
• Ensures parameterCount, parameterTypeName, parameterType, and parameterClassName return correct values
• Covers the specific scenario reported in issue #2744
• Maintains compatibility with existing parameter metadata functionality
Fixes #2744