Skip to content

Commit

Permalink
Merge pull request #55 from OraMUC/development
Browse files Browse the repository at this point in the history
fixed #49, #50, #51, #52, #53
  • Loading branch information
ogobrecht authored Aug 15, 2023
2 parents 743d76d + 222f28d commit 97e6ee7
Show file tree
Hide file tree
Showing 9 changed files with 450 additions and 256 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ SIGNATURE
```sql
PACKAGE om_tapigen AUTHID CURRENT_USER IS
c_generator CONSTANT VARCHAR2(10 CHAR) := 'OM_TAPIGEN';
c_generator_version CONSTANT VARCHAR2(10 CHAR) := '0.6.2';
c_generator_version CONSTANT VARCHAR2(10 CHAR) := '0.6.3';
```


Expand Down
11 changes: 10 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Please use for all comments, discussions, feature requests or bug reports the Gi

<!-- toc -->

- [0.6.3 (2023-08-15)](#063-2023-08-15)
- [0.6.2 (2023-04-23)](#062-2023-04-23)
- [0.6.1 (2022-03-06)](#061-2022-03-06)
- [0.6.0 (2020-12-20)](#060-2020-12-20)
Expand All @@ -35,9 +36,17 @@ Please use for all comments, discussions, feature requests or bug reports the Gi

<!-- tocstop -->

## 0.6.3 (2023-08-15)

- Fixed #53: Generating default values for virtual columns - Thanks to Leon (https://github.com/ljvankempen) for reporting the issue
- Fixed #52: Error installing on oracle 23c free - Thanks to Leon (https://github.com/ljvankempen) for reporting the issue
- Fixed #51: P%COLUMN_MAPPING parameters are case sensitive- Thanks to Paolo (https://github.com/softinn72) for reporting the issue
- Fixed #50: Specifying shorter table name substitution variables in p_one_to_one_view_name generates corrupted view name - Thanks to Paolo (https://github.com/softinn72) for reporting the issue
- Fixed #49: Tenant column filter is missing from generated views - Thanks to Paolo (https://github.com/softinn72) for reporting the issue

## 0.6.2 (2023-04-23)

- Fixed: Install issue with database 23c free - Thanks to Steffen Clauß (github.com/scl-4711) for reporting the issue
- Fixed #47: Oracle 23c Free - Install-Script returns ORA-01422 - Thanks to Steffen Clauß (github.com/scl-4711) for reporting the issue

## 0.6.1 (2022-03-06)

Expand Down
103 changes: 80 additions & 23 deletions om_tapigen_install.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ begin
end if;
if to_number(v_db_version) >= 180 then
execute immediate q'[
select replace(regexp_substr(version_full, '\d+\.\d+'), '.', null) as db_version
select replace(regexp_substr(min(version_full), '\d+\.\d+'), '.', null) as db_version
from product_component_version
where product like 'Oracle Database%' ]'
into v_db_version;
Expand All @@ -36,7 +36,7 @@ end;
prompt Compile package om_tapigen (spec)
CREATE OR REPLACE PACKAGE om_tapigen AUTHID CURRENT_USER IS
c_generator CONSTANT VARCHAR2(10 CHAR) := 'OM_TAPIGEN';
c_generator_version CONSTANT VARCHAR2(10 CHAR) := '0.6.2';
c_generator_version CONSTANT VARCHAR2(10 CHAR) := '0.6.3';
/**
Oracle PL/SQL Table API Generator
=================================
Expand Down Expand Up @@ -910,7 +910,7 @@ CREATE OR REPLACE PACKAGE BODY om_tapigen IS
WHEN p_data_type = 'BLOB' THEN
'TO_BLOB(UTL_RAW.cast_to_raw(''@@@@@@@@@@@@@@@''))'
WHEN p_data_type = 'RAW' THEN
'UTL_RAW.cast_to_raw(''@@@@@@@@@@@@@@@'')'
'UTL_RAW.cast_to_raw(''@@@@@@@@@@@@@@@'')'
WHEN p_data_type = 'XMLTYPE' THEN
'XMLTYPE(''<NULL/>'')'
ELSE
Expand Down Expand Up @@ -1097,14 +1097,14 @@ CREATE OR REPLACE PACKAGE BODY om_tapigen IS

-- 1. Possible substitutions: #TABLE_NAME#, #COLUMN_PREFIX# and #PK_COLUMN# (the first column on multicolumn primary keys)
-- 2. To be backward compatible we have to support things like this #TABLE_NAME_26# (this is like substr(table_name, 1, 26))
-- 3. If someone want to use the substr version he has always to provide position and length.
-- 3. If someone want to use the substr version - please always provide position and length.
-- 4. Negative position is supported like this #TABLE_NAME_-15_15# (the second number can not be omitted like in substr, see 2.)
IF v_position IS NULL AND v_length IS NULL THEN
v_position := 1;
v_length := 200;
ELSIF v_position IS NOT NULL AND v_length IS NULL THEN
v_position := 1;
v_length := v_position; -- see point 2. above
v_position := 1;
END IF;

v_return := replace(p_name_template,
Expand Down Expand Up @@ -1839,6 +1839,32 @@ CREATE OR REPLACE PACKAGE BODY om_tapigen IS
RETURN v_result;
END list_columns_w_pk_full;

-----------------------------------------------------------------------------
/*
col1,
col2,
*/
FUNCTION list_columns_w_pk_view RETURN t_tab_list IS
v_result t_tab_list;
v_list_padding t_vc2_30;
v_index pls_integer;
BEGIN
v_list_padding := get_list_padding(6);
FOR i IN 1 .. g_columns.count LOOP
IF g_columns(i).is_hidden_yn = 'N'
AND g_columns(i).tenant_expression is null
THEN
v_index := v_result.count + 1;
v_result(v_index).col1 := v_list_padding;
v_result(v_index).col2 :=
util_double_quote(g_columns(i).column_name) ||
get_column_comment(i) ||
c_list_delimiter;
END IF;
END LOOP;
trim_list(v_result);
RETURN v_result;
END list_columns_w_pk_view;

-----------------------------------------------------------------------------
/*
Expand Down Expand Up @@ -2625,7 +2651,10 @@ CREATE OR REPLACE PACKAGE BODY om_tapigen IS
v_list_padding := get_list_padding(4);
v_operator_padding := get_operator_padding;
FOR i IN 1 .. g_columns.count LOOP
IF g_columns(i).data_default IS NOT NULL AND g_columns(i).is_hidden_yn = 'N' THEN
IF g_columns(i).data_default IS NOT NULL
AND g_columns(i).is_hidden_yn = 'N'
AND g_columns(i).is_virtual_yn = 'N'
THEN
v_index := v_result.count + 1;
v_result(v_index).col1 := v_list_padding || 'v_row.' ||
util_double_quote(g_columns(i).column_name);
Expand Down Expand Up @@ -2710,12 +2739,36 @@ CREATE OR REPLACE PACKAGE BODY om_tapigen IS

-----------------------------------------------------------------------------

FUNCTION list_where_clause_tenant_id RETURN t_tab_list IS
v_result t_tab_list;
v_index pls_integer;
BEGIN
FOR i IN 1 .. g_columns.count LOOP
IF g_columns(i).tenant_expression IS NOT NULL THEN
v_index := v_result.count + 1;
v_result(v_index).col1 := 'WHERE ';
v_result(v_index).col2 :=
util_get_attribute_compare (
p_data_type => g_columns(i).data_type,
p_nullable => util_string_to_bool(g_columns(i).is_nullable_yn),
p_first_attribute => util_double_quote(g_columns(i).column_name),
p_second_attribute => g_columns(i).tenant_expression,
p_compare_operation => '=' );
END IF;
END LOOP;
RETURN v_result;
END list_where_clause_tenant_id;

-----------------------------------------------------------------------------

BEGIN
CASE p_list_name
WHEN 'LIST_INSERT_COLUMNS' THEN
RETURN list_insert_columns;
WHEN 'LIST_COLUMNS_W_PK_FULL' THEN
RETURN list_columns_w_pk_full;
WHEN 'LIST_COLUMNS_W_PK_VIEW' THEN
RETURN list_columns_w_pk_view;
WHEN 'LIST_ROWCOLS_W_DICT_DEFAULTS' THEN
RETURN list_rowcols_w_dict_defaults;
WHEN 'LIST_ROWCOLS_W_CUST_DEFAULTS' THEN
Expand Down Expand Up @@ -2774,6 +2827,8 @@ CREATE OR REPLACE PACKAGE BODY om_tapigen IS
RETURN list_uk_map_param_eq_param;
WHEN 'LIST_SPEC_CUSTOM_DEFAULTS' THEN
RETURN list_spec_custom_defaults;
WHEN 'LIST_WHERE_CLAUSE_TENANT_ID' THEN
RETURN list_where_clause_tenant_id;
ELSE
raise_application_error(c_generator_error_number, 'FIXME: Bug - list ' || p_list_name || ' not defined');
END CASE;
Expand Down Expand Up @@ -3605,7 +3660,11 @@ CREATE OR REPLACE PACKAGE BODY om_tapigen IS
v_idx := g_columns_reverse_index(v_column_name);
g_columns(v_idx).audit_type := p_audit_type;
EXCEPTION
WHEN no_data_found THEN NULL;
WHEN no_data_found THEN
raise_application_error(c_generator_error_number,
'Invalid column name ' || v_column_name || c_lf ||
'provided for the parameter p_audit_column_mappings' || c_lf ||
'and audit type ' || p_audit_type );
WHEN others THEN raise;
END;
END IF;
Expand Down Expand Up @@ -3661,15 +3720,13 @@ CREATE OR REPLACE PACKAGE BODY om_tapigen IS
v_idx := g_columns_reverse_index(v_column_name);
g_columns(v_idx).row_version_expression := v_expression;
EXCEPTION
WHEN no_data_found THEN NULL;
WHEN no_data_found THEN
raise_application_error(c_generator_error_number,
'Invalid column name ' || v_column_name || c_lf ||
'provided for the parameter p_row_version_column_mapping.' || c_lf ||
'Example Usage: #PREFIX#_MY_COLUMN_NAME=my_version_sequence.nextval');
WHEN others THEN raise;
END;
IF v_idx IS NULL THEN
raise_application_error(c_generator_error_number,
'Invalid column name provided in the parameter' || c_lf ||
'p_row_version_column_mapping.' || c_lf ||
'Example Usage: #PREFIX#_MY_COLUMN_NAME=my_version_sequence.nextval');
END IF;
util_debug_stop_one_step;
END IF;
END IF;
Expand Down Expand Up @@ -3707,15 +3764,13 @@ CREATE OR REPLACE PACKAGE BODY om_tapigen IS
v_idx := g_columns_reverse_index(v_column_name);
g_columns(v_idx).tenant_expression := v_expression;
EXCEPTION
WHEN no_data_found THEN NULL;
WHEN no_data_found THEN
raise_application_error(c_generator_error_number,
'Invalid column name ' || v_column_name || c_lf ||
'provided for the parameter p_tenant_column_mapping.' || c_lf ||
q'[Example Usage: #PREFIX#_MY_COLUMN_NAME=to_number(sys_context('my_sec_ctx','my_tenant_id'))]');
WHEN others THEN raise;
END;
IF v_idx IS NULL THEN
raise_application_error(c_generator_error_number,
'Invalid column name provided in the parameter' || c_lf ||
'p_tenant_column_mapping.' || c_lf ||
q'[Example Usage: #PREFIX#_MY_COLUMN_NAME=to_number(sys_context('my_sec_ctx','my_tenant_id'))]');
END IF;
util_debug_stop_one_step;
END IF;
END IF;
Expand Down Expand Up @@ -5169,8 +5224,9 @@ END {{ API_NAME }};';

g_code_blocks.template := '
CREATE OR REPLACE VIEW {{ OWNER }}.{{ DML_VIEW_NAME }} AS
SELECT {% LIST_COLUMNS_W_PK_FULL %}
SELECT {% LIST_COLUMNS_W_PK_VIEW %}
FROM {{ TABLE_NAME }}
{% LIST_WHERE_CLAUSE_TENANT_ID %}
/*
This is the DML view for the table {{ TABLE_NAME }}.
- Generator: {{ GENERATOR }}
Expand Down Expand Up @@ -5238,8 +5294,9 @@ END {{ DML_VIEW_TRIGGER_NAME }};';

g_code_blocks.template := '
CREATE OR REPLACE VIEW {{ OWNER }}.{{ ONE_TO_ONE_VIEW_NAME }} AS
SELECT {% LIST_COLUMNS_W_PK_FULL %}
SELECT {% LIST_COLUMNS_W_PK_VIEW %}
FROM {{ TABLE_NAME }}
{% LIST_WHERE_CLAUSE_TENANT_ID %}
WITH READ ONLY
/*
This is the 1:1 view for the table {{ TABLE_NAME }}.
Expand Down
Loading

0 comments on commit 97e6ee7

Please sign in to comment.