diff options
Diffstat (limited to 'sql/modules/Entity.sql')
-rw-r--r-- | sql/modules/Entity.sql | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/sql/modules/Entity.sql b/sql/modules/Entity.sql new file mode 100644 index 00000000..2b5aed58 --- /dev/null +++ b/sql/modules/Entity.sql @@ -0,0 +1,41 @@ +-- +BEGIN; + +CREATE OR REPLACE FUNCTION entity_save( + in_entity_id int, in_name text, in_entity_class INT +) RETURNS INT AS $$ + + DECLARE + e entity; + e_id int; + + BEGIN + + select * into e from entity where id = in_entity_id; + + IF NOT FOUND THEN + -- do the insert magic. + e_id = nextval('entity_id_seq'); + insert into entity (id, name, entity_class) values + (e_id, + in_name, + in_entity_class + ); + return e_id; + + ELSIF FOUND THEN + + update + entity + SET + name = in_name + entity_class = in_entity_class + WHERE + id = in_entity_id; + return in_entity_id; + END IF; + END; + +$$ language 'plpgsql'; + +commit;
\ No newline at end of file |