Skip to content

Commit 8450a2a

Browse files
author
James Cor
committed
preserve transactions
1 parent 70a3a2b commit 8450a2a

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

sql/rowexec/proc.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,11 @@ func (b *BaseBuilder) buildCall(ctx *sql.Context, n *plan.Call, row sql.Row) (sq
227227
}
228228
}
229229

230+
// Preserve existing transaction
231+
oldTx := ctx.GetTransaction()
232+
defer ctx.SetTransaction(oldTx)
233+
ctx.SetTransaction(nil)
234+
230235
rowIter, _, err := procedures.Call(ctx, n)
231236
if err != nil {
232237
return nil, err
@@ -260,17 +265,6 @@ func (b *BaseBuilder) buildCall(ctx *sql.Context, n *plan.Call, row sql.Row) (sq
260265
}
261266
}
262267

263-
// We might close transactions in the procedure, so we need to start a new one if we're not in one already
264-
if sess, ok := ctx.Session.(sql.TransactionSession); ok {
265-
if tx := ctx.GetTransaction(); tx == nil {
266-
tx, err = sess.StartTransaction(ctx, sql.ReadWrite)
267-
if err != nil {
268-
return nil, err
269-
}
270-
ctx.SetTransaction(tx)
271-
}
272-
}
273-
274268
return &callIter{
275269
call: n,
276270
innerIter: rowIter,

0 commit comments

Comments
 (0)