-
Notifications
You must be signed in to change notification settings - Fork 90
Description
I am encountering an issue with the github.com/microsoft/go-mssqldb driver while working with multi-result sets in a stored procedure. Specifically, when the first result set consists of a single row with multiple columns (e.g., an aggregate value), and the second result set contains multiple rows and columns, the NextResultSet() method fails to move to the second result set.
Issue Details:
-
Stored Procedure Structure:
- The first result set contains 1 row with 1 column (e.g., a single integer value or aggregate value).
- The second result set contains multiple rows and columns (e.g., a list of user drafts).
-
What Happens:
- When the query is executed, the first result set (which contains a single row with 1 column) is scanned correctly.
- However, the driver seems unable to proceed to the second result set, even when
NextResultSet()is called. It fails to move past the first result set and doesn't return any data from the second result set.
-
Workaround:
- When I swap the result sets so that the first result set contains multiple rows and columns, and the second result set contains the single row with a column, the issue disappears and the
NextResultSet()successfully moves to the second record set.
- When I swap the result sets so that the first result set contains multiple rows and columns, and the second result set contains the single row with a column, the issue disappears and the
Steps to Reproduce:
-
Execute a stored procedure that returns two result sets:
- Result Set 1: 1 row with 1 column (e.g., a total count, aggregate data, or a status).
- Result Set 2: Multiple rows and columns (e.g., user data or a list of drafts).
Example stored procedure:
CREATE PROCEDURE dbo.sp_user_get_draft_list AS BEGIN -- First result set (1 row, 1 column) SELECT COUNT(*) AS total FROM users; -- Second result set (multiple rows, multiple columns) SELECT id, username, email FROM users; END
-
In Go code, use the
NextResultSet()method after scanning the first result set to try to access the second result set:if recordSet.Next() { // Scan first record set (single row with multiple columns) err := recordSet.Scan(&totalRow) if err != nil { return nil, fmt.Errorf("failed to scan total row: %w", err) } } if recordSet.NextResultSet() { // Scan second record set (multiple rows) for recordSet.Next() { // Scan data from the second result set } } else { return nil, fmt.Errorf("failed to move to the second result set") }
-
When the first result set contains only 1 row with 1 column, the
NextResultSet()call does not seem to proceed to the second result set.
Expected Behavior:
The NextResultSet() method should correctly handle the transition from the first result set (which contains 1 row with 1 column) to the second result set (which contains multiple rows and columns).
Observed Behavior:
The NextResultSet() method fails to move past the first result set when the first result set contains only 1 row with 1 column. However, swapping the result sets (making the first result set contain multiple rows and columns) resolves the issue.
Additional Information:
- I am using
github.com/microsoft/go-mssqldbversion 1.9.2. - The issue occurs specifically when dealing with 1 row 1 column result sets.
- I have captured the query being executed and can provide it for further analysis if needed.
Query Captured:
EXEC dbo.sp_user_get_draft_list @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8I am unsure whether this is a bug in the driver or if it is due to how the driver handles minimal result sets (e.g., a single row with multiple columns). I would appreciate any assistance or insight into how to resolve this issue.
Thank you for your time and help!