From 0e31cb7aff031c9754e5a067fff44400e297e79f Mon Sep 17 00:00:00 2001 From: Marlies Winterstein Date: Tue, 11 Feb 2025 09:31:12 +0100 Subject: [PATCH] =?UTF-8?q?Auslagerung=20Layout-Tabellen=20f=C3=BCllen=20n?= =?UTF-8?q?ach=20fm=5Ftemplates?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rpta/schluesseltabellen/fm_templates.unl | 212 ++++++++++++++++++ .../fm_templates_fuellen.sql | 14 ++ .../schluesseltabellen/fm_templates_unload.x | 11 + .../schluesseltabellen/fm_templates_update.x | 17 ++ 4 files changed, 254 insertions(+) create mode 100644 src-modules/module/rpta/schluesseltabellen/fm_templates.unl create mode 100644 src-modules/module/rpta/schluesseltabellen/fm_templates_fuellen.sql create mode 100755 src-modules/module/rpta/schluesseltabellen/fm_templates_unload.x create mode 100755 src-modules/module/rpta/schluesseltabellen/fm_templates_update.x diff --git a/src-modules/module/rpta/schluesseltabellen/fm_templates.unl b/src-modules/module/rpta/schluesseltabellen/fm_templates.unl new file mode 100644 index 0000000..d328ff8 --- /dev/null +++ b/src-modules/module/rpta/schluesseltabellen/fm_templates.unl @@ -0,0 +1,212 @@ +333^RPTA-Makros^<#macro rpta_column_layout_fuellen>\ +CREATE temp TABLE tmp_rpta_column\ +(\ + uniquename varchar(255) NOT NULL,\ + caption 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\ +);\ +\ +CREATE temp TABLE tmp_rpta_column_layout\ +(\ + uniquename varchar(255) NOT NULL,\ + caption varchar(255),\ + resultset_id integer,\ + whereclause text,\ + description text\ +);\ +\ +insert into tmp_rpta_column_layout(\ +resultset_id,\ +uniquename,\ +caption,\ +whereclause,\ + description\ +)\ +select tid,\ +'${rpta_column_layout.uniquename}',\ +'${rpta_column_layout.caption}',\ +'${rpta_column_layout.whereclause}',\ +'${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,\ + srcfieldname,\ + targetfieldname,\ + column_type,\ + col_function,\ + is_visible,\ + visible_size,\ + is_aggregate,\ + sortnr,\ + description\ + )\ +select R.tid,\ +'${column.uniquename}',\ +'${column.caption}',\ +'${column.srcfieldname}',\ +<#if !column.targetfieldname?exists || column.targetfieldname=="">null::varchar <#else>'${column.targetfieldname}' ,\ +T.tid as column_type,\ +'${column.col_function}',\ +${column.is_visible},\ +${column.visible_size},\ +${column.is_aggregate},\ +${sortnr*10},\ +'${column.description}'\ +FROM rpta_resultset R, rpta_column_type T\ +where R.uniquename='${rpta_column_layout.rpta_resultset}'\ +and T.uniquename='${column.column_type}';\ +\ +\ +\ +\ +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 * into temp tmp_rpta_column_layout_target\ +from tmp_rpta_column_layout --tmp_ eingefügt\ +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,\ + description)\ + select uniquename,\ + caption,\ + resultset_id,\ + whereclause,\ + description\ +FROM tmp_rpta_column_layout T\ +where 0=(select count(*) from tmp_rpta_column_layout_target T2\ +where T.uniquename=T2.uniquename);\ +--falls geändert, uniquename muss bleiben\ +update rpta_column_layout\ +set (caption, resultset_id, whereclause, description)\ += ( select caption, resultset_id,\ + whereclause,\ + 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)\ +select C.tid as column_id,\ + L.tid as layout_id,\ + T.sortnr,\ + T.is_visible,\ + T.visible_size,\ + T.caption,\ + T.description\ +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^ diff --git a/src-modules/module/rpta/schluesseltabellen/fm_templates_fuellen.sql b/src-modules/module/rpta/schluesseltabellen/fm_templates_fuellen.sql new file mode 100644 index 0000000..0f60d9a --- /dev/null +++ b/src-modules/module/rpta/schluesseltabellen/fm_templates_fuellen.sql @@ -0,0 +1,14 @@ + +delete from fm_templates where id in (select id from tmp_templates); + +insert into fm_templates(id, + content, + description, + comment, + version) select id, + content, + description, + comment, + version from tmp_templates; + + diff --git a/src-modules/module/rpta/schluesseltabellen/fm_templates_unload.x b/src-modules/module/rpta/schluesseltabellen/fm_templates_unload.x new file mode 100755 index 0000000..4cd8f24 --- /dev/null +++ b/src-modules/module/rpta/schluesseltabellen/fm_templates_unload.x @@ -0,0 +1,11 @@ +#!/bin/bash +#löscht alle nicht-kern-templates und entlädt die Tabelle sortiert ins Rohdaten Verzeichnis (für git-diff). + + + + +SX_CLIENT=jdbc +export SX_CLIENT +#man_catalogue +DOQUERY "select * from fm_templates where id in ('RPTA-Makros')" false $DBDELIMITER ./fm_templates.unl txt + diff --git a/src-modules/module/rpta/schluesseltabellen/fm_templates_update.x b/src-modules/module/rpta/schluesseltabellen/fm_templates_update.x new file mode 100755 index 0000000..e132b6c --- /dev/null +++ b/src-modules/module/rpta/schluesseltabellen/fm_templates_update.x @@ -0,0 +1,17 @@ +#!/bin/bash + +DOQUERY "create table tmp_templates(tid integer, + id char(200) not null, +content text not null, +description char(200) , +comment char(200) , +version integer default 1 + +) +;" + +sx_auto_upload_table.x tmp_templates ./fm_templates.unl + +DOSQL fm_templates_fuellen.sql + +DOQUERY "drop table tmp_templates;"