@@ -447,8 +447,7 @@ func (e *Engine) QueryWithBindings(ctx *sql.Context, query string, parsed sqlpar
447447 return nil , nil , nil , err
448448 }
449449
450- iter = rowexec .AddTransactionCommittingIter (iter , qFlags )
451- iter = rowexec .AddExpressionCloser (analyzed , iter )
450+ iter = finalizeIters (analyzed , qFlags , iter )
452451
453452 return analyzed .Schema (), iter , qFlags , nil
454453}
@@ -482,7 +481,8 @@ func (e *Engine) PrepQueryPlanForExecution(ctx *sql.Context, _ string, plan sql.
482481
483482 return nil , nil , nil , err
484483 }
485- iter = rowexec .AddExpressionCloser (plan , iter )
484+
485+ iter = finalizeIters (plan , nil , iter )
486486
487487 return plan .Schema (), iter , nil , nil
488488}
@@ -829,7 +829,8 @@ func (e *Engine) executeEvent(ctx *sql.Context, dbName, createEventStatement, us
829829 }
830830 return err
831831 }
832- iter = rowexec .AddExpressionCloser (definitionNode , iter )
832+
833+ iter = finalizeIters (definitionNode , nil , iter )
833834
834835 // Drain the iterate to execute the event body/definition
835836 // NOTE: No row data is returned for an event; we just need to execute the statements
@@ -862,3 +863,10 @@ func findCreateEventNode(planTree sql.Node) (*plan.CreateEvent, error) {
862863
863864 return createEventNode , nil
864865}
866+
867+ // finalizeIters applies the final transformations on sql.RowIter before execution.
868+ func finalizeIters (analyzed sql.Node , qFlags * sql.QueryFlags , iter sql.RowIter ) sql.RowIter {
869+ iter = rowexec .AddTransactionCommittingIter (iter , qFlags )
870+ iter = rowexec .AddExpressionCloser (analyzed , iter )
871+ return iter
872+ }
0 commit comments