From c2cc3a304996fd1a7208b8e0570eef435682e75f Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Tue, 9 Dec 2008 13:37:22 +0100 Subject: [PATCH] [FIX] psycopg2: in queries we must now use %s everywhere (no more %d or %f) bzr revid: christophe@tinyerp.com-20081209123722-4kmv4pecjwiw3tm3 --- bin/addons/__init__.py | 4 +- bin/addons/base/ir/ir_cron.py | 2 +- bin/addons/base/ir/ir_model.py | 18 ++++---- bin/addons/base/ir/ir_rule.py | 2 +- bin/addons/base/ir/ir_sequence.py | 4 +- bin/addons/base/ir/ir_ui_menu.py | 2 +- bin/addons/base/ir/ir_ui_view.py | 2 +- bin/addons/base/ir/workflow/print_instance.py | 16 +++---- bin/addons/base/module/module.py | 12 +++--- bin/addons/base/res/partner/partner.py | 2 +- bin/addons/base/res/res_currency.py | 4 +- bin/addons/base/res/res_request.py | 10 ++--- bin/addons/base/res/res_user.py | 2 +- bin/osv/expression.py | 4 +- bin/service/security.py | 2 +- bin/tools/upgrade.py | 6 +-- bin/workflow/instance.py | 22 +++++----- bin/workflow/wkf_logs.py | 2 +- bin/workflow/wkf_service.py | 16 +++---- bin/workflow/workitem.py | 42 +++++++++---------- 20 files changed, 87 insertions(+), 87 deletions(-) diff --git a/bin/addons/__init__.py b/bin/addons/__init__.py index 4eeed2e23c6..f61b5f16ba0 100644 --- a/bin/addons/__init__.py +++ b/bin/addons/__init__.py @@ -487,10 +487,10 @@ def load_module_graph(cr, graph, status=None, **kwargs): else: tools.convert_xml_import(cr, m, fp, idref, noupdate=True, **kwargs) fp.close() - cr.execute('update ir_module_module set demo=%s where id=%d', (True, mid)) + cr.execute('update ir_module_module set demo=%s where id=%s', (True, mid)) package_todo.append(package.name) ver = release.major_version + '.' + package.data.get('version', '1.0') - cr.execute("update ir_module_module set state='installed', latest_version=%s where id=%d", (ver, mid,)) + cr.execute("update ir_module_module set state='installed', latest_version=%s where id=%s", (ver, mid,)) cr.commit() # Update translations for all installed languages diff --git a/bin/addons/base/ir/ir_cron.py b/bin/addons/base/ir/ir_cron.py index 31ad86612ad..f20381fc6e3 100644 --- a/bin/addons/base/ir/ir_cron.py +++ b/bin/addons/base/ir/ir_cron.py @@ -101,7 +101,7 @@ class ir_cron(osv.osv, netsvc.Agent): addsql='' if not numbercall: addsql = ', active=False' - cr.execute("update ir_cron set nextcall=%s, numbercall=%d"+addsql+" where id=%d", (nextcall.strftime('%Y-%m-%d %H:%M:%S'), numbercall, job['id'])) + cr.execute("update ir_cron set nextcall=%s, numbercall=%s"+addsql+" where id=%s", (nextcall.strftime('%Y-%m-%d %H:%M:%S'), numbercall, job['id'])) cr.commit() finally: cr.close() diff --git a/bin/addons/base/ir/ir_model.py b/bin/addons/base/ir/ir_model.py index 91360668243..4d8e2175d9d 100644 --- a/bin/addons/base/ir/ir_model.py +++ b/bin/addons/base/ir/ir_model.py @@ -266,7 +266,7 @@ class ir_model_access(osv.osv): if not grouparr: return False - cr.execute("select 1 from res_groups_users_rel where uid=%d and gid in(select res_id from ir_model_data where module=%s and name=%s)", (uid, grouparr[0], grouparr[1],)) + cr.execute("select 1 from res_groups_users_rel where uid=%s and gid in(select res_id from ir_model_data where module=%s and name=%s)", (uid, grouparr[0], grouparr[1],)) return bool(cr.fetchone()) def check_group(self, cr, uid, model, mode, group_ids): @@ -285,7 +285,7 @@ class ir_model_access(osv.osv): cr.execute("SELECT perm_" + mode + " " " FROM ir_model_access a " " JOIN ir_model m ON (m.id = a.model_id) " - " WHERE m.model = %s AND a.group_id = %d", (model_name, group_id) + " WHERE m.model = %s AND a.group_id = %s", (model_name, group_id) ) r = cr.fetchone() if r is None: @@ -442,10 +442,10 @@ class ir_model_data(osv.osv): cr.execute('select id,res_id from ir_model_data where module=%s and name=%s', (module,xml_id)) results = cr.fetchall() for action_id2,res_id2 in results: - cr.execute('select id from '+self.pool.get(model)._table+' where id=%d', (res_id2,)) + cr.execute('select id from '+self.pool.get(model)._table+' where id=%s', (res_id2,)) result3 = cr.fetchone() if not result3: - cr.execute('delete from ir_model_data where id=%d', (action_id2,)) + cr.execute('delete from ir_model_data where id=%s', (action_id2,)) else: res_id,action_id = res_id2,action_id2 @@ -513,7 +513,7 @@ class ir_model_data(osv.osv): #self.pool.get(model).unlink(cr, uid, ids) for id in ids: self.unlink_mark[(model, id)]=False - cr.execute('delete from ir_model_data where res_id=%d and model=\'%s\'', (id,model)) + cr.execute('delete from ir_model_data where res_id=%s and model=\'%s\'', (id,model)) return True def ir_set(self, cr, uid, key, key2, name, models, value, replace=True, isobject=False, meta=None, xml_id=False): @@ -525,7 +525,7 @@ class ir_model_data(osv.osv): model = models[0] if res_id: - where = ' and res_id=%d' % (res_id,) + where = ' and res_id=%s' % (res_id,) else: where = ' and (res_id is null)' @@ -552,10 +552,10 @@ class ir_model_data(osv.osv): if (module,name) not in self.loads: self.unlink_mark[(model,res_id)] = id if model=='workflow.activity': - cr.execute('select res_type,res_id from wkf_instance where id in (select inst_id from wkf_workitem where act_id=%d)', (res_id,)) + cr.execute('select res_type,res_id from wkf_instance where id in (select inst_id from wkf_workitem where act_id=%s)', (res_id,)) wkf_todo.extend(cr.fetchall()) - cr.execute("update wkf_transition set condition='True', role_id=NULL, signal=NULL,act_to=act_from,act_from=%d where act_to=%d", (res_id,res_id)) - cr.execute("delete from wkf_transition where act_to=%d", (res_id,)) + cr.execute("update wkf_transition set condition='True', role_id=NULL, signal=NULL,act_to=act_from,act_from=%s where act_to=%s", (res_id,res_id)) + cr.execute("delete from wkf_transition where act_to=%s", (res_id,)) for model,id in wkf_todo: wf_service = netsvc.LocalService("workflow") diff --git a/bin/addons/base/ir/ir_rule.py b/bin/addons/base/ir/ir_rule.py index ef9e90c6b64..3db6218e442 100644 --- a/bin/addons/base/ir/ir_rule.py +++ b/bin/addons/base/ir/ir_rule.py @@ -148,7 +148,7 @@ class ir_rule(osv.osv): WHERE m.model = %s AND (g.id IN (SELECT rule_group_id FROM group_rule_group_rel g_rel JOIN res_groups_users_rel u_rel ON (g_rel.group_id = u_rel.gid) - WHERE u_rel.uid = %d) OR g.global)""", (model_name, uid)) + WHERE u_rel.uid = %s) OR g.global)""", (model_name, uid)) ids = map(lambda x:x[0], cr.fetchall()) if not ids: return '', [] diff --git a/bin/addons/base/ir/ir_sequence.py b/bin/addons/base/ir/ir_sequence.py index 7c160fe98da..23e4ee90c93 100644 --- a/bin/addons/base/ir/ir_sequence.py +++ b/bin/addons/base/ir/ir_sequence.py @@ -69,11 +69,11 @@ class ir_sequence(osv.osv): 'sec': time.strftime('%S'), } - def get_id(self, cr, uid, sequence_id, test='id=%d'): + def get_id(self, cr, uid, sequence_id, test='id=%s'): cr.execute('select id,number_next,number_increment,prefix,suffix,padding from ir_sequence where '+test+' and active=True FOR UPDATE', (sequence_id,)) res = cr.dictfetchone() if res: - cr.execute('update ir_sequence set number_next=number_next+number_increment where id=%d and active=True', (res['id'],)) + cr.execute('update ir_sequence set number_next=number_next+number_increment where id=%s and active=True', (res['id'],)) if res['number_next']: return self._process(res['prefix']) + '%%0%sd' % res['padding'] % res['number_next'] + self._process(res['suffix']) else: diff --git a/bin/addons/base/ir/ir_ui_menu.py b/bin/addons/base/ir/ir_ui_menu.py index e44c5f6b65c..0a0b0442652 100644 --- a/bin/addons/base/ir/ir_ui_menu.py +++ b/bin/addons/base/ir/ir_ui_menu.py @@ -41,7 +41,7 @@ class many2many_unique(fields.many2many): for act in values: if act[0]==4: cr.execute('SELECT * FROM '+self._rel+' \ - WHERE '+self._id1+'=%d AND '+self._id2+'=%d', (id, act[1])) + WHERE '+self._id1+'=%s AND '+self._id2+'=%s', (id, act[1])) if cr.fetchall(): val.remove(act) return super(many2many_unique, self).set(cr, obj, id, name, val, user=user, diff --git a/bin/addons/base/ir/ir_ui_view.py b/bin/addons/base/ir/ir_ui_view.py index 7e7fc29459f..74badb96846 100644 --- a/bin/addons/base/ir/ir_ui_view.py +++ b/bin/addons/base/ir/ir_ui_view.py @@ -99,7 +99,7 @@ class view(osv.osv): for rs in result: if rs.get('model') == 'board.board': - cr.execute("select id,arch,ref_id from ir_ui_view_custom where user_id=%d and ref_id=%d", (uid, rs['id'])) + cr.execute("select id,arch,ref_id from ir_ui_view_custom where user_id=%s and ref_id=%s", (uid, rs['id'])) oview = cr.dictfetchall() if oview: rs['arch'] = oview[0]['arch'] diff --git a/bin/addons/base/ir/workflow/print_instance.py b/bin/addons/base/ir/workflow/print_instance.py index 48a958c5945..2f225c44209 100644 --- a/bin/addons/base/ir/workflow/print_instance.py +++ b/bin/addons/base/ir/workflow/print_instance.py @@ -28,7 +28,7 @@ import report,pooler,tools def graph_get(cr, graph, wkf_id, nested=False, workitem={}): import pydot - cr.execute('select * from wkf_activity where wkf_id=%d', (wkf_id,)) + cr.execute('select * from wkf_activity where wkf_id=%s', (wkf_id,)) nodes = cr.dictfetchall() activities = {} actfrom = {} @@ -36,7 +36,7 @@ def graph_get(cr, graph, wkf_id, nested=False, workitem={}): for n in nodes: activities[n['id']] = n if n['subflow_id'] and nested: - cr.execute('select * from wkf where id=%d', (n['subflow_id'],)) + cr.execute('select * from wkf where id=%s', (n['subflow_id'],)) wkfinfo = cr.dictfetchone() graph2 = pydot.Cluster('subflow'+str(n['subflow_id']), fontsize='12', label = """\"Subflow: %s\\nOSV: %s\"""" % ( n['name'], wkfinfo['osv']) ) (s1,s2) = graph_get(cr, graph2, n['subflow_id'], nested,workitem) @@ -78,9 +78,9 @@ def graph_get(cr, graph, wkf_id, nested=False, workitem={}): activity_to = actto[t['act_to']][1].get(t['signal'], actto[t['act_to']][0]) graph.add_edge(pydot.Edge( str(activity_from) ,str(activity_to), fontsize='10', **args)) nodes = cr.dictfetchall() - cr.execute('select id from wkf_activity where flow_start=True and wkf_id=%d limit 1', (wkf_id,)) + cr.execute('select id from wkf_activity where flow_start=True and wkf_id=%s limit 1', (wkf_id,)) start = cr.fetchone()[0] - cr.execute("select 'subflow.'||name,id from wkf_activity where flow_stop=True and wkf_id=%d", (wkf_id,)) + cr.execute("select 'subflow.'||name,id from wkf_activity where flow_stop=True and wkf_id=%s", (wkf_id,)) stop = cr.fetchall() stop = (stop[0][1], dict(stop)) return ((start,{}),stop) @@ -88,14 +88,14 @@ def graph_get(cr, graph, wkf_id, nested=False, workitem={}): def graph_instance_get(cr, graph, inst_id, nested=False): workitems = {} - cr.execute('select * from wkf_instance where id=%d', (inst_id,)) + cr.execute('select * from wkf_instance where id=%s', (inst_id,)) inst = cr.dictfetchone() def workitem_get(instance): - cr.execute('select act_id,count(*) from wkf_workitem where inst_id=%d group by act_id', (instance,)) + cr.execute('select act_id,count(*) from wkf_workitem where inst_id=%s group by act_id', (instance,)) workitems = dict(cr.fetchall()) - cr.execute('select subflow_id from wkf_workitem where inst_id=%d', (instance,)) + cr.execute('select subflow_id from wkf_workitem where inst_id=%s', (instance,)) for (subflow_id,) in cr.fetchall(): workitems.update(workitem_get(subflow_id)) return workitems @@ -130,7 +130,7 @@ class report_graph_instance(object): showpage''' else: cr.execute('SELECT id FROM wkf_instance \ - WHERE res_id=%d AND wkf_id=%d \ + WHERE res_id=%s AND wkf_id=%s \ ORDER BY state LIMIT 1', (data['id'], wkfinfo['id'])) inst_id = cr.fetchone() diff --git a/bin/addons/base/module/module.py b/bin/addons/base/module/module.py index a6767cd6c52..de2544df472 100644 --- a/bin/addons/base/module/module.py +++ b/bin/addons/base/module/module.py @@ -68,7 +68,7 @@ class module_category(osv.osv): cr.execute('select category_id,count(*) from ir_module_module where category_id in ('+','.join(map(str,ids))+') or category_id in (select id from ir_module_category where parent_id in ('+','.join(map(str,ids))+')) group by category_id') result = dict(cr.fetchall()) for id in ids: - cr.execute('select id from ir_module_category where parent_id=%d', (id,)) + cr.execute('select id from ir_module_category where parent_id=%s', (id,)) childs = [c for c, in cr.fetchall()] result[id] = reduce(lambda x,y:x+y, [result.get(c, 0) for c in childs], result.get(id, 0)) return result @@ -312,7 +312,7 @@ class module(osv.osv): 'license': terp.get('license', 'GPL-2'), }) cr.execute('DELETE FROM ir_module_module_dependency\ - WHERE module_id = %d', (id,)) + WHERE module_id = %s', (id,)) self._update_dependencies(cr, uid, ids[0], terp.get('depends', [])) self._update_category(cr, uid, ids[0], terp.get('category', @@ -433,7 +433,7 @@ class module(osv.osv): 'license': terp.get('license', 'GPL-2'), }) cr.execute('DELETE FROM ir_module_module_dependency ' \ - 'WHERE module_id = %d', (mod.id,)) + 'WHERE module_id = %s', (mod.id,)) self._update_dependencies(cr, uid, mod.id, terp.get('depends', [])) self._update_category(cr, uid, mod.id, terp.get('category', @@ -445,21 +445,21 @@ class module(osv.osv): def _update_dependencies(self, cr, uid, id, depends=[]): for d in depends: - cr.execute('INSERT INTO ir_module_module_dependency (module_id, name) values (%d, %s)', (id, d)) + cr.execute('INSERT INTO ir_module_module_dependency (module_id, name) values (%s, %s)', (id, d)) def _update_category(self, cr, uid, id, category='Uncategorized'): categs = category.split('/') p_id = None while categs: if p_id is not None: - cr.execute('select id from ir_module_category where name=%s and parent_id=%d', (categs[0], p_id)) + cr.execute('select id from ir_module_category where name=%s and parent_id=%s', (categs[0], p_id)) else: cr.execute('select id from ir_module_category where name=%s and parent_id is NULL', (categs[0],)) c_id = cr.fetchone() if not c_id: cr.execute('select nextval(\'ir_module_category_id_seq\')') c_id = cr.fetchone()[0] - cr.execute('insert into ir_module_category (id, name, parent_id) values (%d, %s, %d)', (c_id, categs[0], p_id)) + cr.execute('insert into ir_module_category (id, name, parent_id) values (%s, %s, %s)', (c_id, categs[0], p_id)) else: c_id = c_id[0] p_id = c_id diff --git a/bin/addons/base/res/partner/partner.py b/bin/addons/base/res/partner/partner.py index 12a82d2b6cd..8aef2eb46fd 100644 --- a/bin/addons/base/res/partner/partner.py +++ b/bin/addons/base/res/partner/partner.py @@ -259,7 +259,7 @@ class res_partner(osv.osv): raise osv.except_osv(_('Warning'), _("Couldn't generate the next id because some partners have an alphabetic id !")) # update the current partner - cr.execute("update res_partner set ref=%d where id=%d", (nextref, ids[0])) + cr.execute("update res_partner set ref=%s where id=%s", (nextref, ids[0])) return True def view_header_get(self, cr, uid, view_id, view_type, context): diff --git a/bin/addons/base/res/res_currency.py b/bin/addons/base/res/res_currency.py index b3849c0e352..8b752e4af5e 100644 --- a/bin/addons/base/res/res_currency.py +++ b/bin/addons/base/res/res_currency.py @@ -39,7 +39,7 @@ class res_currency(osv.osv): date=time.strftime('%Y-%m-%d') date= date or time.strftime('%Y-%m-%d') for id in ids: - cr.execute("SELECT currency_id, rate FROM res_currency_rate WHERE currency_id = %d AND name <= '%s' ORDER BY name desc LIMIT 1" % (id, date)) + cr.execute("SELECT currency_id, rate FROM res_currency_rate WHERE currency_id = %s AND name <= '%s' ORDER BY name desc LIMIT 1" % (id, date)) if cr.rowcount: id, rate=cr.fetchall()[0] res[id]=rate @@ -91,7 +91,7 @@ class res_currency(osv.osv): if account and (account.currency_mode=='average') and account.currency_id: q = self.pool.get('account.move.line')._query_get(cr, uid, context=context) cr.execute('select sum(debit-credit),sum(amount_currency) from account_move_line l ' \ - 'where l.currency_id=%d and l.account_id=%d and '+q, (account.currency_id.id,account.id,)) + 'where l.currency_id=%s and l.account_id=%s and '+q, (account.currency_id.id,account.id,)) tot1,tot2 = cr.fetchone() if tot2 and not account_invert: rate = float(tot1)/float(tot2) diff --git a/bin/addons/base/res/res_request.py b/bin/addons/base/res/res_request.py index 2dd6f1ad4ce..94f4217211f 100644 --- a/bin/addons/base/res/res_request.py +++ b/bin/addons/base/res/res_request.py @@ -34,8 +34,8 @@ class res_request(osv.osv): def request_send(self, cr, uid, ids, *args): for id in ids: - cr.execute('update res_request set state=%s,date_sent=%s where id=%d', ('waiting', time.strftime('%Y-%m-%d %H:%M:%S'), id)) - cr.execute('select act_from,act_to,body,date_sent from res_request where id=%d', (id,)) + cr.execute('update res_request set state=%s,date_sent=%s where id=%s', ('waiting', time.strftime('%Y-%m-%d %H:%M:%S'), id)) + cr.execute('select act_from,act_to,body,date_sent from res_request where id=%s', (id,)) values = cr.dictfetchone() if values['body'] and (len(values['body']) > 128): values['name'] = values['body'][:125] + '...' @@ -47,7 +47,7 @@ class res_request(osv.osv): def request_reply(self, cr, uid, ids, *args): for id in ids: - cr.execute("update res_request set state='active', act_from=%d, act_to=act_from, trigger_date=NULL, body='' where id=%d", (uid,id)) + cr.execute("update res_request set state='active', act_from=%s, act_to=act_from, trigger_date=NULL, body='' where id=%s", (uid,id)) return True def request_close(self, cr, uid, ids, *args): @@ -55,9 +55,9 @@ class res_request(osv.osv): return True def request_get(self, cr, uid): - cr.execute('select id from res_request where act_to=%d and (trigger_date<=%s or trigger_date is null) and active=True', (uid,time.strftime('%Y-%m-%d'))) + cr.execute('select id from res_request where act_to=%s and (trigger_date<=%s or trigger_date is null) and active=True', (uid,time.strftime('%Y-%m-%d'))) ids = map(lambda x:x[0], cr.fetchall()) - cr.execute('select id from res_request where act_from=%d and (act_to<>%d) and (trigger_date<=%s or trigger_date is null) and active=True', (uid,uid,time.strftime('%Y-%m-%d'))) + cr.execute('select id from res_request where act_from=%s and (act_to<>%s) and (trigger_date<=%s or trigger_date is null) and active=True', (uid,uid,time.strftime('%Y-%m-%d'))) ids2 = map(lambda x:x[0], cr.fetchall()) return (ids, ids2) diff --git a/bin/addons/base/res/res_user.py b/bin/addons/base/res/res_user.py index 24c31cf30c3..518acf57944 100644 --- a/bin/addons/base/res/res_user.py +++ b/bin/addons/base/res/res_user.py @@ -74,7 +74,7 @@ class roles(osv.osv): def check(self, cr, uid, ids, role_id): if role_id in ids: return True - cr.execute('select parent_id from res_roles where id=%d', (role_id,)) + cr.execute('select parent_id from res_roles where id=%s', (role_id,)) roles = cr.fetchone()[0] if roles: return self.check(cr, uid, ids, roles) diff --git a/bin/osv/expression.py b/bin/osv/expression.py index 93d3a0bc07b..0ec1e74765b 100644 --- a/bin/osv/expression.py +++ b/bin/osv/expression.py @@ -50,7 +50,7 @@ class expression(object): subids = ids[i:i+cr.IN_MAX] cr.execute('SELECT "%s"' \ ' FROM "%s"' \ - ' WHERE "%s" in (%s)' % (s, f, w, ','.join(['%d']*len(subids))), + ' WHERE "%s" in (%s)' % (s, f, w, ','.join(['%s']*len(subids))), subids) res.extend([r[0] for r in cr.fetchall()]) return res @@ -243,7 +243,7 @@ class expression(object): if len_after: if left == 'id': - instr = ','.join(['%d'] * len_after) + instr = ','.join(['%s'] * len_after) else: instr = ','.join([table._columns[left]._symbol_set[0]] * len_after) query = '(%s.%s %s (%s))' % (table._table, left, operator, instr) diff --git a/bin/service/security.py b/bin/service/security.py index 28f66812c25..81c6ef99744 100644 --- a/bin/service/security.py +++ b/bin/service/security.py @@ -46,7 +46,7 @@ def check(db, uid, passwd): return True cr = pooler.get_db(db).cursor() - cr.execute('select count(*) from res_users where id=%d and password=%s', (int(uid), passwd)) + cr.execute('select count(*) from res_users where id=%s and password=%s', (int(uid), passwd)) res = cr.fetchone()[0] cr.close() if not bool(res): diff --git a/bin/tools/upgrade.py b/bin/tools/upgrade.py index 80a3771f454..8392dbd9e93 100644 --- a/bin/tools/upgrade.py +++ b/bin/tools/upgrade.py @@ -59,7 +59,7 @@ def upgrade(): for module_id,name,url in cr.fetchall(): print '\tremoving module %s' % name remove(name) - cr.execute('update ir_module_module set state=%s where id=%d', ('uninstalled', module_id)) + cr.execute('update ir_module_module set state=%s where id=%s', ('uninstalled', module_id)) cr.commit() print 'Check for modules to upgrade...' @@ -68,7 +68,7 @@ def upgrade(): print '\tupgrading module %s' % name remove(name) install(name, url) - cr.execute('update ir_module_module set state=%s where id=%d', ('installed', module_id)) + cr.execute('update ir_module_module set state=%s where id=%s', ('installed', module_id)) cr.commit() toupdate.append(name) @@ -77,7 +77,7 @@ def upgrade(): for module_id,name,url in cr.fetchall(): print '\tinstalling module %s' % name install(name, url) - cr.execute('update ir_module_module set state=%s where id=%d', ('installed', module_id)) + cr.execute('update ir_module_module set state=%s where id=%s', ('installed', module_id)) cr.commit() toinit.append(name) 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: