Skip to content

Commit 59f616e

Browse files
committed
[PGPRO-7856] Correction for object state releasing in case object was not deleted
Tags: atx
1 parent 83b5759 commit 59f616e

File tree

5 files changed

+102
-5
lines changed

5 files changed

+102
-5
lines changed

expected/pg_variables_atx_pkg.out

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,3 +436,38 @@ SELECT pgv_free();
436436

437437
(1 row)
438438

439+
--
440+
--
441+
-- PGPRO-7856
442+
-- Test for case: we don't remove the package object without any variables at
443+
-- the end of autonomous transaction but need to move the state of this object
444+
-- to upper level.
445+
--
446+
BEGIN;
447+
BEGIN AUTONOMOUS;
448+
SAVEPOINT sp1;
449+
SELECT pgv_set('vars2', 'any1', 'variable exists'::text, true);
450+
pgv_set
451+
---------
452+
453+
(1 row)
454+
455+
SELECT pgv_free();
456+
pgv_free
457+
----------
458+
459+
(1 row)
460+
461+
RELEASE sp1;
462+
ROLLBACK;
463+
BEGIN AUTONOMOUS;
464+
SAVEPOINT sp2;
465+
SAVEPOINT sp3;
466+
SELECT pgv_free();
467+
pgv_free
468+
----------
469+
470+
(1 row)
471+
472+
COMMIT;
473+
ROLLBACK;

expected/pg_variables_atx_pkg_1.out

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,3 +474,42 @@ SELECT pgv_free();
474474

475475
(1 row)
476476

477+
--
478+
--
479+
-- PGPRO-7856
480+
-- Test for case: we don't remove the package object without any variables at
481+
-- the end of autonomous transaction but need to move the state of this object
482+
-- to upper level.
483+
--
484+
BEGIN;
485+
BEGIN AUTONOMOUS;
486+
ERROR: syntax error at or near "AUTONOMOUS"
487+
LINE 1: BEGIN AUTONOMOUS;
488+
^
489+
SAVEPOINT sp1;
490+
ERROR: current transaction is aborted, commands ignored until end of transaction block
491+
SELECT pgv_set('vars2', 'any1', 'variable exists'::text, true);
492+
ERROR: current transaction is aborted, commands ignored until end of transaction block
493+
SELECT pgv_free();
494+
ERROR: current transaction is aborted, commands ignored until end of transaction block
495+
RELEASE sp1;
496+
ERROR: current transaction is aborted, commands ignored until end of transaction block
497+
ROLLBACK;
498+
BEGIN AUTONOMOUS;
499+
ERROR: syntax error at or near "AUTONOMOUS"
500+
LINE 1: BEGIN AUTONOMOUS;
501+
^
502+
SAVEPOINT sp2;
503+
ERROR: SAVEPOINT can only be used in transaction blocks
504+
SAVEPOINT sp3;
505+
ERROR: SAVEPOINT can only be used in transaction blocks
506+
SELECT pgv_free();
507+
pgv_free
508+
----------
509+
510+
(1 row)
511+
512+
COMMIT;
513+
WARNING: there is no transaction in progress
514+
ROLLBACK;
515+
WARNING: there is no transaction in progress

pg_variables.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,7 +2206,7 @@ removeState(TransObject *object, TransObjectType type, TransState *stateToDelete
22062206
}
22072207

22082208
/* Remove package or variable (either transactional or regular) */
2209-
void
2209+
bool
22102210
removeObject(TransObject *object, TransObjectType type)
22112211
{
22122212
bool found;
@@ -2228,7 +2228,7 @@ removeObject(TransObject *object, TransObjectType type)
22282228
if (getNestLevelATX() > 0 && !dlist_is_empty(&object->states))
22292229
{
22302230
GetActualState(object)->is_valid = false;
2231-
return;
2231+
return false;
22322232
}
22332233
#endif
22342234

@@ -2289,6 +2289,8 @@ removeObject(TransObject *object, TransObjectType type)
22892289
}
22902290

22912291
resetVariablesCache();
2292+
2293+
return true;
22922294
}
22932295

22942296
/*
@@ -2429,8 +2431,8 @@ releaseSavepoint(TransObject *object, TransObjectType type, bool sub)
24292431
dlist_is_empty(changesStack))
24302432
)
24312433
{
2432-
removeObject(object, type);
2433-
return;
2434+
if (removeObject(object, type))
2435+
return;
24342436
}
24352437

24362438
/*

pg_variables.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ extern bool update_record(Variable *variable, HeapTupleHeader tupleHeader);
193193
extern bool delete_record(Variable *variable, Datum value, bool is_null);
194194
extern void insert_record_copy(RecordVar *dest_record, Datum src_tuple,
195195
Variable *variable);
196-
extern void removeObject(TransObject *object, TransObjectType type);
196+
extern bool removeObject(TransObject *object, TransObjectType type);
197197

198198
#define GetActualState(object) \
199199
(dlist_head_element(TransState, node, &((TransObject *) object)->states))

sql/pg_variables_atx_pkg.sql

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,24 @@ ROLLBACK;
215215
SELECT pgv_remove('vars1', 'int1');
216216

217217
SELECT pgv_free();
218+
--
219+
--
220+
-- PGPRO-7856
221+
-- Test for case: we don't remove the package object without any variables at
222+
-- the end of autonomous transaction but need to move the state of this object
223+
-- to upper level.
224+
--
225+
BEGIN;
226+
BEGIN AUTONOMOUS;
227+
SAVEPOINT sp1;
228+
SELECT pgv_set('vars2', 'any1', 'variable exists'::text, true);
229+
SELECT pgv_free();
230+
RELEASE sp1;
231+
ROLLBACK;
232+
233+
BEGIN AUTONOMOUS;
234+
SAVEPOINT sp2;
235+
SAVEPOINT sp3;
236+
SELECT pgv_free();
237+
COMMIT;
238+
ROLLBACK;

0 commit comments

Comments
 (0)