Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function: ecm.card_custum_declaration_save(text, text)
- -- DROP FUNCTION ecm.card_custum_declaration_save(text, text);
- CREATE OR REPLACE FUNCTION ecm.card_custum_declaration_save(uid text, in_json text)
- RETURNS integer AS
- $BODY$
- import json
- x=json.loads(in_json)
- actor = plpy.execute("select distinct(id) from ou.users usr where lower(usr.uid) = lower('" + uid + "')")
- x['actor'] = actor[0]['id']
- doc_id = plpy.execute("select ecm.card_common_save('"+uid+"','"+in_json+"') as did")
- x['doc_id_new'] = doc_id[0]['did']
- if not x.get('doc_cardid'): raise Exception('Error 1')
- if not x.get('contractorid'): raise Exception('Error 2')
- if not x.get('start_date'): raise Exception('Error 3')
- if not x.get('end_date'): raise Exception('Error 4')
- if not x.get('doc_id'):
- sql="""insert into card_custom_declarations(
- contractorid,
- start_date,
- end_date
- ) values (
- $1,
- $2,
- $3
- ) returning id"""
- pr=plpy.prepare(sql, [
- "integer", #contractorid
- "date", #start_date
- "date", #end_date
- ])
- new_id=plpy.execute(pr,[
- x['contractorid'],
- x['start_date'],
- x['end_date']
- ])
- else:
- sql="""update card_custom_declarations set
- contractorid =$1
- where start_date=$2 and end_date=$3"""
- pr = plpy.prepare(sql,[
- "integer",
- "date",
- "date"])
- plpy.execute(pr,[
- x['contractorid'],
- x['start_date'],
- x['end_date']
- ])
- return x['doc_id_new'];
- $BODY$
- LANGUAGE plpythonu VOLATILE
- COST 100;
- ALTER FUNCTION ecm.card_custum_declaration_save(text, text)
- OWNER TO "user";
Advertisement
Add Comment
Please, Sign In to add comment