-
Notifications
You must be signed in to change notification settings - Fork 438
Description
Driver version
13.2.0.jre11
SQL Server version
Microsoft SQL Server 2022 (RTM-CU15-GDR) (KB5046059) - 16.0.4150.1 (X64)
Sep 25 2024 17:34:41
Copyright (C) 2022 Microsoft Corporation
Developer Edition (64-bit) on Linux (Ubuntu 22.04.5 LTS)
Client Operating System
Arch Linux (6.16.0-arch2-1)
JAVA/JVM version
OpenJDK 17
Table schema
create type dbo.IdTable as table (id uniqueidentifier);
Problem description
Calling getParameterMetaData
on a PreparedStatement
crashes with when the query includes a table-valued parameter.
Example:
String sql = "declare @ids dbo.IdTable = ?; select id from @ids;";
PreparedStatement stmt = connection.prepareStatement(sql);
// This crashes
stmt.getParameterMetaData();
Looking at the source code, the problem seems to be that the driver assumes any custom data type is an assembly type, and doesn't even attempt to handle the case where it's not.
Expected behavior
I expect the call to getParameterMetaData
to succeed, returning the metadata with the correct type name for the table-valued parameter from getParameterTypeName
.
Actual behavior
An SQLServerException is thrown when calling getParameterMetaData
.
Error message/stack trace
com.microsoft.sqlserver.jdbc.SQLServerException: A metadata error for the parameter {0} occurred.
at com.microsoft.sqlserver.jdbc.SQLServerParameterMetaData.parseQueryMeta(SQLServerParameterMetaData.java:190)
at com.microsoft.sqlserver.jdbc.SQLServerParameterMetaData.<init>(SQLServerParameterMetaData.java:354)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.getParameterMetaData(SQLServerPreparedStatement.java:3445)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.getParameterMetaData(SQLServerPreparedStatement.java:3456)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: A metadata error for the parameter {0} occurred.
at com.microsoft.sqlserver.jdbc.SQLServerParameterMetaData.parseQueryMeta(SQLServerParameterMetaData.java:176)
at com.microsoft.sqlserver.jdbc.SQLServerParameterMetaData.<init>(SQLServerParameterMetaData.java:354)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.getParameterMetaData(SQLServerPreparedStatement.java:3445)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.getParameterMetaData(SQLServerPreparedStatement.java:3456)
Any other details that can be helpful
When explicitly calling sp_describe_undeclared_parameters
with the query (replacing ?
with @P0
), the correct information appears to be returned
Column | Value |
---|---|
parameter_ordinal | 1 |
name | @P0 |
suggested_system_type_id | 243 |
suggested_system_type_name | null |
suggested_max_length | 8 |
suggested_precision | 0 |
suggested_scale | 0 |
suggested_user_type_id | 258 |
suggested_user_type_database | master |
suggested_user_type_schema | dbo |
suggested_user_type_name | IdTable |
suggested_assembly_qualified_type_name | null |
suggested_xml_collection_id | null |
suggested_xml_collection_database | null |
suggested_xml_collection_schema | null |
suggested_xml_collection_name | null |
suggested_is_xml_document | false |
suggested_is_case_sensitive | false |
suggested_is_fixed_length_clr_type | false |
suggested_is_input | true |
suggested_is_output | false |
formal_parameter_name | null |
suggested_tds_type_id | 243 |
suggested_tds_length | 8 |