Skip to content

Commit 48c46fc

Browse files
committed
fix: add package test and meson.build entry for autonomous transactions
- Add Test 21: autonomous transaction in package procedure - Add pl_autonomous.c to meson.build for Meson build support
1 parent a580f91 commit 48c46fc

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

src/pl/plisql/src/expected/plisql_autonomous.out

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,31 @@ SELECT id, msg FROM autonomous_test WHERE id = 55 ORDER BY id;
509509
55 | boolean: false
510510
(2 rows)
511511

512+
--
513+
-- Test 21: Autonomous transaction in package procedure
514+
-- Tests that PRAGMA AUTONOMOUS_TRANSACTION works inside package bodies
515+
--
516+
CREATE OR REPLACE PACKAGE test_pkg AUTHID DEFINER AS
517+
PROCEDURE pkg_test_with_params(p_id INT, p_msg TEXT);
518+
END;
519+
/
520+
CREATE OR REPLACE PACKAGE BODY test_pkg AS
521+
PROCEDURE pkg_test_with_params(p_id INT, p_msg TEXT) AS
522+
PRAGMA AUTONOMOUS_TRANSACTION;
523+
BEGIN
524+
INSERT INTO autonomous_test VALUES (p_id, p_msg, 'committed');
525+
END pkg_test_with_params;
526+
END test_pkg;
527+
/
528+
COMMIT;
529+
WARNING: there is no transaction in progress
530+
CALL test_pkg.pkg_test_with_params(76, 'package procedure test');
531+
SELECT id, msg FROM autonomous_test WHERE id = 76;
532+
id | msg
533+
----+------------------------
534+
76 | package procedure test
535+
(1 row)
536+
512537
--
513538
-- Summary: Show all test results
514539
--
@@ -536,4 +561,6 @@ DROP FUNCTION outer_function(INT);
536561
DROP FUNCTION test_function_numeric(NUMERIC);
537562
DROP FUNCTION test_function_date(DATE, INT);
538563
DROP FUNCTION test_function_boolean(INT);
564+
DROP PACKAGE BODY test_pkg;
565+
DROP PACKAGE test_pkg;
539566
DROP TABLE autonomous_test;

src/pl/plisql/src/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ plisql_sources = files(
1010
'pl_subproc_function.c',
1111
'pl_package.c',
1212
'pl_exception_type.c',
13+
'pl_autonomous.c',
1314
)
1415

1516
pl_gram = custom_target('gram',

src/pl/plisql/src/sql/plisql_autonomous.sql

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,29 @@ SELECT test_function_boolean(75) AS bool_true_result;
428428
SELECT test_function_boolean(25) AS bool_false_result;
429429
SELECT id, msg FROM autonomous_test WHERE id = 55 ORDER BY id;
430430

431+
--
432+
-- Test 21: Autonomous transaction in package procedure
433+
-- Tests that PRAGMA AUTONOMOUS_TRANSACTION works inside package bodies
434+
--
435+
CREATE OR REPLACE PACKAGE test_pkg AUTHID DEFINER AS
436+
PROCEDURE pkg_test_with_params(p_id INT, p_msg TEXT);
437+
END;
438+
/
439+
440+
CREATE OR REPLACE PACKAGE BODY test_pkg AS
441+
PROCEDURE pkg_test_with_params(p_id INT, p_msg TEXT) AS
442+
PRAGMA AUTONOMOUS_TRANSACTION;
443+
BEGIN
444+
INSERT INTO autonomous_test VALUES (p_id, p_msg, 'committed');
445+
END pkg_test_with_params;
446+
END test_pkg;
447+
/
448+
449+
COMMIT;
450+
451+
CALL test_pkg.pkg_test_with_params(76, 'package procedure test');
452+
SELECT id, msg FROM autonomous_test WHERE id = 76;
453+
431454
--
432455
-- Summary: Show all test results
433456
--
@@ -451,4 +474,6 @@ DROP FUNCTION outer_function(INT);
451474
DROP FUNCTION test_function_numeric(NUMERIC);
452475
DROP FUNCTION test_function_date(DATE, INT);
453476
DROP FUNCTION test_function_boolean(INT);
477+
DROP PACKAGE BODY test_pkg;
478+
DROP PACKAGE test_pkg;
454479
DROP TABLE autonomous_test;

0 commit comments

Comments
 (0)