[Formed-commits] r329 - in trunk: . formed/formed/plugins/export
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Apr 28 12:06:32 CEST 2009
Author: teichmann
Date: 2009-04-28 12:06:31 +0200 (Tue, 28 Apr 2009)
New Revision: 329
Modified:
trunk/ChangeLog
trunk/formed/formed/plugins/export/rg_sql.py
Log:
Added delete functions for repeat group SQL generator.
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2009-04-27 14:54:41 UTC (rev 328)
+++ trunk/ChangeLog 2009-04-28 10:06:31 UTC (rev 329)
@@ -1,5 +1,10 @@
-2009-04-24 Sascha L. Teichmann <teichmann at intevation.de>
+2009-04-28 Sascha L. Teichmann <teichmann at intevation.de>
+ * formed/formed/plugins/export/rg_sql.py: Added delete functions.
+ TODO: Adjust execution rights.
+
+2009-04-27 Sascha L. Teichmann <teichmann at intevation.de>
+
* formed/formed/plugins/export/rg_sql.py: Fixed $$$$ -> $$ template problems.
Add functions to create dataset.
Modified: trunk/formed/formed/plugins/export/rg_sql.py
===================================================================
--- trunk/formed/formed/plugins/export/rg_sql.py 2009-04-27 14:54:41 UTC (rev 328)
+++ trunk/formed/formed/plugins/export/rg_sql.py 2009-04-28 10:06:31 UTC (rev 329)
@@ -203,6 +203,23 @@
RETURN rid;
END;
$$$$;
+
+CREATE OR REPLACE FUNCTION delete_${RELATION}(rid integer)
+RETURNS void
+LANGUAGE 'plpgsql' VOLATILE EXTERNAL SECURITY DEFINER AS
+$$$$
+DECLARE
+ mid integer;
+BEGIN
+ ${SELECT_MASTER_ID_DELETE}
+
+ IF NOT isEditorOrStandin(mid) THEN
+ RAISE EXCEPTION 'DS ID not session_user ID';
+ END IF;
+
+ DELETE FROM ${RELATION} WHERE id = rid;
+END;
+$$$$;
''')
CREATE_DELETE_MASTER_TMPL = Template('''
@@ -236,6 +253,23 @@
RETURN rid;
END;
$$$$;
+
+CREATE OR REPLACE FUNCTION delete_master_tbl(mid integer) RETURNS void
+ LANGUAGE 'plpgsql' VOLATILE EXTERNAL SECURITY DEFINER
+ AS $$$$
+DECLARE
+ st integer;
+BEGIN
+ SELECT INTO st s.status FROM master_tbl m JOIN ka_status_tbl s
+ ON s.master_id = m.id WHERE m.id = mid;
+
+ IF NOT st in (3, 5) THEN
+ RAISE EXCEPTION 'case is not deletable';
+ END IF;
+
+ DELETE FROM master_tbl WHERE id = mid;
+END;
+$$$$;
''')
class RGNode(object):
@@ -277,6 +311,8 @@
else:
if self.parent.name == "master_tbl":
select_master = "mid := pid;"
+ select_master_delete = "SELECT INTO mid master_id FROM %s WHERE id = rid;" % \
+ self.name;
else:
cout = ["SELECT INTO mid master_tbl.id FROM"]
current = self.parent
@@ -291,10 +327,24 @@
select_master = "\n ".join(cout)
+ cout = ["SELECT INTO mid master_tbl.id FROM %s" % self.name]
+ current = self
+ while current.parent:
+ cout.append("INNER JOIN %(parent)s ON %(current)s.master_id = %(parent)s.id" % {
+ 'current': current.name,
+ 'parent' : current.parent.name
+ })
+ current = current.parent
+
+ cout.append("WHERE %s.id = rid;" % self.name)
+
+ select_master_delete = "\n ".join(cout);
+
out.append(CREATE_DELETE_TMPL.safe_substitute({
- 'RELATION' : self.name,
- 'CREATE_CHILDREN' : create_children,
- 'SELECT_MASTER_ID': select_master
+ 'RELATION' : self.name,
+ 'CREATE_CHILDREN' : create_children,
+ 'SELECT_MASTER_ID' : select_master,
+ 'SELECT_MASTER_ID_DELETE': select_master_delete
}))
for child in self.children:
@@ -424,5 +474,4 @@
try: f.close()
except: pass
-
# vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 enc=utf-8:
More information about the Formed-commits
mailing list