Skip to content

Conversation

muskan124947
Copy link
Contributor

@muskan124947 muskan124947 commented Jul 15, 2025

Description

This PR addresses GitHub reported issue : DatabaseMetadata.getProcedures and getFunctions return both functions and procedures #2690
Both DatabaseMetadata.getProcedures and DatabaseMetadata.getFunctions were returning a result set that included both stored procedures and functions, instead of filtering to return only the relevant object type for each method. This caused confusion, as users expect the results of each method to be exclusive to procedures or functions.

Currently, getFunctions() and getProcedures() both call the sp_stored_procedures. This issue originates from how the server handles sp_stored_procedures. It always returns the procedure type as 2 (sp-stored-procedures-transact-sql), regardless of whether the object is a function or a procedure.

Fix

The implementation has been updated so that getProcedures() and getFunctions() now use sys.all_objects to accurately filter database objects. Additionally, for procedures type is returned as 1 and 2 for functions.
Specifically, procedures are identified by object types

- 'P' (SQL stored procedure) 
- 'PC' (assembly stored procedure)

And functions are identified by

- 'FN' (SQL scalar function) 
- 'IF' (SQL inline table-valued function)
- 'TF' (SQL table-valued function)

This ensures that each method returns only the objects relevant to its purpose, resolving the confusion caused by the previous behavior.

Testing

Manual testing by creating scripts to validate objects (functions and procedures) obtained from getFunctions() and getProcedures() using sys.all_objects matches the result obtained from sp_stored_procedures. This testing was done locally

@muskan124947 muskan124947 self-assigned this Jul 15, 2025
Copy link

codecov bot commented Jul 15, 2025

Codecov Report

❌ Patch coverage is 73.68421% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 51.56%. Comparing base (44d6010) to head (867c2a8).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...soft/sqlserver/jdbc/SQLServerDatabaseMetaData.java 73.68% 3 Missing and 7 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #2705      +/-   ##
============================================
- Coverage     51.60%   51.56%   -0.05%     
- Complexity     4083     4091       +8     
============================================
  Files           149      149              
  Lines         34242    34268      +26     
  Branches       5719     5725       +6     
============================================
- Hits          17672    17669       -3     
- Misses        14104    14127      +23     
- Partials       2466     2472       +6     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@muskan124947 muskan124947 requested a review from Ananya2 August 4, 2025 06:38
@machavan machavan added this to the 13.2.0 milestone Aug 4, 2025
@divang divang changed the title Updated getFunctions() and getProcedures() to use sys.all_objects to give correct results post filtering Fix: Use sys.all_objects for Accurate Function and Procedure Filtering Aug 7, 2025
@divang divang changed the title Fix: Use sys.all_objects for Accurate Function and Procedure Filtering Use sys.all_objects for Accurate Function and Procedure Filtering Aug 7, 2025
Copy link
Collaborator

@David-Engel David-Engel left a comment

Choose a reason for hiding this comment

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

Implementation looks good. Tests need a little tweaking, though. We don't need to print all that stuff to the logs.

@muskan124947 muskan124947 changed the title Use sys.all_objects for Accurate Function and Procedure Filtering Use sys.all_objects for accurate function and procedure filtering Aug 12, 2025
machavan
machavan previously approved these changes Aug 12, 2025
Ananya2
Ananya2 previously approved these changes Aug 12, 2025
@Ananya2
Copy link
Contributor

Ananya2 commented Aug 12, 2025

PR approved. We can perform manual testing against a SQL DW instance using JDBC_DW.

@muskan124947 muskan124947 dismissed stale reviews from Ananya2 and machavan via da9d22a August 12, 2025 13:07
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