--freemarker template
delete from sx_captions where id like 'doku_16000%';
delete from sx_captions where id like 'doku_16020%';
delete from sx_captions where id like 'doku_16040%';
delete from sx_captions where id like 'doku_16060%';
delete from sx_captions where id like 'doku_16100%';
delete from sx_captions where id like 'doku_16120%';
delete from sx_captions where id like 'doku_16140%';
delete from sx_captions where id like 'doku_16160%';
delete from sx_captions where id like 'doku_16180%';
delete from sx_captions where id like 'doku_16200%';
delete from sx_captions where id like 'doku_16220%';
delete from sx_captions where id like 'doku_16240%';
delete from sx_captions where id like 'doku_16260%';
delete from sx_captions where id like 'doku_16280%';
delete from sx_captions where id like 'doku_16300%';
delete from sx_captions where id like 'doku_16340%';
delete from sx_captions where id like 'doku_16360%';
delete from sx_captions where id like 'doku_16380%';
delete from sx_captions where id like 'doku_16400%';
delete from sx_captions where id like 'doku_16450%';
delete from sx_captions where id like 'doku_16470%';
delete from sx_captions where id like 'doku_16490%';
delete from sx_captions where id like 'doku_16530%';
delete from sx_captions where id like 'doku_16550%';
delete from sx_captions where id like 'doku_16570%';
delete from sx_captions where id like 'doku_16590%';
delete from sx_captions where id like 'doku_16610%';
delete from sx_captions where id like 'doku_16630%';
delete from sx_captions where id like 'doku_16650%';
delete from sx_captions where id like 'doku_16690%';
delete from sx_captions where id like 'doku_16710%';
delete from sx_captions where id like 'doku_16730%';
delete from sx_captions where id like 'doku_16750%';
delete from sx_captions where id like 'doku_16770%';

delete from sx_captions where id like 'sos_doku_benutzer_url%';
delete from sx_captions where id like 'sos_doku_admin_url%';
delete from sx_captions where id like 'einzelpruefungen_doku_benutzer_url%';
delete from sx_captions where id like 'studierende_doku_benutzer_url%';
delete from sx_captions where id like 'pruefungen_doku_benutzer_url%';
delete from sx_captions where id like 'abschlusspruefungen_doku_benutzer_url%';
delete from sx_captions where id like 'sos_astat_doku_url%';


--Für Update Felderinfo mit neuen Spalten
--Prüfungen/ Studierene 120
--delete from sx_captions where table_name like 'felderinfo%' and sachgebiete_id=120;
--Abschlusspruefungen 16
--delete from sx_captions where table_name like 'felderinfo%' and sachgebiete_id=16;
--Einzelpruefungen 34
--delete from sx_captions where table_name like 'felderinfo%' and sachgebiete_id=34;

--in tmp_captions stehen release captions:
--Löschung der release captions nach id bzw. felderinfo, Feldname, tid: 
--z.B. id=sos_auslaender_w_absol
--oder table_name=felderinfo und field_name=Seit Semester
delete from tmp_captions where 
--Löschung der release captions nach id
(id is not null 
and id in (select id from sx_captions where id is not null))
--Löschung der release captions nach felderinfo, Feldname: , tid:
or (
id is null and record_no is  null and  field_name is not null and field_name in
(select field_name from sx_captions where field_name is not null
--Wenn keine record_no, dann gilt es für alle Felder mit dem Namen
and record_no is null));

--record_no abfangen, wenn vorhanden
delete from tmp_captions 
where id is null and field_name is not null 
--Wenn  record_no gefüllt:
and record_no is not null
and (trim(field_name) || record_no in (select trim(field_name) || record_no from sx_captions 
where field_name is not null
and record_no is not null));


<#if SQLdialect='Postgres'>
select sp_update_sequence('sx_captions');
</#if>

insert into sx_captions ( id,table_name,field_name,record_no,locale,contents_short,contents_long, equalitystatus,sachgebiete_id
<#if TableFieldExists?exists && TableFieldExists('sx_captions','doku_link')>
,doku_link
</#if>
<#if TableFieldExists?exists && TableFieldExists('sx_captions','export_to_glossar')>
,export_to_glossar
</#if>
)
select id,table_name,field_name,record_no,locale,contents_short,contents_long, equalitystatus,sachgebiete_id
<#if TableFieldExists?exists && TableFieldExists('sx_captions','doku_link')>
,doku_link
</#if>
<#if TableFieldExists?exists && TableFieldExists('sx_captions','export_to_glossar')>
,export_to_glossar
</#if>
from tmp_captions;

drop table tmp_captions;


