From 64d076920da42d473da13e78415b658372640f31 Mon Sep 17 00:00:00 2001 From: Rafi Shamim Date: Wed, 18 Jan 2023 02:39:57 +0000 Subject: [PATCH] sql: fix CLOSE ALL so it doesn't ignore the ALL flag Release note (bug fix): Fixed a bug where CLOSE ALL would not respect the "ALL" flag and would instead attempt to close a cursor with no name. --- pkg/sql/logictest/testdata/logic_test/cursor | 35 ++++++++++++++++++++ pkg/sql/sql_cursor.go | 3 ++ 2 files changed, 38 insertions(+) diff --git a/pkg/sql/logictest/testdata/logic_test/cursor b/pkg/sql/logictest/testdata/logic_test/cursor index 787ff25c069c..09eea2aa3877 100644 --- a/pkg/sql/logictest/testdata/logic_test/cursor +++ b/pkg/sql/logictest/testdata/logic_test/cursor @@ -1,3 +1,6 @@ +statement ok +CLOSE ALL + statement ok CREATE TABLE a (a INT PRIMARY KEY, b INT); INSERT INTO a VALUES (1, 2), (2, 3) @@ -46,6 +49,38 @@ CLOSE foo statement ok COMMIT; +BEGIN; +DECLARE foo CURSOR FOR SELECT * FROM a ORDER BY a + +query II +FETCH 1 foo +---- +1 2 + +statement ok +CLOSE foo + +statement error cursor \"foo\" does not exist +FETCH 2 foo + +statement ok +ROLLBACK; +BEGIN; +DECLARE foo CURSOR FOR SELECT * FROM a ORDER BY a + +query II +FETCH 1 foo +---- +1 2 + +statement ok +CLOSE ALL + +statement error cursor \"foo\" does not exist +FETCH 2 foo + +statement ok +ROLLBACK; statement error cursor \"foo\" does not exist BEGIN; diff --git a/pkg/sql/sql_cursor.go b/pkg/sql/sql_cursor.go index 74e391d5f349..24cac954e275 100644 --- a/pkg/sql/sql_cursor.go +++ b/pkg/sql/sql_cursor.go @@ -242,6 +242,9 @@ func (p *planner) CloseCursor(ctx context.Context, n *tree.CloseCursor) (planNod return &delayedNode{ name: n.String(), constructor: func(ctx context.Context, p *planner) (planNode, error) { + if n.All { + return newZeroNode(nil /* columns */), p.sqlCursors.closeAll(false /* errorOnWithHold */) + } return newZeroNode(nil /* columns */), p.sqlCursors.closeCursor(n.Name) }, }, nil