-- ============================================================
-- 49_permission_static_sql_condition.sql
--
-- Makes room for a literal, static WHERE condition attached to an
-- allowlisted permission rule.  The VPD function validates the expression
-- again before returning it as part of a predicate.
-- ============================================================
WHENEVER SQLERROR EXIT SQL.SQLCODE
SET ECHO OFF
SET FEEDBACK ON
SET DEFINE OFF

PROMPT === Enlarging rule value for static SQL conditions ===
DECLARE
  v_data_length NUMBER;
BEGIN
  SELECT data_length
  INTO   v_data_length
  FROM   user_tab_columns
  WHERE  table_name = 'CB_PERMISSION_RULE'
  AND    column_name = 'RULE_VALUE';

  IF v_data_length < 1000 THEN
    EXECUTE IMMEDIATE
      'ALTER TABLE cb_permission_rule MODIFY (rule_value VARCHAR2(1000 CHAR))';
  END IF;
END;
/

SELECT column_name, data_type, char_length
FROM user_tab_columns
WHERE table_name = 'CB_PERMISSION_RULE'
  AND column_name = 'RULE_VALUE';

PROMPT === Static SQL condition storage ready ===
