mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
When a cursor is opened using dblink_open, only start a transaction
if there isn't one already open. Upon dblink_close, only commit the open transaction if it was started by dblink_open, and only then when all cursors opened by dblink_open are closed. The transaction accounting is done individually for all named connections, plus the persistent unnamed connection.
This commit is contained in:
@ -217,6 +217,42 @@ SELECT dblink_open('myconn','rmt_foo_cursor','SELECT * FROM foobar',false);
|
||||
-- reset remote transaction state
|
||||
SELECT dblink_exec('myconn','ABORT');
|
||||
|
||||
-- test opening cursor in a transaction
|
||||
SELECT dblink_exec('myconn','BEGIN');
|
||||
|
||||
-- an open transaction will prevent dblink_open() from opening its own
|
||||
SELECT dblink_open('myconn','rmt_foo_cursor','SELECT * FROM foo');
|
||||
|
||||
-- this should not commit the transaction because the client opened it
|
||||
SELECT dblink_close('myconn','rmt_foo_cursor');
|
||||
|
||||
-- this should succeed because we have an open transaction
|
||||
SELECT dblink_exec('myconn','DECLARE xact_test CURSOR FOR SELECT * FROM foo');
|
||||
|
||||
-- commit remote transaction
|
||||
SELECT dblink_exec('myconn','COMMIT');
|
||||
|
||||
-- test automatic transactions for multiple cursor opens
|
||||
SELECT dblink_open('myconn','rmt_foo_cursor','SELECT * FROM foo');
|
||||
|
||||
-- the second cursor
|
||||
SELECT dblink_open('myconn','rmt_foo_cursor2','SELECT * FROM foo');
|
||||
|
||||
-- this should not commit the transaction
|
||||
SELECT dblink_close('myconn','rmt_foo_cursor2');
|
||||
|
||||
-- this should succeed because we have an open transaction
|
||||
SELECT dblink_exec('myconn','DECLARE xact_test CURSOR FOR SELECT * FROM foo');
|
||||
|
||||
-- this should commit the transaction
|
||||
SELECT dblink_close('myconn','rmt_foo_cursor');
|
||||
|
||||
-- this should fail because there is no open transaction
|
||||
SELECT dblink_exec('myconn','DECLARE xact_test CURSOR FOR SELECT * FROM foo');
|
||||
|
||||
-- reset remote transaction state
|
||||
SELECT dblink_exec('myconn','ABORT');
|
||||
|
||||
-- open a cursor
|
||||
SELECT dblink_open('myconn','rmt_foo_cursor','SELECT * FROM foo');
|
||||
|
||||
|
Reference in New Issue
Block a user