<commit_before>--#SET TERMINATOR @

/**
 * Tests different names for loggers.
 */

SET CURRENT SCHEMA LOGGER_1A @

!db2 connect to log4db2 > NUL@
!db2 -tf CleanTriggers.sql +o@

--CREATE OR REPLACE TRIGGER T1_LOGS_UNIQUE_DATE
--  BEFORE INSERT ON LOGDATA.LOGS
--  REFERENCING NEW AS N
--  FOR EACH ROW
--  SET N.DATE = GENERATE_UNIQUE() @

CREATE OR REPLACE TRIGGER T3_EFFECTIVE_INSERT
  BEFORE INSERT ON LOGDATA.CONF_LOGGERS_EFFECTIVE
  REFERENCING NEW AS N
  FOR EACH ROW
  SET N.LOGGER_ID = NEXT VALUE FOR LOGDATA.LOGGER_ID_SEQ@

BEGIN
-- Reserved names for errors.
DECLARE SQLCODE INTEGER DEFAULT 0;
DECLARE SQLSTATE CHAR(5) DEFAULT '0000';

DECLARE STRING VARCHAR(32);
DECLARE EXPECTED_ID ANCHOR DATA TYPE TO LOGDATA.CONF_LOGGERS.LOGGER_ID;
DECLARE ACTUAL_ID ANCHOR DATA TYPE TO LOGDATA.CONF_LOGGERS.LOGGER_ID;

-- For any other SQL State.
DECLARE CONTINUE HANDLER FOR SQLWARNING
  INSERT INTO LOGDATA.LOGS (DATE, LEVEL_ID, MESSAGE) VALUES (GENERATE_UNIQUE(), 4, 'Warning SQLCode ' || SQLCODE || '-SQLState ' || SQLSTATE);
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
  INSERT INTO LOGDATA.LOGS (DATE, LEVEL_ID, MESSAGE) VALUES (GENERATE_UNIQUE(), 4, 'Exception SQLCode ' || SQLCODE || '-SQLState ' || SQLSTATE);
DECLARE CONTINUE HANDLER FOR NOT FOUND
  INSERT INTO LOGDATA.LOGS (DATE, LEVEL_ID, MESSAGE) VALUES (GENERATE_UNIQUE(), 3, 'Not found SQLCode ' || SQLCODE || '-SQLState ' || SQLSTATE);

-- Prepares the environment.
INSERT INTO LOGDATA.LOGS (DATE, LEVEL_ID, MESSAGE) VALUES (GENERATE_UNIQUE(), 3, 'TestsGetLogger: Preparing environment');
DELETE FROM LOGDATA.CONF_LOGGERS_EFFECTIVE
  WHERE LOGGER_ID <> 0;

-- Test1: empty string.
SET STRING = '';
INSERT INTO LOGDATA.LOGS (DATE, LEVEL_ID, MESSAGE) VALUES (GENERATE_UNIQUE(), 3, 'Test1: >' || STRING || '<');
SET EXPECTED_ID = 0;
CALL LOGGER.GET_LOGGER(STRING, ACTUAL_ID);
IF (EXPECTED_ID <> ACTUAL_ID) THEN<commit_msg>log levels and env<commit_after>--#SET TERMINATOR @

/**
 * Tests different names for loggers.
 */

SET CURRENT SCHEMA LOGGER_1A @

!db2 connect to log4db2 > NUL@
!db2 -tf CleanTriggers.sql +o@

--CREATE OR REPLACE TRIGGER T1_LOGS_UNIQUE_DATE
--  BEFORE INSERT ON LOGDATA.LOGS
--  REFERENCING NEW AS N
--  FOR EACH ROW
--  SET N.DATE = GENERATE_UNIQUE() @

CREATE OR REPLACE TRIGGER T3_EFFECTIVE_INSERT
  BEFORE INSERT ON LOGDATA.CONF_LOGGERS_EFFECTIVE
  REFERENCING NEW AS N
  FOR EACH ROW
  SET N.LOGGER_ID = NEXT VALUE FOR LOGDATA.LOGGER_ID_SEQ@

BEGIN
-- Reserved names for errors.
DECLARE SQLCODE INTEGER DEFAULT 0;
DECLARE SQLSTATE CHAR(5) DEFAULT '0000';

DECLARE STRING VARCHAR(32);
DECLARE EXPECTED_ID ANCHOR DATA TYPE TO LOGDATA.CONF_LOGGERS.LOGGER_ID;
DECLARE ACTUAL_ID ANCHOR DATA TYPE TO LOGDATA.CONF_LOGGERS.LOGGER_ID;

-- For any other SQL State.
DECLARE CONTINUE HANDLER FOR SQLWARNING
  INSERT INTO LOGDATA.LOGS (DATE, LEVEL_ID, MESSAGE) VALUES (GENERATE_UNIQUE(), 4, 'Warning SQLCode ' || SQLCODE || '-SQLState ' || SQLSTATE);
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
  INSERT INTO LOGDATA.LOGS (DATE, LEVEL_ID, MESSAGE) VALUES (GENERATE_UNIQUE(), 4, 'Exception SQLCode ' || SQLCODE || '-SQLState ' || SQLSTATE);
DECLARE CONTINUE HANDLER FOR NOT FOUND
  INSERT INTO LOGDATA.LOGS (DATE, LEVEL_ID, MESSAGE) VALUES (GENERATE_UNIQUE(), 5, 'Not found SQLCode ' || SQLCODE || '-SQLState ' || SQLSTATE);

-- Prepares the environment.
INSERT INTO LOGDATA.LOGS (DATE, LEVEL_ID, MESSAGE) VALUES (GENERATE_UNIQUE(), 3, 'TestsGetLogger: Preparing environment');
DELETE FROM LOGDATA.CONF_LOGGERS_EFFECTIVE
  WHERE LOGGER_ID <> 0;
UPDATE LOGDATA.CONFIGURATION
  SET VALUE = 'false'
  WHERE KEY = 'internalCache';
UPDATE LOGDATA.CONFIGURATION
  SET VALUE = 'false'
  WHERE KEY = 'logInternals';
COMMIT;

-- Test1: empty string.
SET STRING = '';
INSERT INTO LOGDATA.LOGS (DATE, LEVEL_ID, MESSAGE) VALUES (GENERATE_UNIQUE(), 3, 'Test1: >' || STRING || '<');
SET EXPECTED_ID = 0;
CALL LOGGER.GET_LOGGER(STRING, ACTUAL_ID);
IF (EXPECTED_ID <> ACTUAL_ID) THEN
{'fraction_non_alphanumeric': 0.10482233502538071, 'fraction_numerical': 0.012182741116751269, 'mean_word_length': 4.7701317715959, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4977985', 'n_tokens_mistral': 1539, 'n_tokens_neox': 1442, 'n_words': 427}