diff options
| author | Christophe Simonis <christophe@tinyerp.com> | 2008-12-09 13:37:22 +0100 |
|---|---|---|
| committer | Christophe Simonis <christophe@tinyerp.com> | 2008-12-09 13:37:22 +0100 |
| commit | c2cc3a304996fd1a7208b8e0570eef435682e75f (patch) | |
| tree | 44886a3b2b0bcddb301ab5890648d7c79a214d64 /bin/workflow | |
| parent | b2f82b8bd636a3be14315729c8d2f08f67875553 (diff) | |
[FIX] psycopg2: in queries we must now use %s everywhere (no more %d or %f)
bzr revid: christophe@tinyerp.com-20081209123722-4kmv4pecjwiw3tm3
Diffstat (limited to 'bin/workflow')
| -rw-r--r-- | bin/workflow/instance.py | 22 | ||||
| -rw-r--r-- | bin/workflow/wkf_logs.py | 2 | ||||
| -rw-r--r-- | bin/workflow/wkf_service.py | 16 | ||||
| -rw-r--r-- | bin/workflow/workitem.py | 42 |
4 files changed, 41 insertions, 41 deletions
diff --git a/bin/workflow/instance.py b/bin/workflow/instance.py index 9521135a0e8..ce9dfdd0c6a 100644 --- a/bin/workflow/instance.py +++ b/bin/workflow/instance.py @@ -30,8 +30,8 @@ def create(cr, ident, wkf_id): (uid,res_type,res_id) = ident cr.execute("select nextval('wkf_instance_id_seq')") id_new = cr.fetchone()[0] - cr.execute('insert into wkf_instance (id,res_type,res_id,uid,wkf_id) values (%d,%s,%s,%s,%s)', (id_new,res_type,res_id,uid,wkf_id)) - cr.execute('select * from wkf_activity where flow_start=True and wkf_id=%d', (wkf_id,)) + cr.execute('insert into wkf_instance (id,res_type,res_id,uid,wkf_id) values (%s,%s,%s,%s,%s)', (id_new,res_type,res_id,uid,wkf_id)) + cr.execute('select * from wkf_activity where flow_start=True and wkf_id=%s', (wkf_id,)) res = cr.dictfetchall() stack = [] workitem.create(cr, res, id_new, ident, stack=stack) @@ -40,10 +40,10 @@ def create(cr, ident, wkf_id): def delete(cr, ident): (uid,res_type,res_id) = ident - cr.execute('delete from wkf_instance where res_id=%d and res_type=%s', (res_id,res_type)) + cr.execute('delete from wkf_instance where res_id=%s and res_type=%s', (res_id,res_type)) def validate(cr, inst_id, ident, signal, force_running=False): - cr.execute("select * from wkf_workitem where inst_id=%d", (inst_id,)) + cr.execute("select * from wkf_workitem where inst_id=%s", (inst_id,)) for witem in cr.dictfetchall(): stack = [] workitem.process(cr, witem, ident, signal, force_running, stack=stack) @@ -52,27 +52,27 @@ def validate(cr, inst_id, ident, signal, force_running=False): return stack and stack[0] or False def update(cr, inst_id, ident): - cr.execute("select * from wkf_workitem where inst_id=%d", (inst_id,)) + cr.execute("select * from wkf_workitem where inst_id=%s", (inst_id,)) for witem in cr.dictfetchall(): stack = [] workitem.process(cr, witem, ident, stack=stack) return _update_end(cr, inst_id, ident) def _update_end(cr, inst_id, ident): - cr.execute('select wkf_id from wkf_instance where id=%d', (inst_id,)) + cr.execute('select wkf_id from wkf_instance where id=%s', (inst_id,)) wkf_id = cr.fetchone()[0] - cr.execute('select state,flow_stop from wkf_workitem w left join wkf_activity a on (a.id=w.act_id) where w.inst_id=%d', (inst_id,)) + cr.execute('select state,flow_stop from wkf_workitem w left join wkf_activity a on (a.id=w.act_id) where w.inst_id=%s', (inst_id,)) ok=True for r in cr.fetchall(): if (r[0]<>'complete') or not r[1]: ok=False break if ok: - cr.execute('select distinct a.name from wkf_activity a left join wkf_workitem w on (a.id=w.act_id) where w.inst_id=%d', (inst_id,)) + cr.execute('select distinct a.name from wkf_activity a left join wkf_workitem w on (a.id=w.act_id) where w.inst_id=%s', (inst_id,)) act_names = cr.fetchall() - cr.execute("update wkf_instance set state='complete' where id=%d", (inst_id,)) - cr.execute("update wkf_workitem set state='complete' where subflow_id=%d", (inst_id,)) - cr.execute("select i.id,w.osv,i.res_id from wkf_instance i left join wkf w on (i.wkf_id=w.id) where i.id in (select inst_id from wkf_workitem where subflow_id=%d)", (inst_id,)) + cr.execute("update wkf_instance set state='complete' where id=%s", (inst_id,)) + cr.execute("update wkf_workitem set state='complete' where subflow_id=%s", (inst_id,)) + cr.execute("select i.id,w.osv,i.res_id from wkf_instance i left join wkf w on (i.wkf_id=w.id) where i.id in (select inst_id from wkf_workitem where subflow_id=%s)", (inst_id,)) for i in cr.fetchall(): for act_name in act_names: validate(cr, i[0], (ident[0],i[1],i[2]), 'subflow.'+act_name[0]) diff --git a/bin/workflow/wkf_logs.py b/bin/workflow/wkf_logs.py index 6dbf0ef48ef..17e3bfb1471 100644 --- a/bin/workflow/wkf_logs.py +++ b/bin/workflow/wkf_logs.py @@ -26,7 +26,7 @@ def log(cr,ident,act_id,info=''): pass - #cr.execute('insert into wkf_logs (res_type, res_id, uid, act_id, time, info) values (%s,%d,%d,%d,current_time,%s)', (ident[1],int(ident[2]),int(ident[0]),int(act_id),info)) + #cr.execute('insert into wkf_logs (res_type, res_id, uid, act_id, time, info) values (%s,%s,%s,%s,current_time,%s)', (ident[1],int(ident[2]),int(ident[0]),int(act_id),info)) # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/bin/workflow/wkf_service.py b/bin/workflow/wkf_service.py index 1ac88015d0b..598bf8ac9cf 100644 --- a/bin/workflow/wkf_service.py +++ b/bin/workflow/wkf_service.py @@ -44,15 +44,15 @@ class workflow_service(netsvc.Service): def trg_write(self, uid, res_type, res_id, cr): ident = (uid,res_type,res_id) - cr.execute('select id from wkf_instance where res_id=%d and res_type=%s and state=%s', (res_id,res_type, 'active')) + cr.execute('select id from wkf_instance where res_id=%s and res_type=%s and state=%s', (res_id,res_type, 'active')) for (id,) in cr.fetchall(): instance.update(cr, id, ident) def trg_trigger(self, uid, res_type, res_id, cr): - cr.execute('select instance_id from wkf_triggers where res_id=%d and model=%s', (res_id,res_type)) + cr.execute('select instance_id from wkf_triggers where res_id=%s and model=%s', (res_id,res_type)) res = cr.fetchall() for (instance_id,) in res: - cr.execute('select uid,res_type,res_id from wkf_instance where id=%d', (instance_id,)) + cr.execute('select uid,res_type,res_id from wkf_instance where id=%s', (instance_id,)) ident = cr.fetchone() instance.update(cr, instance_id, ident) @@ -76,7 +76,7 @@ class workflow_service(netsvc.Service): result = False ident = (uid,res_type,res_id) # ids of all active workflow instances for a corresponding resource (id, model_nam) - cr.execute('select id from wkf_instance where res_id=%d and res_type=%s and state=%s', (res_id, res_type, 'active')) + cr.execute('select id from wkf_instance where res_id=%s and res_type=%s and state=%s', (res_id, res_type, 'active')) for (id,) in cr.fetchall(): res2 = instance.validate(cr, id, ident, signal) result = result or res2 @@ -88,21 +88,21 @@ class workflow_service(netsvc.Service): def trg_redirect(self, uid, res_type, res_id, new_rid, cr): # get ids of wkf instances for the old resource (res_id) #CHECKME: shouldn't we get only active instances? - cr.execute('select id, wkf_id from wkf_instance where res_id=%d and res_type=%s', (res_id, res_type)) + cr.execute('select id, wkf_id from wkf_instance where res_id=%s and res_type=%s', (res_id, res_type)) for old_inst_id, wkf_id in cr.fetchall(): # first active instance for new resource (new_rid), using same wkf cr.execute( 'SELECT id '\ 'FROM wkf_instance '\ - 'WHERE res_id=%d AND res_type=%s AND wkf_id=%d AND state=%s', + 'WHERE res_id=%s AND res_type=%s AND wkf_id=%s AND state=%s', (new_rid, res_type, wkf_id, 'active')) new_id = cr.fetchone() if new_id: # select all workitems which "wait" for the old instance - cr.execute('select id from wkf_workitem where subflow_id=%d', (old_inst_id,)) + cr.execute('select id from wkf_workitem where subflow_id=%s', (old_inst_id,)) for (item_id,) in cr.fetchall(): # redirect all those workitems to the wkf instance of the new resource - cr.execute('update wkf_workitem set subflow_id=%d where id=%d', (new_id[0], item_id)) + cr.execute('update wkf_workitem set subflow_id=%s where id=%s', (new_id[0], item_id)) workflow_service() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/bin/workflow/workitem.py b/bin/workflow/workitem.py index 8757fd9024c..6f41bc9602c 100644 --- a/bin/workflow/workitem.py +++ b/bin/workflow/workitem.py @@ -22,7 +22,7 @@ # # TODO: -# cr.execute('delete from wkf_triggers where model=%s and res_id=%d', (res_type,res_id)) +# cr.execute('delete from wkf_triggers where model=%s and res_id=%s', (res_type,res_id)) # import netsvc @@ -35,8 +35,8 @@ def create(cr, act_datas, inst_id, ident, stack): for act in act_datas: cr.execute("select nextval('wkf_workitem_id_seq')") id_new = cr.fetchone()[0] - cr.execute("insert into wkf_workitem (id,act_id,inst_id,state) values (%d,%s,%s,'active')", (id_new, act['id'], inst_id)) - cr.execute('select * from wkf_workitem where id=%d',(id_new,)) + cr.execute("insert into wkf_workitem (id,act_id,inst_id,state) values (%s,%s,%s,'active')", (id_new, act['id'], inst_id)) + cr.execute('select * from wkf_workitem where id=%s',(id_new,)) res = cr.dictfetchone() wkf_logs.log(cr,ident,act['id'],'active') process(cr, res, ident, stack=stack) @@ -45,7 +45,7 @@ def process(cr, workitem, ident, signal=None, force_running=False, stack=None): if stack is None: raise 'Error !!!' result = True - cr.execute('select * from wkf_activity where id=%d', (workitem['act_id'],)) + cr.execute('select * from wkf_activity where id=%s', (workitem['act_id'],)) activity = cr.dictfetchone() triggers = False @@ -63,7 +63,7 @@ def process(cr, workitem, ident, signal=None, force_running=False, stack=None): triggers = triggers and not ok if triggers: - cr.execute('select * from wkf_transition where act_from=%d', (workitem['act_id'],)) + cr.execute('select * from wkf_transition where act_from=%s', (workitem['act_id'],)) alltrans = cr.dictfetchall() for trans in alltrans: if trans['trigger_model']: @@ -71,7 +71,7 @@ def process(cr, workitem, ident, signal=None, force_running=False, stack=None): for res_id in ids: cr.execute('select nextval(\'wkf_triggers_id_seq\')') id =cr.fetchone()[0] - cr.execute('insert into wkf_triggers (model,res_id,instance_id,workitem_id,id) values (%s,%d,%d,%d,%d)', (trans['trigger_model'],res_id,workitem['inst_id'], workitem['id'], id)) + cr.execute('insert into wkf_triggers (model,res_id,instance_id,workitem_id,id) values (%s,%s,%s,%s,%s)', (trans['trigger_model'],res_id,workitem['inst_id'], workitem['id'], id)) return result @@ -79,7 +79,7 @@ def process(cr, workitem, ident, signal=None, force_running=False, stack=None): # ---------------------- PRIVATE FUNCS -------------------------------- def _state_set(cr, workitem, activity, state, ident): - cr.execute('update wkf_workitem set state=%s where id=%d', (state,workitem['id'])) + cr.execute('update wkf_workitem set state=%s where id=%s', (state,workitem['id'])) workitem['state'] = state wkf_logs.log(cr,ident,activity['id'],state) @@ -89,7 +89,7 @@ def _execute(cr, workitem, activity, ident, stack): # send a signal to parent workflow (signal: subflow.signal_name) # if (workitem['state']=='active') and activity['signal_send']: - cr.execute("select i.id,w.osv,i.res_id from wkf_instance i left join wkf w on (i.wkf_id=w.id) where i.id in (select inst_id from wkf_workitem where subflow_id=%d)", (workitem['inst_id'],)) + cr.execute("select i.id,w.osv,i.res_id from wkf_instance i left join wkf w on (i.wkf_id=w.id) where i.id in (select inst_id from wkf_workitem where subflow_id=%s)", (workitem['inst_id'],)) for i in cr.fetchall(): instance.validate(cr, i[0], (ident[0],i[1],i[2]), activity['signal_send'], force_running=True) @@ -116,7 +116,7 @@ def _execute(cr, workitem, activity, ident, stack): elif activity['kind']=='stopall': if workitem['state']=='active': _state_set(cr, workitem, activity, 'running', ident) - cr.execute('delete from wkf_workitem where inst_id=%d and id<>%d', (workitem['inst_id'], workitem['id'])) + cr.execute('delete from wkf_workitem where inst_id=%s and id<>%s', (workitem['inst_id'], workitem['id'])) if activity['action']: wkf_expr.execute(cr, ident, workitem, activity) _state_set(cr, workitem, activity, 'complete', ident) @@ -129,14 +129,14 @@ def _execute(cr, workitem, activity, ident, stack): cr.execute('delete from wkf_workitem where id=%s', (workitem['id'],)) return False assert type(id_new)==type(1) or type(id_new)==type(1L), 'Wrong return value: '+str(id_new)+' '+str(type(id_new)) - cr.execute('select id from wkf_instance where res_id=%d and wkf_id=%d', (id_new,activity['subflow_id'])) + cr.execute('select id from wkf_instance where res_id=%s and wkf_id=%s', (id_new,activity['subflow_id'])) id_new = cr.fetchone()[0] else: id_new = instance.create(cr, ident, activity['subflow_id']) - cr.execute('update wkf_workitem set subflow_id=%d where id=%s', (id_new, workitem['id'])) + cr.execute('update wkf_workitem set subflow_id=%s where id=%s', (id_new, workitem['id'])) workitem['subflow_id'] = id_new if workitem['state']=='running': - cr.execute("select state from wkf_instance where id=%d", (workitem['subflow_id'],)) + cr.execute("select state from wkf_instance where id=%s", (workitem['subflow_id'],)) state= cr.fetchone()[0] if state=='complete': _state_set(cr, workitem, activity, 'complete', ident) @@ -145,7 +145,7 @@ def _execute(cr, workitem, activity, ident, stack): def _split_test(cr, workitem, split_mode, ident, signal=None, stack=None): if stack is None: raise 'Error !!!' - cr.execute('select * from wkf_transition where act_from=%d', (workitem['act_id'],)) + cr.execute('select * from wkf_transition where act_from=%s', (workitem['act_id'],)) test = False transitions = [] alltrans = cr.dictfetchall() @@ -162,36 +162,36 @@ def _split_test(cr, workitem, split_mode, ident, signal=None, stack=None): if not wkf_expr.check(cr, workitem, ident, transition,signal): test = False break - cr.execute('select count(*) from wkf_witm_trans where trans_id=%d and inst_id=%d', (transition['id'], workitem['inst_id'])) + cr.execute('select count(*) from wkf_witm_trans where trans_id=%s and inst_id=%s', (transition['id'], workitem['inst_id'])) if not cr.fetchone()[0]: transitions.append((transition['id'], workitem['inst_id'])) if test and len(transitions): - cr.executemany('insert into wkf_witm_trans (trans_id,inst_id) values (%d,%d)', transitions) - cr.execute('delete from wkf_workitem where id=%d', (workitem['id'],)) + cr.executemany('insert into wkf_witm_trans (trans_id,inst_id) values (%s,%s)', transitions) + cr.execute('delete from wkf_workitem where id=%s', (workitem['id'],)) for t in transitions: _join_test(cr, t[0], t[1], ident, stack) return True return False def _join_test(cr, trans_id, inst_id, ident, stack): - cr.execute('select * from wkf_activity where id=(select act_to from wkf_transition where id=%d)', (trans_id,)) + cr.execute('select * from wkf_activity where id=(select act_to from wkf_transition where id=%s)', (trans_id,)) activity = cr.dictfetchone() if activity['join_mode']=='XOR': create(cr,[activity], inst_id, ident, stack) - cr.execute('delete from wkf_witm_trans where inst_id=%d and trans_id=%d', (inst_id,trans_id)) + cr.execute('delete from wkf_witm_trans where inst_id=%s and trans_id=%s', (inst_id,trans_id)) else: - cr.execute('select id from wkf_transition where act_to=%d', (activity['id'],)) + cr.execute('select id from wkf_transition where act_to=%s', (activity['id'],)) trans_ids = cr.fetchall() ok = True for (id,) in trans_ids: - cr.execute('select count(*) from wkf_witm_trans where trans_id=%d and inst_id=%d', (id,inst_id)) + cr.execute('select count(*) from wkf_witm_trans where trans_id=%s and inst_id=%s', (id,inst_id)) res = cr.fetchone()[0] if not res: ok = False break if ok: for (id,) in trans_ids: - cr.execute('delete from wkf_witm_trans where trans_id=%d and inst_id=%d', (id,inst_id)) + cr.execute('delete from wkf_witm_trans where trans_id=%s and inst_id=%s', (id,inst_id)) create(cr, [activity], inst_id, ident, stack) # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
