 -- Test8: Cascade call limit with error.
 INSERT INTO LOGDATA.LOGS (LEVEL_ID, MESSAGE) VALUES (3, 'Test8: Cascade call limit with error');
 SET EXPECTED = 'TRUE';
-CALL LOGGING(1, 2, 63);
+SET CASCADE = MIN_63;
+CALL LOGGING(1, 2, CASCADE);
 IF (RAISED_724 = FALSE) THEN
- INSERT INTO LOGDATA.LOGS (LEVEL_ID, MESSAGE) VALUES (3, 'Exception not raised');
+ INSERT INTO LOGDATA.LOGS (LEVEL_ID, MESSAGE) VALUES (3, 'Exception not raised LG001');
 ELSE
  INSERT INTO LOGDATA.LOGS (LEVEL_ID, MESSAGE) VALUES (5, 'Exception raised 54038');
 END IF;

-- Test17: Limit logging to ROOT with debug.
INSERT INTO LOGDATA.LOGS (LEVEL_ID, MESSAGE) VALUES (3, 'Test17: Limit logging to ROOT with debug');
SET EXPECTED = 'TRUE';
CALL LOGGING(1, 5, 60);
SELECT 'TRUE' INTO ACTUAL
  FROM LOGS
  WHERE MESSAGE = '[DEBUG] ROOT - Cascade call for "LOGGING" enters with 60';
IF (EXPECTED <> ACTUAL) THEN
 INSERT INTO LOGDATA.LOGS (LEVEL_ID, MESSAGE) VALUES (2, 'Different MESSAGE ' || EXPECTED || ' - ' || ACTUAL);
END IF;
COMMIT;

-- Test18: Limit achieved logging to ROOT with debug.
INSERT INTO LOGDATA.LOGS (LEVEL_ID, MESSAGE) VALUES (3, 'Test18: Limit achieved logging to ROOT with debug');
SET EXPECTED = 'TRUE';
DELETE FROM LOGS
  WHERE MESSAGE LIKE 'LG001. Cascade call limit achieve, for LOG: Cascade call for "LOGGING" enters w%';
CALL LOGGING(1, 5, 61);
IF (RAISED_LG001 = FALSE) THEN
 INSERT INTO LOGDATA.LOGS (LEVEL_ID, MESSAGE) VALUES (3, 'Exception not raised');
ELSE
 INSERT INTO LOGDATA.LOGS (LEVEL_ID, MESSAGE) VALUES (5, 'Exception raised LG001');
END IF;
SET RAISED_LG001 = FALSE;
SELECT 'TRUE' INTO ACTUAL
  FROM LOGS
  WHERE MESSAGE LIKE 'LG001. Cascade call limit achieve, for LOG: Cascade call for "LOGGING" enters w%';
IF (EXPECTED <> ACTUAL) THEN
 INSERT INTO LOGDATA.LOGS (LEVEL_ID, MESSAGE) VALUES (2, 'Different MESSAGE ' || EXPECTED || ' - ' || ACTUAL);
END IF;

-- Test1: Limit logging to ROOT with fatal.
INSERT INTO LOGDATA.LOGS (LEVEL_ID, MESSAGE) VALUES (3, 'Test1: Limit logging to ROOT with fatal');
SET EXPECTED = 'TRUE';
SET CASCADE = VAL_62;
CALL LOGGING(1, 1, CASCADE);
SELECT 'TRUE' INTO ACTUAL
  FROM LOGS
  WHERE MESSAGE = 'LG001. Cascade call limit achieved, for FATAL: (0) Cascade call for "LOGGING" enters with ' || CASCADE
  AND DATE = (SELECT MAX(DATE) FROM LOGDATA.LOGS);
IF (ACTUAL IS NULL OR EXPECTED <> ACTUAL) THEN
 INSERT INTO LOGDATA.LOGS (LEVEL_ID, MESSAGE) VALUES (2, 'Different MESSAGE ' || EXPECTED || ' - ' || COALESCE(ACTUAL, 'NULL'));
END IF;
COMMIT;

-- Test2: Limit achieved logging to ROOT with fatal.
INSERT INTO LOGDATA.LOGS (LEVEL_ID, MESSAGE) VALUES (3, 'Test2: Limit achieved logging to ROOT with fatal');
SET EXPECTED = 'TRUE';
SET CASCADE = MIN_61A;
CALL LOGGING(1, 1, CASCADE);
IF (RAISED_LG001 = FALSE) THEN
 INSERT INTO LOGDATA.LOGS (LEVEL_ID, MESSAGE) VALUES (3, 'Exception not raised LG001');
ELSE
 INSERT INTO LOGDATA.LOGS (LEVEL_ID, MESSAGE) VALUES (5, 'Exception raised LG001');
END IF;
SET RAISED_LG001 = FALSE;
SELECT 'TRUE' INTO ACTUAL
  FROM LOGS
  WHERE MESSAGE LIKE 'LG001. Cascade call limit achieved, for LOG: Cascade call for "LOGGING" enters w%'
  AND DATE = (SELECT MAX(DATE) FROM LOGDATA.LOGS)
  AND LEVEL_ID = 1;
IF (EXPECTED <> ACTUAL) THEN
 INSERT INTO LOGDATA.LOGS (LEVEL_ID, MESSAGE) VALUES (2, 'Different MESSAGE ' || EXPECTED || ' - ' || ACTUAL);
END IF;
