Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions enginetest/queries/script_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,37 @@ type ScriptTestAssertion struct {
// Unlike other engine tests, ScriptTests must be self-contained. No other tables are created outside the definition of
// the tests.
var ScriptTests = []ScriptTest{
{
// https://github.com/dolthub/dolt/issues/9865
Name: "Stored procedure containing a transaction does not return EOF",
Dialect: "mysql",
SetUpScript: []string{
"CREATE TABLE test_table (id INT PRIMARY KEY, name TEXT)",
`CREATE PROCEDURE my_proc()
BEGIN
START TRANSACTION;
INSERT INTO test_table VALUES (1, 'test');
COMMIT;
END`,
`CREATE PROCEDURE empty_procedure()
BEGIN
END`,
},
Assertions: []ScriptTestAssertion{
{
Query: "CALL my_proc()",
Expected: []sql.Row{{types.OkResult{RowsAffected: 0, InsertID: 0, Info: nil}}},
},
{
Query: "SELECT * FROM test_table",
Expected: []sql.Row{{1, "test"}},
},
{
Query: "CALL empty_procedure()",
Expected: []sql.Row{{types.OkResult{RowsAffected: 0, InsertID: 0, Info: nil}}},
},
},
},
{
// https://github.com/dolthub/dolt/issues/9873
// TODO: `FOR UPDATE OF` (`FOR UPDATE` in general) is currently a no-op: https://www.dolthub.com/blog/2023-10-23-hold-my-beer/
Expand Down
5 changes: 5 additions & 0 deletions sql/procedures/interpreter_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,11 @@ func Call(ctx *sql.Context, iNode InterpreterNode) (sql.RowIter, *InterpreterSta
rowIters = append(rowIters, sql.RowsToRowIter(sql.Row{types.NewOkResult(0)}))
} else if retSch != nil {
iNode.SetSchema(retSch)
} else {
// If we have rowIters but no meaningful schema, return OkResult
// This ensures CALL statements always return proper result sets for MySQL protocol
iNode.SetSchema(types.OkResultSchema)
rowIters = []sql.RowIter{sql.RowsToRowIter(sql.Row{types.NewOkResult(0)})}
}

return rowIters[len(rowIters)-1], stack, nil
Expand Down
12 changes: 9 additions & 3 deletions sql/rowexec/proc_iters.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,20 @@ var _ sql.MutableRowIter = (*callIter)(nil)

// Next implements the sql.RowIter interface.
func (ci *callIter) Next(ctx *sql.Context) (sql.Row, error) {
if ci.innerIter == nil {
return nil, io.EOF
}
return ci.innerIter.Next(ctx)
}

// Close implements the sql.RowIter interface.
func (ci *callIter) Close(ctx *sql.Context) error {
err := ci.innerIter.Close(ctx)
if err != nil {
return err
var err error
if ci.innerIter != nil {
err = ci.innerIter.Close(ctx)
if err != nil {
return err
}
}
err = ci.call.Pref.CloseAllCursors(ctx)
if err != nil {
Expand Down