Skip to content

Commit

Permalink
sql: fix CLOSE ALL so it doesn't ignore the ALL flag
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rafiss committed Jan 18, 2023
1 parent 4ec5a5f commit 370a3f5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
35 changes: 35 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/cursor
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions pkg/sql/sql_cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,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
Expand Down

0 comments on commit 370a3f5

Please sign in to comment.