Guest User

Untitled

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