client: add Stmt.ExecuteProcedureMultiResults for multi-result stored procedures#1165
Merged
lance6716 merged 10 commits intoJul 9, 2026
Conversation
… procedures ExecuteProcedureMultiResults runs COM_STMT_EXECUTE and drains all logical results until SERVER_MORE_RESULTS_EXISTS is clear. A caller-supplied StmtProcedureMultiResultForward callback is invoked for each result in arrival order. The loop continues draining the server response even after forward returns non-nil, matching ExecuteMultiple semantics so that unread packets cannot corrupt the connection state. This is the prepared-statement equivalent of ExecuteMultiple. It is needed for CALL statements with OUT parameters or multiple SELECT result sets, where Connector/J (and other JDBC drivers) use COM_STMT_EXECUTE and expect every result set to be forwarded. Closes go-mysql-org#1162 Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
There was a problem hiding this comment.
Code Review
This pull request adds the ExecuteProcedureMultiResults method to the Stmt struct in client/stmt.go to support executing stored procedures that return multiple result sets. The review feedback suggests improving the API's usability and consistency by making the args parameter variadic and placing the forward callback first, as well as initializing the synthetic resultset with 0 fields instead of 1.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
…ltiResults Place the forward callback first with variadic args for consistency with Stmt.Execute and Stmt.ExecuteSelectStreaming. Initialize the synthetic streaming resultset with zero fields to match ExecuteMultiple. Co-authored-by: Cursor <cursoragent@cursor.com>
Add a nil-callback unit test and a clientTestSuite integration test that creates a stored procedure returning two result sets. Negotiate CLIENT_MULTI_RESULTS and CLIENT_PS_MULTI_RESULTS in SetupSuite. Co-authored-by: Cursor <cursoragent@cursor.com>
CLIENT_MULTI_RESULTS and CLIENT_PS_MULTI_RESULTS are already included in the client's default capability set (client/auth.go) and are negotiated automatically during the initial handshake. Setting them again in SetupSuite was redundant and caused TestConn_SetCapability to fail because that test asserts those capabilities start unset on the shared connection. Co-authored-by: Cursor <cursoragent@cursor.com>
The shared suite connection does not set CLIENT_MULTI_RESULTS or CLIENT_PS_MULTI_RESULTS (they are optional capabilities), so calling a stored procedure through it produced ERROR 1312. Open a per-test connection that explicitly enables both capabilities, which is the correct way to test ExecuteProcedureMultiResults without disturbing the shared connection used by TestConn_SetCapability and other suite tests. Co-authored-by: Cursor <cursoragent@cursor.com>
lance6716
reviewed
Jul 8, 2026
Remove the synthetic NewResultset(0) return value; callers that forward results via the callback do not need a dummy *mysql.Result. Matches ExecuteSelectStreaming semantics and addresses review feedback on PR go-mysql-org#1165. Co-authored-by: Cursor <cursoragent@cursor.com>
Rename TestStmt_ExecuteProcedureMultiResults to TestStmt_ProcedureMultiResult and TestExecuteProcedureMultiResults_NilCallback to TestStmtProcedureMultiResultNilForward, consistent with other TestStmt_* names. Co-authored-by: Cursor <cursoragent@cursor.com>
lance6716
reviewed
Jul 9, 2026
…esult Match the naming style used in conn_test (e.g. TestExecuteMultiple) per review feedback on PR go-mysql-org#1165. Co-authored-by: Cursor <cursoragent@cursor.com>
Clarify that a nil return from forward means the result or error was handled and is not propagated. Simplify the final return to `return forwardErr` per review feedback on PR go-mysql-org#1165. Co-authored-by: Cursor <cursoragent@cursor.com>
lance6716
approved these changes
Jul 9, 2026
dbnski
pushed a commit
to dbnski/go-mysql
that referenced
this pull request
Jul 10, 2026
… procedures (go-mysql-org#1165) * client: add Stmt.ExecuteProcedureMultiResults for multi-result stored procedures ExecuteProcedureMultiResults runs COM_STMT_EXECUTE and drains all logical results until SERVER_MORE_RESULTS_EXISTS is clear. A caller-supplied StmtProcedureMultiResultForward callback is invoked for each result in arrival order. The loop continues draining the server response even after forward returns non-nil, matching ExecuteMultiple semantics so that unread packets cannot corrupt the connection state. This is the prepared-statement equivalent of ExecuteMultiple. It is needed for CALL statements with OUT parameters or multiple SELECT result sets, where Connector/J (and other JDBC drivers) use COM_STMT_EXECUTE and expect every result set to be forwarded. Closes go-mysql-org#1162 Co-authored-by: Cursor <cursoragent@cursor.com> * client: variadic signature and NewResultset(0) for ExecuteProcedureMultiResults Place the forward callback first with variadic args for consistency with Stmt.Execute and Stmt.ExecuteSelectStreaming. Initialize the synthetic streaming resultset with zero fields to match ExecuteMultiple. Co-authored-by: Cursor <cursoragent@cursor.com> * test: add unit and integration tests for ExecuteProcedureMultiResults Add a nil-callback unit test and a clientTestSuite integration test that creates a stored procedure returning two result sets. Negotiate CLIENT_MULTI_RESULTS and CLIENT_PS_MULTI_RESULTS in SetupSuite. Co-authored-by: Cursor <cursoragent@cursor.com> * test: remove redundant SetCapability calls from SetupSuite CLIENT_MULTI_RESULTS and CLIENT_PS_MULTI_RESULTS are already included in the client's default capability set (client/auth.go) and are negotiated automatically during the initial handshake. Setting them again in SetupSuite was redundant and caused TestConn_SetCapability to fail because that test asserts those capabilities start unset on the shared connection. Co-authored-by: Cursor <cursoragent@cursor.com> * test: use dedicated connection with multi-result caps in procedure test The shared suite connection does not set CLIENT_MULTI_RESULTS or CLIENT_PS_MULTI_RESULTS (they are optional capabilities), so calling a stored procedure through it produced ERROR 1312. Open a per-test connection that explicitly enables both capabilities, which is the correct way to test ExecuteProcedureMultiResults without disturbing the shared connection used by TestConn_SetCapability and other suite tests. Co-authored-by: Cursor <cursoragent@cursor.com> * client: return error only from ExecuteProcedureMultiResults Remove the synthetic NewResultset(0) return value; callers that forward results via the callback do not need a dummy *mysql.Result. Matches ExecuteSelectStreaming semantics and addresses review feedback on PR go-mysql-org#1165. Co-authored-by: Cursor <cursoragent@cursor.com> * test: rename procedure multi-result tests to match naming style Rename TestStmt_ExecuteProcedureMultiResults to TestStmt_ProcedureMultiResult and TestExecuteProcedureMultiResults_NilCallback to TestStmtProcedureMultiResultNilForward, consistent with other TestStmt_* names. Co-authored-by: Cursor <cursoragent@cursor.com> * test: rename TestStmt_ProcedureMultiResult to TestStmtProcedureMultiResult Match the naming style used in conn_test (e.g. TestExecuteMultiple) per review feedback on PR go-mysql-org#1165. Co-authored-by: Cursor <cursoragent@cursor.com> * client: document forward error handling and simplify return Clarify that a nil return from forward means the result or error was handled and is not propagated. Simplify the final return to `return forwardErr` per review feedback on PR go-mysql-org#1165. Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: lance6716 <lance6716@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Add
(*Stmt).ExecuteProcedureMultiResultsand theStmtProcedureMultiResultForwardcallback type toclient/stmt.go.Closes #1162
Motivation
(*Stmt).Executereads a single result viareadResult(true)and stops. When a stored procedure returns multiple result sets (e.g., aCALLwithOUTparameters or multipleSELECTstatements inside), the server setsSERVER_MORE_RESULTS_EXISTSin intermediate result statuses. CallingExecutein this case leaves subsequent packets buffered on the connection, corrupting its state.The text-protocol equivalent
Conn.ExecuteMultiplealready handles this correctly by looping until the flag is clear. This PR adds the same capability for prepared statements (COM_STMT_EXECUTE), which is the path taken by Connector/J and other JDBC drivers forCallableStatement.New API
Design notes
forwardreturns an error because leaving unread results on the wire would corrupt the connection. Instead the forward error is saved and returned only after all results have been consumed — identical toExecuteMultiplesemantics.StreamingMultiple / StreamingDoneresult is returned on success so callers can pass it toserver.Conn.WriteValuewithout additional handling.Notes
CLIENT_PS_MULTI_RESULTSto be negotiated (included in server default capabilities since server: advertise CLIENT_MULTI_RESULTS, CLIENT_PS_MULTI_RESULTS in default capabilities #1155).Made with Cursor