Guest User

Untitled

a guest
Jul 4th, 2012
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. CREATE OR REPLACE FUNCTION card_ecm_doc_roles(in_json text)
  2.   RETURNS integer AS
  3.  
  4. $BODY$
  5. #import json
  6. x=json.loads(in_json)
  7.  
  8.  if not x.get('data'):  raise Exception('Error 1')
  9.  if not x.get('doc_cardid'):  raise Exception('Error 2')
  10.  if not x.get('roleid'):  raise Exception('Error 3')
  11.  
  12.  
  13.  for userid in x ['data']:
  14.         sql="""insert into ecm.doc_bpm_roles (
  15.         doc_cardid,
  16.         roleid,
  17.         userid
  18.         ) values (
  19.         $1,
  20.         $2,
  21.         $3   
  22.         ) returning id"""
  23.  
  24.         pr=plpy.prepare(sql,["integer","integer","integer"])
  25.         result = plpy.execute(pr,[doc_cardid,roleid,userid])
  26.  
  27. return 0
  28.    
  29. $BODY$
  30.  
  31.   LANGUAGE plpythonu VOLATILE
  32.   COST 100;
  33. ALTER FUNCTION ecm.card_ecm_doc_roles(text)
  34.   OWNER TO "user";
Advertisement
Add Comment
Please, Sign In to add comment