X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/cf2637263435860d7ef0fd5f5d408dc8ee1366cd..c3ab29e68cb062048266bd5a035bb68faa8d2960:/sql/Pg-upgrade2/delete_cvars_on_trans_deletion_fix2.sql

diff --git a/sql/Pg-upgrade2/delete_cvars_on_trans_deletion_fix2.sql b/sql/Pg-upgrade2/delete_cvars_on_trans_deletion_fix2.sql
new file mode 100644
index 000000000..b0e5935ad
--- /dev/null
+++ b/sql/Pg-upgrade2/delete_cvars_on_trans_deletion_fix2.sql
@@ -0,0 +1,16 @@
+-- @tag: delete_cvars_on_trans_deletion_fix2
+-- @description: Bugfix 2 fÃ¼r das LÃ¶schen von benutzerdefinierten Variablen via Triggerfunktionen
+-- @depends: delete_cvars_on_trans_deletion_fix1
+
+-- 2.1. Parametrisierte Backend-Funktion zum LÃ¶schen:
+CREATE OR REPLACE FUNCTION delete_custom_variables_with_sub_module(config_module TEXT, cvar_sub_module TEXT, old_id INTEGER)
+RETURNS BOOLEAN AS $$
+  BEGIN
+    DELETE FROM custom_variables
+    WHERE EXISTS (SELECT id FROM custom_variable_configs cfg WHERE (cfg.module = config_module) AND (custom_variables.config_id = cfg.id))
+      AND (COALESCE(sub_module, '') = cvar_sub_module)
+      AND (trans_id                 = old_id);
+
+    RETURN TRUE;
+  END;
+$$ LANGUAGE plpgsql;
