From 2740434a220482bc6193b18024a173b1287a893f Mon Sep 17 00:00:00 2001 From: lxfeng1997 <33981743+lxfeng1997@users.noreply.github.com> Date: Mon, 2 Jan 2023 22:04:01 +0800 Subject: [PATCH] bugfix: at model execution failed (#429) * bugfix: at model execution failed --- pkg/datasource/sql/exec/at/delete_executor.go | 5 +++++ pkg/datasource/sql/exec/at/insert_executor.go | 5 +++++ pkg/datasource/sql/exec/at/update_executor.go | 10 ++++++++++ testdata/sql/undo_log.sql | 15 +++++++++++++++ 4 files changed, 35 insertions(+) create mode 100644 testdata/sql/undo_log.sql diff --git a/pkg/datasource/sql/exec/at/delete_executor.go b/pkg/datasource/sql/exec/at/delete_executor.go index 589f8b5b9..9179acb72 100644 --- a/pkg/datasource/sql/exec/at/delete_executor.go +++ b/pkg/datasource/sql/exec/at/delete_executor.go @@ -87,6 +87,11 @@ func (d *deleteExecutor) beforeImage(ctx context.Context) (*types.RecordImage, e } if ok { rowsi, err = util.CtxDriverQuery(ctx, queryerCtx, queryer, selectSQL, selectArgs) + defer func() { + if rowsi != nil { + rowsi.Close() + } + }() if err != nil { log.Errorf("ctx driver query: %+v", err) return nil, err diff --git a/pkg/datasource/sql/exec/at/insert_executor.go b/pkg/datasource/sql/exec/at/insert_executor.go index 14d731356..3fb67e1c5 100644 --- a/pkg/datasource/sql/exec/at/insert_executor.go +++ b/pkg/datasource/sql/exec/at/insert_executor.go @@ -110,6 +110,11 @@ func (i *insertExecutor) afterImage(ctx context.Context) (*types.RecordImage, er } if ok { rowsi, err = util.CtxDriverQuery(ctx, queryerCtx, queryer, selectSQL, selectArgs) + defer func() { + if rowsi != nil { + rowsi.Close() + } + }() if err != nil { log.Errorf("ctx driver query: %+v", err) return nil, err diff --git a/pkg/datasource/sql/exec/at/update_executor.go b/pkg/datasource/sql/exec/at/update_executor.go index 46b927fa8..645a7f474 100644 --- a/pkg/datasource/sql/exec/at/update_executor.go +++ b/pkg/datasource/sql/exec/at/update_executor.go @@ -108,6 +108,11 @@ func (u *updateExecutor) beforeImage(ctx context.Context) (*types.RecordImage, e } if ok { rowsi, err = util.CtxDriverQuery(ctx, queryerCtx, queryer, selectSQL, selectArgs) + defer func() { + if rowsi != nil { + rowsi.Close() + } + }() if err != nil { log.Errorf("ctx driver query: %+v", err) return nil, err @@ -153,6 +158,11 @@ func (u *updateExecutor) afterImage(ctx context.Context, beforeImage types.Recor } if ok { rowsi, err = util.CtxDriverQuery(ctx, queryerCtx, queryer, selectSQL, selectArgs) + defer func() { + if rowsi != nil { + rowsi.Close() + } + }() if err != nil { log.Errorf("ctx driver query: %+v", err) return nil, err diff --git a/testdata/sql/undo_log.sql b/testdata/sql/undo_log.sql new file mode 100644 index 000000000..7a00b709d --- /dev/null +++ b/testdata/sql/undo_log.sql @@ -0,0 +1,15 @@ +DROP TABLE IF EXISTS `undo_log`; +CREATE TABLE `undo_log` +( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `branch_id` bigint(20) NOT NULL, + `xid` varchar(100) NOT NULL, + `context` varchar(128) NOT NULL, + `rollback_info` longblob NOT NULL, + `log_status` int(11) NOT NULL, + `log_created` datetime NOT NULL, + `log_modified` datetime NOT NULL, + `ext` varchar(100) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; \ No newline at end of file