369 lines
10 KiB
369 lines
10 KiB
96^RPTA-Makros^<#macro rpta_column_layout_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\ |
|
);\ |
|
\ |
|
CREATE temp TABLE tmp_rpta_column_layout\ |
|
(\ |
|
uniquename varchar(255) NOT NULL,\ |
|
caption varchar(255),\ |
|
resultset_id integer,\ |
|
whereclause text,\ |
|
sortclause text,\ |
|
description text\ |
|
);\ |
|
\ |
|
insert into tmp_rpta_column_layout(\ |
|
resultset_id,\ |
|
uniquename,\ |
|
caption,\ |
|
whereclause,\ |
|
<#if rpta_column_layout.sortclause?has_content>\ |
|
sortclause,\ |
|
</#if>\ |
|
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.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,\ |
|
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}',\ |
|
<#else>\ |
|
'${column.caption_der_spalte}',\ |
|
</#if>\ |
|
<#if column.caption_in_ergebnistabelle?exists>\ |
|
'${column.caption_in_ergebnistabelle}',\ |
|
<#else>\ |
|
'${column.caption}',\ |
|
</#if>\ |
|
'${column.srcfieldname}',\ |
|
<#if !column.targetfieldname?exists || column.targetfieldname=="">null::varchar <#else>'${column.targetfieldname}' </#if>,\ |
|
T.tid as column_type,\ |
|
<#if column.col_function?exists>'${column.col_function}'<#else>null::varchar </#if>,\ |
|
${column.is_visible},\ |
|
${column.visible_size},\ |
|
${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>,\ |
|
<#if column.description_in_ergebnistabelle?exists>'${column.description_in_ergebnistabelle}'<#elseif column.description?exists>'${column.description}'<#else>null::varchar </#if>,\ |
|
<#if column.format_code?exists>'${column.format_code}'<#else>null::varchar </#if>\ |
|
FROM rpta_resultset R, rpta_column_type T\ |
|
where R.uniquename='${rpta_column_layout.rpta_resultset}'\ |
|
and T.uniquename='${column.column_type}';\ |
|
\ |
|
</#foreach>\ |
|
\ |
|
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,\ |
|
<#if rpta_column_layout.sortclause?has_content>\ |
|
sortclause,\ |
|
</#if>\ |
|
description)\ |
|
select uniquename,\ |
|
caption,\ |
|
resultset_id,\ |
|
whereclause,\ |
|
<#if rpta_column_layout.sortclause?has_content>\ |
|
sortclause,\ |
|
</#if>\ |
|
description\ |
|
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,</#if> description)\ |
|
= ( select caption, resultset_id,\ |
|
whereclause,\ |
|
<#if rpta_column_layout.sortclause?has_content>\ |
|
sortclause,\ |
|
</#if>\ |
|
description\ |
|
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)\ |
|
;\ |
|
\ |
|
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;\ |
|
</#macro>\ |
|
\ |
|
<#macro rpta_interpret_column_layout>\ |
|
select \ |
|
--zuerst die Basisdaten:\ |
|
<#foreach column in columns>\ |
|
<#if column.coltype="physicalColumn">\ |
|
${column.srcfieldname} as ${column.srcfieldname},\ |
|
<#elseif column.coltype="logicalColumn">\ |
|
${column.colfunction} as ${column.targetfieldname},\ |
|
<#elseif column.coltype="lookupColumn">\ |
|
(${column.colfunction}) as ${column.targetfieldname},\ |
|
<#elseif column.coltype="computedColumn" || column.coltype=="processingColumn">\ |
|
null::decimal(19,6) as ${column.targetfieldname},\ |
|
</#if>\ |
|
</#foreach>\ |
|
null::char(1) as dummycol\ |
|
into temp tmp_stud\ |
|
from ${basetable.runtime_tablename}\ |
|
<#if rpta_column_layout.whereclause !="">\ |
|
where ${rpta_column_layout.whereclause}\ |
|
</#if>\ |
|
;\ |
|
\ |
|
--ergebnistabelle:\ |
|
select \ |
|
--zuerst die nicht-Aggregate:\ |
|
<#assign groupby=0 />\ |
|
<#foreach column in columns>\ |
|
-- logicalColumns ausgeschlossen, da sie von processingColumns aggregiert werden\ |
|
-- computedColumns immer mitnehmen, da später verarbeitet\ |
|
<#if (column.is_aggregate==0 && column.coltype!="logicalColumn" && column.coltype!="processingColumn") || column.coltype="computedColumn"> \ |
|
<#assign groupby=groupby+1 />\ |
|
${column.targetfieldname},\ |
|
<#elseif column.is_aggregate==0 && column.coltype="processingColumn"> \ |
|
<#assign groupby=groupby+1 />\ |
|
${column.srcfieldname} as ${column.targetfieldname},\ |
|
</#if>\ |
|
</#foreach>\ |
|
--dann die Aggregate:\ |
|
<#foreach column in columns>\ |
|
-- logicalColumns ausgeschlossen, da sie von processingColumns aggregiert werden\ |
|
-- computedColumns ausgeschlossen, da später im finalen select verarbeitet\ |
|
<#if column.is_aggregate==1 && column.coltype!="computedColumn" && column.coltype!="logicalColumn"> \ |
|
${column.colfunction}(${column.srcfieldname}) as ${column.targetfieldname},\ |
|
</#if>\ |
|
</#foreach>\ |
|
null::char(1) as dummycol\ |
|
into temp tmp_stud2\ |
|
from tmp_stud\ |
|
where 1=1\ |
|
group by\ |
|
<#list 1..groupby as i>${i}\ |
|
<#if i != groupby>\ |
|
,\ |
|
</#if>\ |
|
</#list>\ |
|
;\ |
|
--für Prozentwerte alle Aggregate summieren:\ |
|
select \ |
|
<#foreach column in columns>\ |
|
<#if column.is_aggregate==1 && column.coltype!="computedColumn" && column.coltype!="processingColumn">\ |
|
sum(${column.targetfieldname})::float as ${column.targetfieldname},\ |
|
</#if>\ |
|
</#foreach>\ |
|
null::char(1) as dummycol\ |
|
into temp tmp_gesamt\ |
|
from tmp_stud2\ |
|
where 1=1\ |
|
;\ |
|
\ |
|
<#assign number_of_visible_colums=0 />\ |
|
<#foreach column in columns>\ |
|
<#if column.is_visible!=0>\ |
|
<#assign number_of_visible_colums=number_of_visible_colums+1 />\ |
|
</#if>\ |
|
</#foreach>\ |
|
<#assign colnr=0 />\ |
|
select \ |
|
<#foreach column in columns>\ |
|
<#if column.is_visible!=0>\ |
|
<#assign colnr=colnr+1 />\ |
|
<#assign format_sql="" />\ |
|
<#if column.format_sql?string != "">\ |
|
<#assign format_sql=column.format_sql />\ |
|
</#if>\ |
|
\ |
|
<#if column.coltype=="computedColumn">\ |
|
(${column.colfunction})${format_sql} as ${column.targetfieldname}\ |
|
<#else>\ |
|
${column.targetfieldname}${format_sql} as ${column.targetfieldname}\ |
|
</#if>\ |
|
\ |
|
<#if colnr < number_of_visible_colums>,</#if>\ |
|
</#if> --wenn sichtbar\ |
|
</#foreach>\ |
|
from tmp_stud2\ |
|
order by \ |
|
<#if rpta_column_layout.sortclause !="">\ |
|
${rpta_column_layout.sortclause}\ |
|
<#else>\ |
|
<#list 1..number_of_visible_colums as i>${i}\ |
|
<#if i != number_of_visible_colums>\ |
|
,\ |
|
</#if>\ |
|
</#list>\ |
|
</#if>\ |
|
;\ |
|
\ |
|
<#if basetable.is_virtual==1>\ |
|
drop table if exists ${basetable.runtime_tablename};\ |
|
</#if>\ |
|
drop table if exists tmp_stud;\ |
|
drop table if exists tmp_stud2;\ |
|
drop table if exists tmp_gesamt;\ |
|
\ |
|
</#macro>^Makros zum Umgang mit Spaltenlayouts^^1^
|
|
|