Skip to content

Commit 128aab0

Browse files
committed
test: add regression test for SQLERRM with package EXCEPTION (IvorySQL#1151)
Add test case to verify that SQLERRM can be passed to procedures from exception handlers when the package declares user-defined EXCEPTION variables at package scope.
1 parent d13e8d6 commit 128aab0

2 files changed

Lines changed: 78 additions & 0 deletions

File tree

src/pl/plisql/src/expected/plisql_exception.out

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,45 @@ SELECT 'PRAGMA EXCEPTION_INIT negative error code tests completed' AS result;
340340
PRAGMA EXCEPTION_INIT negative error code tests completed
341341
(1 row)
342342

343+
--
344+
-- Test 12: SQLERRM in procedures when package has EXCEPTION variables (issue #1151)
345+
-- When a package declares user-defined EXCEPTION variables at package scope,
346+
-- passing SQLERRM to procedures from exception handlers should work.
347+
--
348+
CREATE OR REPLACE PACKAGE test_sqlerrm_with_exc IS
349+
my_exception EXCEPTION; -- User-defined exception at package scope
350+
PROCEDURE log_error(p_msg VARCHAR2);
351+
PROCEDURE test_sqlerrm;
352+
END test_sqlerrm_with_exc;
353+
/
354+
CREATE OR REPLACE PACKAGE BODY test_sqlerrm_with_exc IS
355+
PROCEDURE log_error(p_msg VARCHAR2) IS
356+
BEGIN
357+
RAISE INFO 'Logged: %', p_msg;
358+
END log_error;
359+
PROCEDURE test_sqlerrm IS
360+
BEGIN
361+
RAISE my_exception;
362+
EXCEPTION
363+
WHEN my_exception THEN
364+
-- This should work: passing SQLERRM to procedure
365+
log_error(SQLERRM);
366+
END test_sqlerrm;
367+
END test_sqlerrm_with_exc;
368+
/
369+
-- Test execution - this used to fail with "exception variables cannot be used in this context"
370+
BEGIN
371+
test_sqlerrm_with_exc.test_sqlerrm();
372+
END;
373+
/
374+
INFO: Logged: User-Defined Exception
375+
SELECT 'SQLERRM with package EXCEPTION test passed (issue #1151)' AS result;
376+
result
377+
----------------------------------------------------------
378+
SQLERRM with package EXCEPTION test passed (issue #1151)
379+
(1 row)
380+
381+
DROP PACKAGE test_sqlerrm_with_exc;
343382
-- Cleanup
344383
DROP PACKAGE test_pragma_init;
345384
DROP PACKAGE test_pragma_raise;

src/pl/plisql/src/sql/plisql_exception.sql

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,45 @@ END test_pragma_zero;
315315

316316
SELECT 'PRAGMA EXCEPTION_INIT negative error code tests completed' AS result;
317317

318+
--
319+
-- Test 12: SQLERRM in procedures when package has EXCEPTION variables (issue #1151)
320+
-- When a package declares user-defined EXCEPTION variables at package scope,
321+
-- passing SQLERRM to procedures from exception handlers should work.
322+
--
323+
CREATE OR REPLACE PACKAGE test_sqlerrm_with_exc IS
324+
my_exception EXCEPTION; -- User-defined exception at package scope
325+
PROCEDURE log_error(p_msg VARCHAR2);
326+
PROCEDURE test_sqlerrm;
327+
END test_sqlerrm_with_exc;
328+
/
329+
330+
CREATE OR REPLACE PACKAGE BODY test_sqlerrm_with_exc IS
331+
PROCEDURE log_error(p_msg VARCHAR2) IS
332+
BEGIN
333+
RAISE INFO 'Logged: %', p_msg;
334+
END log_error;
335+
336+
PROCEDURE test_sqlerrm IS
337+
BEGIN
338+
RAISE my_exception;
339+
EXCEPTION
340+
WHEN my_exception THEN
341+
-- This should work: passing SQLERRM to procedure
342+
log_error(SQLERRM);
343+
END test_sqlerrm;
344+
END test_sqlerrm_with_exc;
345+
/
346+
347+
-- Test execution - this used to fail with "exception variables cannot be used in this context"
348+
BEGIN
349+
test_sqlerrm_with_exc.test_sqlerrm();
350+
END;
351+
/
352+
353+
SELECT 'SQLERRM with package EXCEPTION test passed (issue #1151)' AS result;
354+
355+
DROP PACKAGE test_sqlerrm_with_exc;
356+
318357
-- Cleanup
319358
DROP PACKAGE test_pragma_init;
320359
DROP PACKAGE test_pragma_raise;

0 commit comments

Comments
 (0)