diff --git a/src-modules/module/rpta/schluesseltabellen/fm_templates.unl b/src-modules/module/rpta/schluesseltabellen/fm_templates.unl index ddd62a2..9edc659 100644 --- a/src-modules/module/rpta/schluesseltabellen/fm_templates.unl +++ b/src-modules/module/rpta/schluesseltabellen/fm_templates.unl @@ -393,4 +393,411 @@ drop TABLE tmp_rpta_column2layout;\ drop table if exists tmp_stud2;\ drop table if exists tmp_gesamt;\ \ -^Makros zum Umgang mit Spaltenlayouts^^1^ +\ +\ +<#macro rpta_column_fuellen>\ +CREATE temp TABLE tmp_rpta_column\ +(\ + uniquename varchar(255) NOT NULL,\ + caption varchar(255),\ + caption_in_ergebnistabelle varchar(255),\ + srcfieldname varchar(255),\ + targetfieldname varchar(255),\ + column_type integer,\ + col_function text,\ + is_visible smallint,\ + visible_size smallint,\ + is_aggregate smallint,\ + resultset_id integer,\ + sortnr integer,\ + description TEXT,\ + description_in_ergebnistabelle TEXT,\ + format_code_uniquename varchar(255),\ + format_code_id integer\ +);\ +\ +<#assign sortnr=0 />\ +<#foreach column in rpta_columns>\ +<#assign sortnr=sortnr +1 />\ +\ +INSERT INTO tmp_rpta_column\ +(resultset_id,\ + uniquename,\ + caption,\ + srcfieldname,\ + targetfieldname,\ + column_type,\ + col_function,\ + is_visible,\ + visible_size,\ + is_aggregate,\ + sortnr,\ + description,\ + format_code_uniquename\ + )\ +select R.tid,\ +'${column.uniquename}',\ +<#if column.caption?exists>\ +'${column.caption}',\ +<#else>\ +'${column.caption_der_spalte}',\ +\ +'${column.srcfieldname}',\ +<#if !column.targetfieldname?exists || column.targetfieldname=="">'${column.srcfieldname}' <#else>'${column.targetfieldname}' ,\ +T.tid as column_type,\ +<#if column.col_function?exists>'${column.col_function}'<#else>null::varchar ,\ +0,\ +0,\ +${column.is_aggregate},\ +${sortnr*10},\ +<#if column.description?exists>'${column.description}'<#elseif column.description_der_spalte?exists>'${column.description_der_spalte}'<#else>null::varchar ,\ +<#if column.format_code?exists>'${column.format_code}'<#else>null::varchar \ +FROM rpta_resultset R, rpta_column_type T\ +where R.uniquename='${rpta_column_resultset.rpta_resultset}'\ +and T.uniquename='${column.column_type}';\ +\ +\ +\ +update tmp_rpta_column set format_code_id=C.tid\ +from rpta_format_code C\ +where C.uniquename=tmp_rpta_column.format_code_uniquename\ +and format_code_uniquename is not null;\ +\ +\ +select * into temp tmp_rpta_column2 \ +from tmp_rpta_column T \ +where (resultset_id,uniquename) not in\ +(select resultset_id,uniquename from rpta_column);\ +\ +INSERT INTO rpta_column\ +(resultset_id,\ + uniquename,\ + caption,\ + srcfieldname,\ + targetfieldname,\ + column_type,\ + col_function,\ + is_aggregate,\ + description,\ + custom\ + )\ + select \ +resultset_id,\ + uniquename,\ + caption,\ + srcfieldname,\ + targetfieldname,\ + column_type,\ + col_function,\ + is_aggregate,\ + description,\ + 0 as custom\ +from tmp_rpta_column2; \ +\ +--evtl. neuen Satz einfügen, dann alle updaten\ +\ +update rpta_column set ( caption,\ + srcfieldname,\ + targetfieldname,\ + column_type,\ + col_function,\ + is_aggregate,\ + description)\ + = (select caption,\ + srcfieldname,\ + targetfieldname,\ + column_type,\ + col_function,\ + is_aggregate,\ + description\ + from tmp_rpta_column T\ + where T.resultset_id=rpta_column.resultset_id\ + and T.uniquename=rpta_column.uniquename)\ + where custom=0\ + and (resultset_id,uniquename) in\ +(select T.resultset_id,T.uniquename\ +from tmp_rpta_column T)\ +;\ +\ +drop table tmp_rpta_column2;\ +\ +drop table tmp_rpta_column;\ +\ +\ +<#macro rpta_column2layout_fuellen>\ +CREATE temp TABLE tmp_rpta_column\ +(\ + uniquename varchar(255) NOT NULL,\ + caption varchar(255),\ + caption_in_ergebnistabelle varchar(255),\ + srcfieldname varchar(255),\ + targetfieldname varchar(255),\ + column_type_u varchar(255),\ + column_type integer,\ + col_function text,\ + is_visible smallint,\ + visible_size smallint,\ + is_aggregate smallint,\ + resultset_id integer,\ + sortnr integer,\ + description TEXT,\ + description_in_ergebnistabelle TEXT,\ + format_code_uniquename varchar(255),\ + format_code_id integer\ +);\ +\ +CREATE temp TABLE tmp_rpta_column_layout\ +(\ + uniquename varchar(255) NOT NULL,\ + caption varchar(255),\ + resultset_id integer,\ + whereclause text,\ + sortclause text,\ + description text,\ + is_virtual smallint default 1\ +);\ +\ +insert into tmp_rpta_column_layout(\ +resultset_id,\ +uniquename,\ +caption,\ +whereclause,\ +<#if rpta_column_layout.sortclause?has_content>\ +sortclause,\ +\ +<#if rpta_column_layout.is_virtual?has_content>\ + is_virtual,\ +\ + description\ +)\ +select tid,\ +'${rpta_column_layout.uniquename}',\ +'${rpta_column_layout.caption}',\ +'${rpta_column_layout.whereclause}',\ +<#if rpta_column_layout.sortclause?has_content>\ +'${rpta_column_layout.sortclause}',\ +\ +<#if rpta_column_layout.is_virtual?has_content>\ +'${rpta_column_layout.is_virtual}',\ +\ +'${rpta_column_layout.description}'\ +FROM rpta_resultset\ +where uniquename='${rpta_column_layout.rpta_resultset}';\ +\ +<#assign sortnr=0 />\ +<#foreach column in rpta_columns>\ +<#assign sortnr=sortnr +1 />\ +\ +INSERT INTO tmp_rpta_column\ +(resultset_id,\ + uniquename,\ + caption,\ + caption_in_ergebnistabelle,\ + srcfieldname,\ + targetfieldname,\ + column_type_u,\ + col_function,\ + is_visible,\ + visible_size,\ + is_aggregate,\ + sortnr,\ + description,\ + description_in_ergebnistabelle,\ + format_code_uniquename\ + )\ +select R.tid,\ +'${column.uniquename}',\ +<#if column.caption?exists>\ +'${column.caption}'\ +<#elseif column.caption_der_spalte?exists>\ +'${column.caption_der_spalte}'\ +<#else> null::varchar\ +,\ +<#if column.caption_in_ergebnistabelle?exists>\ +'${column.caption_in_ergebnistabelle}'\ +<#else> null::varchar\ +,\ +<#if column.srcfieldname?exists> '${column.srcfieldname}' <#else>null::varchar ,\ +<#if column.srcfieldname?exists>\ +<#if !column.targetfieldname?exists || column.targetfieldname=="">'${column.srcfieldname}' <#else>'${column.targetfieldname}' \ +<#else> null::varchar ,\ +<#if column.column_type?exists> '${column.column_type}' <#else> null::varchar ,\ +<#if column.col_function?exists>'${column.col_function}'<#else>null::varchar ,\ +${column.is_visible},\ +${column.visible_size},\ +<#if column.is_aggregate?exists> ${column.is_aggregate} <#else>null ,\ +${sortnr*10},\ +<#if column.description?exists>'${column.description}'<#elseif column.description_der_spalte?exists>'${column.description_der_spalte}'<#else>null::varchar ,\ +<#if column.description_in_ergebnistabelle?exists>'${column.description_in_ergebnistabelle}'<#elseif column.description?exists>'${column.description}'<#else>null::varchar ,\ +<#if column.format_code?exists>'${column.format_code}'<#else>null::varchar \ +FROM rpta_resultset R \ +where R.uniquename='${rpta_column_layout.rpta_resultset}';\ +\ +\ +\ +\ +update tmp_rpta_column set column_type=C.tid\ +from rpta_column_type C\ +where C.uniquename=tmp_rpta_column.column_type_u;\ +\ +\ +update tmp_rpta_column set format_code_id=C.tid\ +from rpta_format_code C\ +where C.uniquename=tmp_rpta_column.format_code_uniquename\ +and format_code_uniquename is not null;\ +\ +\ +select * into temp tmp_rpta_column2layout\ +from rpta_column2layout\ +where layout_id in (select L.tid\ +from rpta_column_layout L,rpta_resultset R\ +where R.tid=L.resultset_id \ +and R.uniquename='${rpta_column_layout.rpta_resultset}'\ +and L.uniquename='${rpta_column_layout.uniquename}'\ +)\ +; \ + \ +select uniquename into temp tmp_rpta_column_layout_target\ +from rpta_column_layout\ +where resultset_id in (select tid\ +FROM rpta_resultset\ +where uniquename='${rpta_column_layout.rpta_resultset}')\ +and uniquename in (select uniquename from tmp_rpta_column_layout)\ +;\ +--falls neu\ +insert into rpta_column_layout\ +(uniquename,\ + caption,\ + resultset_id,\ + whereclause,\ + sortclause,\ + description,\ + is_virtual)\ + select uniquename,\ + caption,\ + resultset_id,\ + whereclause,\ + <#if rpta_column_layout.sortclause?has_content>\ + sortclause,\ + <#else>\ + null::text as sortclause,\ + \ + description,\ + is_virtual\ +FROM tmp_rpta_column_layout T\ +where not exists (select uniquename from tmp_rpta_column_layout_target);\ +\ +--falls geändert, uniquename muss bleiben\ +update rpta_column_layout\ +--set (caption, resultset_id, whereclause,<#if rpta_column_layout.sortclause?has_content>sortclause, description, is_virtual)\ +set (caption, resultset_id, whereclause,sortclause, description, is_virtual)\ += ( select caption, resultset_id,\ + whereclause,\ + <#if rpta_column_layout.sortclause?has_content>\ + sortclause,\ + <#else>\ + null::text as sortclause,\ + \ + description,\ + is_virtual\ +FROM tmp_rpta_column_layout T\ +where T.uniquename=rpta_column_layout.uniquename)\ +where rpta_column_layout.uniquename=(select uniquename from tmp_rpta_column_layout);\ +\ +drop table tmp_rpta_column_layout_target;\ +\ +delete from rpta_column2layout\ +where layout_id in (select L.tid\ +from rpta_column_layout L,rpta_resultset R\ +where R.tid=L.resultset_id \ +and R.uniquename='${rpta_column_layout.rpta_resultset}'\ +and L.uniquename='${rpta_column_layout.uniquename}'\ +)\ +; \ +\ +select * into temp tmp_rpta_column2 \ +from tmp_rpta_column T \ +where (resultset_id,uniquename) not in\ +(select resultset_id,uniquename from rpta_column);\ +\ +INSERT INTO rpta_column\ +(resultset_id,\ + uniquename,\ + caption,\ + srcfieldname,\ + targetfieldname,\ + column_type,\ + col_function,\ + is_aggregate,\ + description,\ + custom\ + )\ + select \ +resultset_id,\ + uniquename,\ + caption,\ + srcfieldname,\ + targetfieldname,\ + column_type,\ + col_function,\ + is_aggregate,\ + description,\ + 0 as custom\ +from tmp_rpta_column2; \ +\ +--evtl. neuen Satz einfügen, dann alle updaten\ +\ +update rpta_column set ( caption,\ + srcfieldname,\ + targetfieldname,\ + column_type,\ + col_function,\ + is_aggregate,\ + description)\ + = (select caption,\ + srcfieldname,\ + targetfieldname,\ + column_type,\ + col_function,\ + is_aggregate,\ + description\ + from tmp_rpta_column T\ + where T.resultset_id=rpta_column.resultset_id\ + and T.uniquename=rpta_column.uniquename)\ + where custom=0\ + and (resultset_id,uniquename) in\ +(select T.resultset_id,T.uniquename\ +from tmp_rpta_column T\ +--nur die aus diesem Durchgang\ +where T.description is not null\ +)\ +;\ +\ +drop table tmp_rpta_column2;\ +\ +insert into rpta_column2layout(column_id,\ + layout_id,\ + sortnr,\ + is_visible,\ + visible_size,\ + caption,\ + description,\ + format_code_id)\ +select C.tid as column_id,\ + L.tid as layout_id,\ + T.sortnr,\ + T.is_visible,\ + T.visible_size,\ + T.caption_in_ergebnistabelle,\ + T.description_in_ergebnistabelle,\ + T.format_code_id\ +FROM rpta_column C, rpta_column_layout L, tmp_rpta_column T\ +where C.uniquename=T.uniquename\ +and C.resultset_id=T.resultset_id\ +and L.uniquename='${rpta_column_layout.uniquename}'\ +and L.resultset_id=T.resultset_id\ + ;\ +drop table tmp_rpta_column;\ +drop TABLE tmp_rpta_column_layout;\ +drop TABLE tmp_rpta_column2layout;\ +^Makros zum Umgang mit Spaltenlayouts^ ^1^