--#SET TERMINATOR @
SET CURRENT SCHEMA LOGGER @

/**
 * Function that returns the value of the given key from the configuration
 * table.
 *
 * IN KEY
 *  Identification of the key/value parameter of the configuration table.
 * RETURNS The associated value of the given key. NULL if there is not a key
 * with that value.
 */
ALTER MODULE LOGGER ADD
  FUNCTION GET_VALUE (
  IN KEY ANCHOR CONFIGURATION.KEY
  )
  RETURNS ANCHOR CONFIGURATION.VALUE
  LANGUAGE SQL
  PARAMETER CCSID UNICODE
  SPECIFIC F_GET_VAL
  DETERMINISTIC
  NO EXTERNAL ACTION
  READS SQL DATA
  SECURED
 BEGIN
  DECLARE RET ANCHOR CONFIGURATION.KEY;
  SELECT VALUE INTO RET
    FROM CONFIGURATION C
    WHERE C.KEY = KEY
    FETCH FIRST 1 ROW ONLY;
  RETURN RET;
 END @

-- Constant logInternals
ALTER MODULE LOGGER ADD
  VARIABLE LOG_INTERNALS ANCHOR CONFIGURATION.VALUE DEFAULT (
  GET_VALUE ('logInternals')
  ) @
--#SET TERMINATOR @
SET CURRENT SCHEMA LOGGER @

/**
 * Function that returns the value of the given key from the configuration
 * table.
 *
 * IN KEY
 *  Identification of the key/value parameter of the configuration table.
 * RETURNS The associated value of the given key. NULL if there is not a key
 * with that value.
 */
ALTER MODULE LOGGER ADD
  FUNCTION GET_VALUE (
  IN GIVEN_KEY ANCHOR CONFIGURATION.KEY
  )
  RETURNS ANCHOR CONFIGURATION.VALUE
  LANGUAGE SQL
  PARAMETER CCSID UNICODE
  SPECIFIC F_GET_VAL
  NOT DETERMINISTIC
  NO EXTERNAL ACTION
  READS SQL DATA
  SECURED
 BEGIN
  DECLARE RET ANCHOR CONFIGURATION.KEY;
  SELECT C.VALUE INTO RET
    FROM CONFIGURATION C
    WHERE C.KEY = GIVEN_KEY;
  RETURN RET;
 END @

-- Constant logInternals
ALTER MODULE LOGGER ADD
  VARIABLE LOG_INTERNALS ANCHOR CONFIGURATION.KEY CONSTANT 'logInternals' @

ALTER MODULE LOGGER ADD
  VARIABLE VAL_TRUE ANCHOR CONFIGURATION.KEY CONSTANT 'true' @
Select fixed with variable, global constants
Select fixed with variable, global constants
