diff options
author | aurynn_cmd <aurynn_cmd@4979c152-3d1c-0410-bac9-87ea11338e46> | 2008-09-23 23:23:03 +0000 |
---|---|---|
committer | aurynn_cmd <aurynn_cmd@4979c152-3d1c-0410-bac9-87ea11338e46> | 2008-09-23 23:23:03 +0000 |
commit | 0a1573bd053a30b3ba2690fcf3545be02cb2eaa8 (patch) | |
tree | e449b9d1099e01686a6059720750ccd495ec45d8 /sql | |
parent | 9937eb3c4ef04f15ceb7cd1106d6bffb10304355 (diff) |
Lots of fixes for editing users. Minor changes to Person.sql, specifically person__save_contact.
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@2339 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'sql')
-rw-r--r-- | sql/modules/Person.sql | 53 |
1 files changed, 35 insertions, 18 deletions
diff --git a/sql/modules/Person.sql b/sql/modules/Person.sql index f942b137..546398e9 100644 --- a/sql/modules/Person.sql +++ b/sql/modules/Person.sql @@ -117,32 +117,49 @@ BEGIN END; $$ LANGUAGE plpgsql; +-- + CREATE OR REPLACE FUNCTION person__save_contact -(in_entity_id int, in_contact_class int, in_contact text) +(in_entity_id int, in_contact_class int, in_contact_orig text, in_contact_new TEXT) RETURNS INT AS $$ -DECLARE out_id int; +DECLARE + out_id int; + v_orig person_to_contact; BEGIN - INSERT INTO person_to_contact(person_id, contact_class_id, contact) - SELECT id, in_contact_class, in_contact FROM person - WHERE entity_id = in_entity_id; - - RETURN 1; + + SELECT cc.* into v_orig + FROM contact_class cc, person p + WHERE p.entity_id = in_entity_id + and contact_class = in_contact_class + AND contact = in_contact_orig + AND cc.person_id = p.id; + IF NOT FOUND THEN + + -- create + INSERT INTO person_to_contact(person_id, contact_class_id, contact) + VALUES ( + (SELECT id FROM person WHERE entity_id = in_entity_id), + in_contact_class, + in_contact_new + ); + return 1; + ELSE + -- edit. + UPDATE person_to_contact + SET contact = in_contact_new + WHERE + contact = in_contact_orig + AND person_id = v_orig.person_id + AND contact_class = in_contact_class; + return 0; + END IF; + END; $$ LANGUAGE PLPGSQL; +-- -/*( - unknown, - unknown, - unknown, - unknown, - unknown, - unknown, - unknown, - unknown) - -*/ create or replace function person__save_location( in_entity_id int, in_location_id int, |