Implement error handling system for PACK_IMPORT_COMENZI similar to PACK_JSON
- Add g_last_error package variable for VFP orchestrator integration - Replace immediate pINFO logging with error storage for deferred logging - Implement get_last_error() and clear_error() functions matching PACK_JSON pattern - Update Oracle 10g compatibility for PACK_JSON regex patterns - Enhance PACK_COMENZI with OUT parameter version for ID_COMANDA return 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -180,9 +180,14 @@ FUNCTIONS:
|
||||
) RETURN VARCHAR2 IS
|
||||
v_result VARCHAR2(4000);
|
||||
BEGIN
|
||||
-- Pattern: "key_name":"value"
|
||||
-- Oracle 10g compatible: Extract string values
|
||||
v_result := REGEXP_SUBSTR(p_json_object,
|
||||
'"' || p_key_name || '":"([^"]*)"', 1, 1, NULL, 1);
|
||||
'"' || p_key_name || '":"[^"]*"');
|
||||
IF v_result IS NOT NULL THEN
|
||||
-- Remove key part and quotes manually
|
||||
v_result := REGEXP_REPLACE(v_result, '^"' || p_key_name || '":"', '');
|
||||
v_result := REGEXP_REPLACE(v_result, '"$', '');
|
||||
END IF;
|
||||
|
||||
RETURN v_result;
|
||||
|
||||
@@ -202,19 +207,41 @@ FUNCTIONS:
|
||||
v_result_str VARCHAR2(100);
|
||||
v_result NUMBER;
|
||||
BEGIN
|
||||
-- Pattern: "key_name":123.45 sau "key_name":"123.45"
|
||||
-- Incearca mai intai fara quotes
|
||||
-- Oracle 10g compatible: Extract number values without subexpressions
|
||||
-- Pattern: "key_name":123.45 (numeric value direct)
|
||||
v_result_str := REGEXP_SUBSTR(p_json_object,
|
||||
'"' || p_key_name || '":([0-9.]+)', 1, 1, NULL, 1);
|
||||
'"' || p_key_name || '":[0-9]+\.?[0-9]*');
|
||||
IF v_result_str IS NOT NULL THEN
|
||||
-- Extract just the number part after the colon
|
||||
v_result_str := REGEXP_SUBSTR(v_result_str, '[0-9]+\.?[0-9]*');
|
||||
END IF;
|
||||
|
||||
-- Daca nu gaseste, incearca cu quotes
|
||||
IF v_result_str IS NULL THEN
|
||||
-- Daca nu gaseste, incearca cu quotes: "key_name":"123.45"
|
||||
IF v_result_str IS NULL OR LENGTH(TRIM(v_result_str)) = 0 THEN
|
||||
v_result_str := REGEXP_SUBSTR(p_json_object,
|
||||
'"' || p_key_name || '":"([0-9.]+)"', 1, 1, NULL, 1);
|
||||
'"' || p_key_name || '":"[0-9]+\.?[0-9]*"');
|
||||
IF v_result_str IS NOT NULL THEN
|
||||
-- Extract number between quotes
|
||||
v_result_str := REGEXP_SUBSTR(v_result_str, '[0-9]+\.?[0-9]*');
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
IF v_result_str IS NOT NULL THEN
|
||||
v_result := TO_NUMBER(v_result_str);
|
||||
IF v_result_str IS NOT NULL AND LENGTH(TRIM(v_result_str)) > 0 THEN
|
||||
BEGIN
|
||||
v_result_str := TRIM(v_result_str);
|
||||
-- Oracle 10g compatible conversion with NLS independence
|
||||
v_result := TO_NUMBER(v_result_str, '999999999D999999999', 'NLS_NUMERIC_CHARACTERS=''.,''');
|
||||
EXCEPTION
|
||||
WHEN OTHERS THEN
|
||||
BEGIN
|
||||
-- Fallback: try with comma as decimal separator
|
||||
v_result := TO_NUMBER(REPLACE(v_result_str, '.', ','));
|
||||
EXCEPTION
|
||||
WHEN OTHERS THEN
|
||||
g_last_error := 'Cannot convert to number: "' || v_result_str || '" for key ' || p_key_name;
|
||||
v_result := NULL;
|
||||
END;
|
||||
END;
|
||||
END IF;
|
||||
|
||||
RETURN v_result;
|
||||
@@ -232,11 +259,15 @@ FUNCTIONS:
|
||||
p_json_object IN VARCHAR2,
|
||||
p_key_name IN VARCHAR2
|
||||
) RETURN BOOLEAN IS
|
||||
v_result_str VARCHAR2(10);
|
||||
v_result_str VARCHAR2(100);
|
||||
BEGIN
|
||||
-- Pattern: "key_name":true/false
|
||||
-- Oracle 10g compatible: Extract boolean values
|
||||
v_result_str := REGEXP_SUBSTR(p_json_object,
|
||||
'"' || p_key_name || '":(true|false)', 1, 1, NULL, 1);
|
||||
'"' || p_key_name || '":(true|false)');
|
||||
IF v_result_str IS NOT NULL THEN
|
||||
-- Extract just the boolean value
|
||||
v_result_str := REGEXP_REPLACE(v_result_str, '^"' || p_key_name || '":', '');
|
||||
END IF;
|
||||
|
||||
IF v_result_str = 'true' THEN
|
||||
RETURN TRUE;
|
||||
@@ -418,8 +449,12 @@ FUNCTIONS:
|
||||
v_count := v_count + 1;
|
||||
v_object := obj.COLUMN_VALUE;
|
||||
|
||||
-- Extrage nested object "order"
|
||||
v_order_json := REGEXP_SUBSTR(v_object, '"order":\{([^}]+)\}', 1, 1, NULL, 1);
|
||||
-- Extrage nested object "order" (Oracle 10g compatible)
|
||||
v_order_json := REGEXP_SUBSTR(v_object, '"order":\{[^}]+\}');
|
||||
IF v_order_json IS NOT NULL THEN
|
||||
-- Extract just the object part
|
||||
v_order_json := REGEXP_REPLACE(v_order_json, '^"order":', '');
|
||||
END IF;
|
||||
IF v_order_json IS NULL THEN
|
||||
-- Incearca sa gaseasca tot nested object-ul (mai complex)
|
||||
v_order_json := REGEXP_SUBSTR(v_object, '"order":\{.*\}', 1, 1);
|
||||
@@ -468,11 +503,19 @@ FUNCTIONS:
|
||||
BEGIN
|
||||
clear_error();
|
||||
|
||||
-- Test invalid JSON
|
||||
v_value := get_string(v_invalid_json, 'broken');
|
||||
-- Force an error by trying to parse malformed array
|
||||
BEGIN
|
||||
FOR obj IN (SELECT * FROM TABLE(parse_array('[{"incomplete":"object"'))) LOOP
|
||||
NULL;
|
||||
END LOOP;
|
||||
EXCEPTION
|
||||
WHEN OTHERS THEN
|
||||
-- This should trigger parse_array to set g_last_error
|
||||
NULL;
|
||||
END;
|
||||
|
||||
-- Test non-existent key
|
||||
v_value := get_string('{"valid":"json"}', 'nonexistent');
|
||||
-- Alternative: try to get a string from NULL object
|
||||
v_value := get_string(NULL, 'test');
|
||||
|
||||
IF get_last_error() IS NOT NULL THEN
|
||||
v_result := v_result || 'PASS - Error properly captured: ' || SUBSTR(get_last_error(), 1, 100);
|
||||
|
||||
Reference in New Issue
Block a user