Skip to content

Commit 4fe2012

Browse files
author
Neil Conway
committed
Add regression tests for recent cursor/savepoint bug fixed by Alvaro and
Tom.
1 parent aba691b commit 4fe2012

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

src/test/regress/expected/transactions.out

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,3 +470,50 @@ ROLLBACK;
470470
DROP TABLE foo;
471471
DROP TABLE baz;
472472
DROP TABLE barbaz;
473+
-- verify that cursors created during an aborted subtransaction are
474+
-- closed, but that we do not rollback the effect of any FETCHs
475+
-- performed in the aborted subtransaction
476+
begin;
477+
savepoint x;
478+
create table abc (a int);
479+
insert into abc values (5);
480+
insert into abc values (10);
481+
declare foo cursor for select * from abc;
482+
fetch from foo;
483+
a
484+
---
485+
5
486+
(1 row)
487+
488+
rollback to x;
489+
-- should fail
490+
fetch from foo;
491+
ERROR: cursor "foo" does not exist
492+
commit;
493+
begin;
494+
create table abc (a int);
495+
insert into abc values (5);
496+
insert into abc values (10);
497+
insert into abc values (15);
498+
declare foo cursor for select * from abc;
499+
fetch from foo;
500+
a
501+
---
502+
5
503+
(1 row)
504+
505+
savepoint x;
506+
fetch from foo;
507+
a
508+
----
509+
10
510+
(1 row)
511+
512+
rollback to x;
513+
fetch from foo;
514+
a
515+
----
516+
15
517+
(1 row)
518+
519+
abort;

src/test/regress/sql/transactions.sql

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,3 +290,38 @@ ROLLBACK;
290290
DROP TABLE foo;
291291
DROP TABLE baz;
292292
DROP TABLE barbaz;
293+
294+
-- verify that cursors created during an aborted subtransaction are
295+
-- closed, but that we do not rollback the effect of any FETCHs
296+
-- performed in the aborted subtransaction
297+
begin;
298+
299+
savepoint x;
300+
create table abc (a int);
301+
insert into abc values (5);
302+
insert into abc values (10);
303+
declare foo cursor for select * from abc;
304+
fetch from foo;
305+
rollback to x;
306+
307+
-- should fail
308+
fetch from foo;
309+
commit;
310+
311+
begin;
312+
313+
create table abc (a int);
314+
insert into abc values (5);
315+
insert into abc values (10);
316+
insert into abc values (15);
317+
declare foo cursor for select * from abc;
318+
319+
fetch from foo;
320+
321+
savepoint x;
322+
fetch from foo;
323+
rollback to x;
324+
325+
fetch from foo;
326+
327+
abort;

0 commit comments

Comments
 (0)