Change all query with %d into %s for psycopg2
This commit is contained in:
1 parent
8ffbcf02ce
commit
a013c3bdca
18 files changed
+124
-127
No files matched your search
@@ -102,7 +102,7 @@ class Attachment(OSV):
|
||||
file_p.close()
|
||||
cursor.execute('UPDATE ir_attachment ' \
|
||||
'SET digest = %s, ' \
|
||||
'collision = %d ' \
|
||||
'WHERE id = %d', (digest, collision, obj_id))
|
||||
'collision = %s ' \
|
||||
'WHERE id = %s', (digest, collision, obj_id))
|
||||
|
||||
Attachment()
|
||||
+2
-2
@@ -114,8 +114,8 @@ class Cron(OSV, Agent):
|
||||
if not numbercall:
|
||||
addsql = ', active=False'
|
||||
cursor.execute("UPDATE ir_cron SET nextcall = %s, " \
|
||||
"numbercall = %d" + addsql + " " \
|
||||
"WHERE id = %d",
|
||||
"numbercall = %s" + addsql + " " \
|
||||
"WHERE id = %s",
|
||||
(nextcall.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
numbercall, job['id']))
|
||||
cursor.commit()
|
||||
|
||||
+4
-4
@@ -416,15 +416,15 @@ class ModelData(OSV):
|
||||
'FROM wkf_instance ' \
|
||||
'WHERE id IN (' \
|
||||
'SELECT instance FROM wkf_workitem ' \
|
||||
'WHERE act_id = %d)', (db_id,))
|
||||
'WHERE act_id = %s)', (db_id,))
|
||||
wkf_todo.extend(cursor.fetchall())
|
||||
cursor.execute("UPDATE wkf_transition " \
|
||||
"SET condition = 'True', role_id = NULL, " \
|
||||
"signal = NULL, act_to = act_from, " \
|
||||
"act_from = %d " \
|
||||
"WHERE act_to = %d", (db_id, db_id))
|
||||
"act_from = %s " \
|
||||
"WHERE act_to = %s", (db_id, db_id))
|
||||
cursor.execute("DELETE FROM wkf_transition " \
|
||||
"WHERE act_to = %d", (db_id,))
|
||||
"WHERE act_to = %s", (db_id,))
|
||||
|
||||
wf_service.trg_write(user, model, db_id, cursor)
|
||||
|
||||
|
||||
+5
-5
@@ -73,7 +73,7 @@ class Rule(OSV):
|
||||
super(Rule, self).__init__(pool)
|
||||
if pool:
|
||||
self._rpc_allowed = self._rpc_allowed + [
|
||||
'operand',
|
||||
'get_operand',
|
||||
]
|
||||
|
||||
|
||||
@@ -136,12 +136,12 @@ class Rule(OSV):
|
||||
"WHERE m.model = %s "
|
||||
"AND (g.id IN (" \
|
||||
"SELECT rule_group_id FROM user_rule_group_rel " \
|
||||
"WHERE user_id = %d " \
|
||||
"WHERE user_id = %s " \
|
||||
"UNION SELECT rule_group_id " \
|
||||
"FROM group_rule_group_rel g_rel " \
|
||||
"JOIN res_group_user_rel u_rel " \
|
||||
"ON (g_rel.group_id = u_rel.gid) " \
|
||||
"WHERE u_rel.uid = %d) "
|
||||
"WHERE u_rel.uid = %s) "
|
||||
"OR g.global_p)", (model_name, user, user))
|
||||
ids = [x[0] for x in cursor.fetchall()]
|
||||
if not ids:
|
||||
@@ -211,11 +211,11 @@ class Rule(OSV):
|
||||
WHERE m.model = %s
|
||||
AND (g.id NOT IN (SELECT rule_group FROM ir_rule))
|
||||
AND (g.id IN (SELECT rule_group_id FROM user_rule_group_rel
|
||||
WHERE user_id = %d
|
||||
WHERE user_id = %s
|
||||
UNION SELECT rule_group_id FROM group_rule_group_rel g_rel
|
||||
JOIN res_group_user_rel u_rel
|
||||
ON g_rel.group_id = u_rel.gid
|
||||
WHERE u_rel.uid = %d))""", (model_name, user, user))
|
||||
WHERE u_rel.uid = %s))""", (model_name, user, user))
|
||||
if not cursor.fetchall():
|
||||
query, val = _query(clause, 'OR')
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ class Sequence(OSV):
|
||||
'day':time.strftime('%d'),
|
||||
}
|
||||
|
||||
def get_id(self, cursor, user, sequence_id, test='id=%d'):
|
||||
def get_id(self, cursor, user, sequence_id, test='id=%s'):
|
||||
cursor.execute('lock table ir_sequence')
|
||||
cursor.execute('SELECT id, number_next, number_increment, prefix, ' \
|
||||
'suffix, padding ' \
|
||||
@@ -66,7 +66,7 @@ class Sequence(OSV):
|
||||
if res:
|
||||
cursor.execute('UPDATE ir_sequence ' \
|
||||
'SET number_next = number_next + number_increment ' \
|
||||
'WHERE id = %d AND active = True', (res['id'],))
|
||||
'WHERE id = %s AND active = True', (res['id'],))
|
||||
if res['number_next']:
|
||||
return self._process(res['prefix']) + \
|
||||
'%%0%sd' % res['padding'] % res['number_next'] + \
|
||||
|
||||
@@ -214,7 +214,7 @@ class Translation(OSV, Cacheable):
|
||||
'selection'):
|
||||
cursor.execute('SELECT module FROM ir_translation ' \
|
||||
'WHERE name = %s ' \
|
||||
'AND res_id = %d ' \
|
||||
'AND res_id = %s ' \
|
||||
'AND lang = %s ' \
|
||||
'AND type = %s ' \
|
||||
'AND src = %s ',
|
||||
@@ -226,7 +226,7 @@ class Translation(OSV, Cacheable):
|
||||
else:
|
||||
cursor.execute('SELECT module, src FROM ir_translation ' \
|
||||
'WHERE name = %s ' \
|
||||
'AND res_id = %d ' \
|
||||
'AND res_id = %s ' \
|
||||
'AND lang = %s ' \
|
||||
'AND type = %s',
|
||||
(vals.get('name', ''), vals.get('res_id', 0), 'en_US',
|
||||
@@ -304,7 +304,7 @@ class Translation(OSV, Cacheable):
|
||||
cursor.execute('SELECT id FROM ir_translation ' \
|
||||
'WHERE (write_uid IS NULL OR write_uid = 0) ' \
|
||||
'AND id IN ' \
|
||||
'(' + ','.join(['%d' for x in ids]) + ')',
|
||||
'(' + ','.join(['%s' for x in ids]) + ')',
|
||||
ids)
|
||||
ids2 = [x[0] for x in cursor.fetchall()]
|
||||
if ids2:
|
||||
@@ -446,7 +446,7 @@ class TranslationUpdate(Wizard):
|
||||
'SET fuzzy = True, ' \
|
||||
'src = %s ' \
|
||||
'WHERE name = %s ' \
|
||||
'AND res_id = %d ' \
|
||||
'AND res_id = %s ' \
|
||||
'AND type = %s ' \
|
||||
'AND lang = %s',
|
||||
(row['src'], row['name'], row['res_id'], row['type'],
|
||||
|
||||
@@ -112,8 +112,8 @@ class Many2ManyUniq(fields.Many2Many):
|
||||
for act in values:
|
||||
if act[0] == 4:
|
||||
cursor.execute('SELECT * FROM ' + self._rel + ' ' \
|
||||
'WHERE ' + self._id1 + ' = %d ' \
|
||||
'AND ' + self._id2 + ' = %d',
|
||||
'WHERE ' + self._id1 + ' = %s ' \
|
||||
'AND ' + self._id2 + ' = %s',
|
||||
(obj_id, act[1]))
|
||||
if cursor.fetchall():
|
||||
val.remove(act)
|
||||
@@ -220,7 +220,7 @@ class UIMenu(OSV):
|
||||
if 'module' in context:
|
||||
cursor.execute('INSERT INTO ir_translation ' \
|
||||
'(name, lang, type, src, res_id, value, module) ' \
|
||||
'VALUES (%s, %s, %s, %s, %d, %s, %s)',
|
||||
'VALUES (%s, %s, %s, %s, %s, %s, %s)',
|
||||
('ir.ui.menu,name', 'en_US', 'model', vals['name'],
|
||||
new_id, '', context.get('module')))
|
||||
return new_id
|
||||
|
||||
+35
-37
@@ -26,7 +26,7 @@ import psycopg2
|
||||
import warnings
|
||||
import __builtin__
|
||||
|
||||
def _symbol_set(symb):
|
||||
def _symbol_f(symb):
|
||||
if symb == None or symb == False:
|
||||
return None
|
||||
elif isinstance(symb, unicode):
|
||||
@@ -40,7 +40,7 @@ class Column(object):
|
||||
_type = 'unknown'
|
||||
_obj = None
|
||||
_symbol_c = '%s'
|
||||
_symbol_f = _symbol_set
|
||||
_symbol_f = _symbol_f
|
||||
_symbol_set = (_symbol_c, _symbol_f)
|
||||
_symbol_get = None
|
||||
|
||||
@@ -87,7 +87,7 @@ boolean = Boolean
|
||||
|
||||
class Integer(Column):
|
||||
_type = 'integer'
|
||||
_symbol_c = '%d'
|
||||
_symbol_c = '%s'
|
||||
_symbol_f = lambda x: int(x or 0)
|
||||
_symbol_set = (_symbol_c, _symbol_f)
|
||||
|
||||
@@ -143,7 +143,7 @@ text = Text
|
||||
|
||||
class Float(Column):
|
||||
_type = 'float'
|
||||
_symbol_c = '%f'
|
||||
_symbol_c = '%s'
|
||||
_symbol_f = lambda x: __builtin__.float(x or 0.0)
|
||||
_symbol_set = (_symbol_c, _symbol_f)
|
||||
|
||||
@@ -225,12 +225,12 @@ class One2One(Column):
|
||||
if act[0] == 0:
|
||||
id_new = obj.create(cursor, user, act[1])
|
||||
cursor.execute('UPDATE "' + obj_src._table + '" ' \
|
||||
'SET "' + field + '" = %d ' \
|
||||
'WHERE id = %d', (id_new, src_id))
|
||||
'SET "' + field + '" = %s ' \
|
||||
'WHERE id = %s', (id_new, src_id))
|
||||
else:
|
||||
cursor.execute('SELECT "' + field + '" ' \
|
||||
'FROM "' + obj_src._table + '" ' \
|
||||
'WHERE id = %d', (act[0],))
|
||||
'WHERE id = %s', (act[0],))
|
||||
(obj_id,) = cursor.fetchone()
|
||||
obj.write(cursor, user, [obj_id] , act[1], context=context)
|
||||
|
||||
@@ -284,30 +284,30 @@ class Many2One(Column):
|
||||
if act[0] == 0:
|
||||
id_new = obj.create(cursor, act[2])
|
||||
cursor.execute('UPDATE "' + obj_src._table + '" ' \
|
||||
'SET "' + field + '" = %d ' \
|
||||
'WHERE id = %d', (id_new, obj_id))
|
||||
'SET "' + field + '" = %s ' \
|
||||
'WHERE id = %s', (id_new, obj_id))
|
||||
elif act[0] == 1:
|
||||
obj.write(cursor, [act[1]], act[2], context=context)
|
||||
elif act[0] == 2:
|
||||
cursor.execute('DELETE FROM "' + table + '" ' \
|
||||
'WHERE id = %d', (act[1],))
|
||||
'WHERE id = %s', (act[1],))
|
||||
elif act[0] == 3 or act[0] == 5:
|
||||
cursor.execute('UPDATE "' + obj_src._table + '" ' \
|
||||
'SET "' + field + '" = NULL ' \
|
||||
'WHERE id = %d', (obj_id,))
|
||||
'WHERE id = %s', (obj_id,))
|
||||
elif act[0] == 4:
|
||||
cursor.execute('UPDATE "' + obj_src._table + '" ' \
|
||||
'SET "' + field + '" = %d ' \
|
||||
'WHERE id = %d', (act[1], obj_id))
|
||||
'SET "' + field + '" = %s ' \
|
||||
'WHERE id = %s', (act[1], obj_id))
|
||||
else:
|
||||
if values:
|
||||
cursor.execute('UPDATE "' + obj_src._table + '" ' \
|
||||
'SET "' + field + '" = %d ' \
|
||||
'WHERE id = %d', (values, obj_id))
|
||||
'SET "' + field + '" = %s ' \
|
||||
'WHERE id = %s', (values, obj_id))
|
||||
else:
|
||||
cursor.execute('UPDATE "' + obj_src._table + '" ' \
|
||||
'SET "' + field + '" = NULL ' \
|
||||
'WHERE id = %d', (obj_id,))
|
||||
'WHERE id = %s', (obj_id,))
|
||||
|
||||
many2one = Many2One
|
||||
|
||||
@@ -360,15 +360,15 @@ class One2Many(Column):
|
||||
elif act[0] == 3:
|
||||
cursor.execute('UPDATE "' + _table + '" ' \
|
||||
'SET "' + self._fields_id + '" = NULL ' \
|
||||
'WHERE id = %d', (act[1],))
|
||||
'WHERE id = %s', (act[1],))
|
||||
elif act[0] == 4:
|
||||
cursor.execute('UPDATE "' + _table + '" ' \
|
||||
'SET "' + self._fields_id + '" = %d ' \
|
||||
'WHERE id = %d', (obj_id, act[1]))
|
||||
'SET "' + self._fields_id + '" = %s ' \
|
||||
'WHERE id = %s', (obj_id, act[1]))
|
||||
elif act[0] == 5:
|
||||
cursor.execute('UPDATE "' + _table + '" ' \
|
||||
'SET "' + self._fields_id + '" = NULL ' \
|
||||
'WHERE "' + self._fields_id + '" = %d', (obj_id,))
|
||||
'WHERE "' + self._fields_id + '" = %s', (obj_id,))
|
||||
elif act[0] == 6:
|
||||
if not act[2]:
|
||||
ids2 = [0]
|
||||
@@ -376,13 +376,13 @@ class One2Many(Column):
|
||||
ids2 = act[2]
|
||||
cursor.execute('UPDATE "' + _table + '" ' \
|
||||
'SET "' + self._fields_id + '" = NULL ' \
|
||||
'WHERE "' + self._fields_id + '" = %d ' \
|
||||
'WHERE "' + self._fields_id + '" = %s ' \
|
||||
'AND id not IN (' + \
|
||||
','.join([str(x) for x in ids2]) + ')',
|
||||
(obj_id,))
|
||||
if act[2]:
|
||||
cursor.execute('UPDATE "' + _table + '" ' \
|
||||
'SET "' + self._fields_id + '" = %d ' \
|
||||
'SET "' + self._fields_id + '" = %s ' \
|
||||
'WHERE id IN (' + \
|
||||
','.join([str(x) for x in act[2]]) + ')',
|
||||
(obj_id,))
|
||||
@@ -416,7 +416,7 @@ class Many2Many(Column):
|
||||
for i in ids:
|
||||
res[i] = []
|
||||
ids_s = ','.join([str(x) for x in ids])
|
||||
limit_str = self._limit is not None and ' limit %d' % self._limit or ''
|
||||
limit_str = self._limit is not None and ' limit %s' % self._limit or ''
|
||||
obj = obj.pool.get(self._obj)
|
||||
|
||||
domain1, domain2 = obj.pool.get('ir.rule').domain_get(cursor,
|
||||
@@ -432,7 +432,7 @@ class Many2Many(Column):
|
||||
'AND ' + self._rel + '.' + self._id2 + ' = ' + \
|
||||
obj._table + '.id ' + domain1 + \
|
||||
limit_str + ' ORDER BY ' + obj._table + '.' + obj._order + \
|
||||
' offset %d', domain2 + [offset])
|
||||
' offset %s', domain2 + [offset])
|
||||
for i in cursor.fetchall():
|
||||
res[i[1]].append(i[0])
|
||||
return res
|
||||
@@ -448,34 +448,34 @@ class Many2Many(Column):
|
||||
idnew = obj.create(cursor, user, act[2])
|
||||
cursor.execute('INSERT INTO "' + self._rel + '" ' \
|
||||
'(' + self._id1 + ', ' + self._id2 + ') ' \
|
||||
'VALUES (%d, %d)', (obj_id, idnew))
|
||||
'VALUES (%s, %s)', (obj_id, idnew))
|
||||
elif act[0] == 1:
|
||||
obj.write(cursor, user, [act[1]] , act[2], context=context)
|
||||
elif act[0] == 2:
|
||||
obj.unlink(cursor, user, [act[1]], context=context)
|
||||
elif act[0] == 3:
|
||||
cursor.execute('DELETE FROM "' + self._rel + '" ' \
|
||||
'WHERE "' + self._id1 + '" = %d ' \
|
||||
'AND "'+ self._id2 + '" = %d', (obj_id, act[1]))
|
||||
'WHERE "' + self._id1 + '" = %s ' \
|
||||
'AND "'+ self._id2 + '" = %s', (obj_id, act[1]))
|
||||
elif act[0] == 4:
|
||||
cursor.execute('INSERT INTO "' + self._rel + '" ' \
|
||||
'(' + self._id1 + ', ' + self._id2 + ') ' \
|
||||
'VALUES (%d, %d)', (obj_id, act[1]))
|
||||
'VALUES (%s, %s)', (obj_id, act[1]))
|
||||
elif act[0] == 5:
|
||||
cursor.execute('UPDATE "' + self._rel + '" ' \
|
||||
'SET "' + self._id2 + '" = NULL ' \
|
||||
'WHERE "' + self._id2 + '" = %d', (obj_id,))
|
||||
'WHERE "' + self._id2 + '" = %s', (obj_id,))
|
||||
elif act[0] == 6:
|
||||
domain1, domain2 = obj.pool.get('ir.rule').domain_get(cursor,
|
||||
user, obj._name)
|
||||
if domain1:
|
||||
domain1 = ' AND ' + domain1
|
||||
cursor.execute('DELETE FROM "' + self._rel + '" ' \
|
||||
'WHERE "' + self._id1 + '" = %d ' \
|
||||
'WHERE "' + self._id1 + '" = %s ' \
|
||||
'AND "' + self._id2 + '" IN (' \
|
||||
'SELECT ' + self._rel + '.' + self._id2 + ' ' \
|
||||
'FROM "' + self._rel + '", "' + obj._table + '" ' \
|
||||
'WHERE ' + self._rel + '.' + self._id1 + ' = %d ' \
|
||||
'WHERE ' + self._rel + '.' + self._id1 + ' = %s ' \
|
||||
'AND ' + self._rel + '.' + self._id2 + ' = ' + \
|
||||
obj._table + '.id ' + domain1 + ')',
|
||||
[obj_id, obj_id] + domain2)
|
||||
@@ -483,7 +483,7 @@ class Many2Many(Column):
|
||||
for act_nbr in act[2]:
|
||||
cursor.execute('INSERT INTO "' + self._rel + '" ' \
|
||||
'(' + self._id1 + ', ' + self._id2 + ') ' \
|
||||
'VALUES (%d, %d)', (obj_id, act_nbr))
|
||||
'VALUES (%s, %s)', (obj_id, act_nbr))
|
||||
|
||||
many2many = Many2Many
|
||||
|
||||
@@ -491,7 +491,6 @@ many2many = Many2Many
|
||||
class Function(Column):
|
||||
_classic_read = False
|
||||
_classic_write = False
|
||||
_type = 'function'
|
||||
_properties = True
|
||||
|
||||
def __init__(self, fnct, arg=None, fnct_inv='', fnct_inv_arg=None,
|
||||
@@ -508,10 +507,9 @@ class Function(Column):
|
||||
self.readonly = 1
|
||||
self._type = type
|
||||
self._fnct_search = fnct_search
|
||||
if type == 'float':
|
||||
self._symbol_c = '%f'
|
||||
self._symbol_f = lambda x: __builtin__.float(x or 0.0)
|
||||
self._symbol_set = (self._symbol_c, self._symbol_f)
|
||||
self._symbol_c = eval(self._type)._symbol_c
|
||||
self._symbol_f = eval(self._type)._symbol_f
|
||||
self._symbol_set = (self._symbol_c, self._symbol_f)
|
||||
|
||||
def search(self, cursor, user, obj, name, args, context=None):
|
||||
if not self._fnct_search:
|
||||
|
||||
+13
-13
@@ -350,7 +350,7 @@ class ORM(object):
|
||||
cursor.execute("INSERT INTO ir_model_field " \
|
||||
"(model, name, field_description, ttype, " \
|
||||
"relation, group_name, view_load, help) " \
|
||||
"VALUES (%d, %s, %s, %s, %s, %s, %s, %s)",
|
||||
"VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
|
||||
(model_id, k, field.string, field._type,
|
||||
field._obj or 'NULL', field.group_name or '',
|
||||
(field.view_load and 'True') or 'False',
|
||||
@@ -369,7 +369,7 @@ class ORM(object):
|
||||
'group_name = %s, ' \
|
||||
'view_load = %s, ' \
|
||||
'help = %s ' \
|
||||
'WHERE id = %d ',
|
||||
'WHERE id = %s ',
|
||||
(field.string, field._type, field._obj or 'NULL',
|
||||
field.group_name or '',
|
||||
(field.view_load and 'True') or 'False',
|
||||
@@ -384,7 +384,7 @@ class ORM(object):
|
||||
elif trans_columns[trans_name]['src'] != field.string:
|
||||
cursor.execute('UPDATE ir_translation ' \
|
||||
'SET src = %s ' \
|
||||
'WHERE id = %d ',
|
||||
'WHERE id = %s ',
|
||||
(field.string, trans_columns[trans_name]['id']))
|
||||
if trans_name not in trans_help:
|
||||
if field.help:
|
||||
@@ -396,7 +396,7 @@ class ORM(object):
|
||||
elif trans_help[trans_name]['src'] != field.help:
|
||||
cursor.execute('UPDATE ir_translation ' \
|
||||
'SET src = %s ' \
|
||||
'WHERE id = %d ',
|
||||
'WHERE id = %s ',
|
||||
(field.help, trans_help[trans_name]['id']))
|
||||
if hasattr(field, 'selection') \
|
||||
and isinstance(field.selection, (tuple, list)):
|
||||
@@ -1323,7 +1323,7 @@ class ORM(object):
|
||||
for i in range((len(ids) / ID_MAX) + \
|
||||
((len(ids) % ID_MAX) and 1 or 0)):
|
||||
sub_ids = ids[ID_MAX * i:ID_MAX * (i + 1)]
|
||||
str_d = ','.join(('%d',) * len(sub_ids))
|
||||
str_d = ','.join(('%s',) * len(sub_ids))
|
||||
if domain1:
|
||||
cursor.execute('SELECT id FROM "'+self._table+'" ' \
|
||||
'WHERE id IN (' + str_d + ') ' + domain1,
|
||||
@@ -1424,8 +1424,8 @@ class ORM(object):
|
||||
(val, field))
|
||||
|
||||
if self._log_access:
|
||||
upd0.append('write_uid=%d')
|
||||
upd0.append('write_date=now()')
|
||||
upd0.append('write_uid = %s')
|
||||
upd0.append('write_date = now()')
|
||||
upd1.append(user)
|
||||
|
||||
if len(upd0):
|
||||
@@ -1563,11 +1563,11 @@ class ORM(object):
|
||||
for table in tocreate:
|
||||
new_id = self.pool.get(table).create(cursor, user, tocreate[table])
|
||||
upd0 += ',' + self._inherits[table]
|
||||
upd1 += ',%d'
|
||||
upd1 += ',%s'
|
||||
upd2.append(new_id)
|
||||
cursor.execute('INSERT INTO inherit ' \
|
||||
'(obj_type, obj_id, inst_type, inst_id) ' \
|
||||
'values (%s, %d, %s, %d)',
|
||||
'values (%s, %s, %s, %s)',
|
||||
(table, new_id, self._name, id_new))
|
||||
|
||||
for field in vals:
|
||||
@@ -1600,7 +1600,7 @@ class ORM(object):
|
||||
(val, field))
|
||||
if self._log_access:
|
||||
upd0 += ', create_uid, create_date'
|
||||
upd1 += ', %d, now()'
|
||||
upd1 += ', %s, now()'
|
||||
upd2.append(user)
|
||||
cursor.execute('INSERT INTO "' + self._table + '" ' \
|
||||
'(id' + upd0 + ') ' \
|
||||
@@ -1874,7 +1874,7 @@ class ORM(object):
|
||||
where = (model and (" and model='%s'" % (self._name,))) or ''
|
||||
cursor.execute('SELECT arch, name, field_childs, id, type, ' \
|
||||
'inherit ' \
|
||||
'FROM ir_ui_view WHERE id = %d ' + where, (view_id,))
|
||||
'FROM ir_ui_view WHERE id = %s ' + where, (view_id,))
|
||||
else:
|
||||
cursor.execute('SELECT arch, name, field_childs, id, type, ' \
|
||||
'inherit ' \
|
||||
@@ -1897,7 +1897,7 @@ class ORM(object):
|
||||
def _inherit_apply_rec(result, inherit_id):
|
||||
# get all views which inherit from (ie modify) this view
|
||||
cursor.execute('SELECT arch, id FROM ir_ui_view ' \
|
||||
'WHERE inherit = %d AND model = %s ' \
|
||||
'WHERE inherit = %s AND model = %s ' \
|
||||
'ORDER BY priority', (inherit_id, self._name))
|
||||
sql_inherit = cursor.fetchall()
|
||||
for (inherit, view_id) in sql_inherit:
|
||||
@@ -2208,7 +2208,7 @@ class ORM(object):
|
||||
if arg[0] == 'id':
|
||||
qu1.append('(%s.id in (%s))' % \
|
||||
(table._table,
|
||||
','.join(['%d'] * len(arg[2])),))
|
||||
','.join(['%s'] * len(arg[2])),))
|
||||
else:
|
||||
qu1.append('(%s.%s in (%s))' % \
|
||||
(table._table, arg[0], ','.join(
|
||||
|
||||
@@ -124,12 +124,12 @@ class Request(OSV):
|
||||
|
||||
def request_get(self, cursor, user):
|
||||
cursor.execute('SELECT id FROM res_request ' \
|
||||
'WHERE act_to = %d ' \
|
||||
'WHERE act_to = %s ' \
|
||||
'AND (trigger_date <= %s OR trigger_date IS NULL) ' \
|
||||
'AND active = True', (user, time.strftime('%Y-%m-%d')))
|
||||
ids = [x[0] for x in cursor.fetchall()]
|
||||
cursor.execute('SELECT id FROM res_request ' \
|
||||
'WHERE act_from = %d AND (act_to <> %d) ' \
|
||||
'WHERE act_from = %s AND (act_to <> %s) ' \
|
||||
'AND (trigger_date <= %s OR trigger_date IS NULL) ' \
|
||||
'AND active = True',
|
||||
(user, user, time.strftime('%Y-%m-%d')))
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ def check(dbname, user, passwd):
|
||||
return True
|
||||
cursor = pooler.get_db(dbname).cursor()
|
||||
cursor.execute('SELECT count(*) FROM res_user ' \
|
||||
'WHERE id = %d AND password = %s', (int(user), passwd))
|
||||
'WHERE id = %s AND password = %s', (int(user), passwd))
|
||||
res = cursor.fetchone()[0]
|
||||
cursor.close()
|
||||
if not bool(res):
|
||||
|
||||
+3
-4
@@ -69,7 +69,6 @@ class FakeCursor(object):
|
||||
sql = sql.encode('utf-8')
|
||||
if self.sql_log:
|
||||
now = mdt.now()
|
||||
sql = sql.replace('%d', '%s')
|
||||
if para:
|
||||
res = self.cursor.execute(sql, para)
|
||||
else:
|
||||
@@ -185,7 +184,7 @@ def init_db(cursor):
|
||||
if p_id is not None:
|
||||
cursor.execute('SELECT id ' \
|
||||
'FROM ir_module_category ' \
|
||||
'WHERE name = %s AND parent = %d',
|
||||
'WHERE name = %s AND parent = %s',
|
||||
(categs[0], p_id))
|
||||
else:
|
||||
cursor.execute('SELECT id ' \
|
||||
@@ -199,7 +198,7 @@ def init_db(cursor):
|
||||
c_id = cursor.fetchone()[0]
|
||||
cursor.execute('INSERT INTO ir_module_category ' \
|
||||
'(id, name, parent) ' \
|
||||
'VALUES (%d, %s, %d)', (c_id, categs[0], p_id))
|
||||
'VALUES (%s, %s, %s)', (c_id, categs[0], p_id))
|
||||
else:
|
||||
c_id = c_id[0]
|
||||
p_id = c_id
|
||||
@@ -219,7 +218,7 @@ def init_db(cursor):
|
||||
cursor.execute('INSERT INTO ir_module_module ' \
|
||||
'(id, author, latest_version, website, name, shortdesc, ' \
|
||||
'description, category, state) ' \
|
||||
'VALUES (%d, %s, %s, %s, %s, %s, %s, %d, %s)',
|
||||
'VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)',
|
||||
(module_id, info.get('author', ''),
|
||||
version.VERSION.rsplit('.', 1)[0] + '.' + info.get('version', ''),
|
||||
info.get('website', ''), i, info.get('name', False),
|
||||
|
||||
@@ -70,16 +70,16 @@ class MenuitemTagHandler:
|
||||
"LEFT JOIN ir_action_url url ON (a.id = url.action) " \
|
||||
"LEFT JOIN ir_action_act_window_view wv on (act.id = wv.act_window) " \
|
||||
"LEFT JOIN ir_ui_view v on (v.id = wv.view) " \
|
||||
"WHERE report.id = %d " \
|
||||
"OR act.id = %d " \
|
||||
"OR wizard.id = %d " \
|
||||
"OR url.id = %d " \
|
||||
"WHERE report.id = %s " \
|
||||
"OR act.id = %s " \
|
||||
"OR wizard.id = %s " \
|
||||
"OR url.id = %s " \
|
||||
"ORDER by wv.sequence " \
|
||||
"LIMIT 1", (action_id, action_id, action_id, action_id))
|
||||
action_name, action_type, view_type, view_mode = \
|
||||
self.mh.cursor.fetchone()
|
||||
|
||||
values['action'] = '%s,%d' % (action_type, action_id)
|
||||
values['action'] = '%s,%s' % (action_type, action_id)
|
||||
|
||||
icon = attributes.get('icon', '').encode('utf8')
|
||||
if icon:
|
||||
|
||||
@@ -177,7 +177,7 @@ class Directory(OSV):
|
||||
if model_obj._log_access:
|
||||
cursor.execute('SELECT EXTRACT(epoch FROM create_date) ' \
|
||||
'FROM "' + model_obj._table +'" ' \
|
||||
'WHERE id = %d', (object_id,))
|
||||
'WHERE id = %s', (object_id,))
|
||||
return cursor.fetchone()[0]
|
||||
return time.time()
|
||||
|
||||
@@ -188,7 +188,7 @@ class Directory(OSV):
|
||||
if model_obj._log_access and object_id:
|
||||
cursor.execute('SELECT EXTRACT(epoch FROM write_date) ' \
|
||||
'FROM "' + model_obj._table +'" ' \
|
||||
'WHERE id = %d', (object_id,))
|
||||
'WHERE id = %s', (object_id,))
|
||||
return cursor.fetchone()[0]
|
||||
return time.time()
|
||||
|
||||
|
||||
@@ -156,7 +156,7 @@ class Wizard(object):
|
||||
cursor.execute('UPDATE ir_translation ' \
|
||||
'SET src = %s, ' \
|
||||
'fuzzy = True '
|
||||
'WHERE id = %d', (button_value, res[0]['id']))
|
||||
'WHERE id = %s', (button_value, res[0]['id']))
|
||||
|
||||
def execute(self, cursor, user, data, state='init', context=None):
|
||||
if context is None:
|
||||
|
||||
@@ -5,10 +5,10 @@ def create(cursor, ident, wkf_id):
|
||||
cursor.execute("SELECT NEXTVAL('wkf_instance_id_seq')")
|
||||
(id_new,) = cursor.fetchone()
|
||||
cursor.execute('INSERT INTO wkf_instance ' \
|
||||
'(id, res_type, res_id, uid, workflow) VALUES (%d,%s,%s,%s,%s)',
|
||||
'(id, res_type, res_id, uid, workflow) VALUES (%s,%s,%s,%s,%s)',
|
||||
(id_new, res_type, res_id, user, wkf_id))
|
||||
cursor.execute('SELECT * FROM wkf_activity ' \
|
||||
'WHERE flow_start = True and workflow = %d', (wkf_id,))
|
||||
'WHERE flow_start = True and workflow = %s', (wkf_id,))
|
||||
res = cursor.dictfetchall()
|
||||
workitem.create(cursor, res, id_new, ident)
|
||||
update(cursor, id_new, ident)
|
||||
@@ -17,17 +17,17 @@ def create(cursor, ident, wkf_id):
|
||||
def delete(cursor, ident):
|
||||
(user, res_type, res_id) = ident
|
||||
cursor.execute('DELETE FROM wkf_instance ' \
|
||||
'WHERE res_id = %d AND res_type = %s', (res_id, res_type))
|
||||
'WHERE res_id = %s AND res_type = %s', (res_id, res_type))
|
||||
|
||||
def validate(cursor, inst_id, ident, signal, force_running=False):
|
||||
cursor.execute("SELECT * FROM wkf_workitem WHERE instance = %d",
|
||||
cursor.execute("SELECT * FROM wkf_workitem WHERE instance = %s",
|
||||
(inst_id,))
|
||||
for witem in cursor.dictfetchall():
|
||||
workitem.process(cursor, witem, ident, signal, force_running)
|
||||
return _update_end(cursor, inst_id, ident)
|
||||
|
||||
def update(cursor, inst_id, ident):
|
||||
cursor.execute("SELECT * FROM wkf_workitem WHERE instance = %d",
|
||||
cursor.execute("SELECT * FROM wkf_workitem WHERE instance = %s",
|
||||
(inst_id,))
|
||||
for witem in cursor.dictfetchall():
|
||||
workitem.process(cursor, witem, ident)
|
||||
@@ -36,7 +36,7 @@ def update(cursor, inst_id, ident):
|
||||
def _update_end(cursor, inst_id, ident):
|
||||
cursor.execute('SELECT state, flow_stop FROM wkf_workitem w ' \
|
||||
'LEFT JOIN wkf_activity a ' \
|
||||
'ON (a.id = w.activity) WHERE w.instance = %d',
|
||||
'ON (a.id = w.activity) WHERE w.instance = %s',
|
||||
(inst_id,))
|
||||
res = True
|
||||
for row in cursor.fetchall():
|
||||
@@ -47,19 +47,19 @@ def _update_end(cursor, inst_id, ident):
|
||||
cursor.execute('SELECT DISTINCT a.name FROM wkf_activity a ' \
|
||||
'LEFT JOIN wkf_workitem w ' \
|
||||
'ON (a.id = w.activity) ' \
|
||||
'WHERE w.instance = %d', (inst_id,))
|
||||
'WHERE w.instance = %s', (inst_id,))
|
||||
act_names = cursor.fetchall()
|
||||
cursor.execute("UPDATE wkf_instance " \
|
||||
"SET state = 'complete' WHERE id = %d", (inst_id,))
|
||||
"SET state = 'complete' WHERE id = %s", (inst_id,))
|
||||
cursor.execute("UPDATE wkf_workitem " \
|
||||
"SET state = 'complete' WHERE subflow = %d", (inst_id,))
|
||||
"SET state = 'complete' WHERE subflow = %s", (inst_id,))
|
||||
# TODO remove the subquery
|
||||
cursor.execute("SELECT i.id, w.osv, i.res_id " \
|
||||
"FROM wkf_instance i " \
|
||||
"LEFT JOIN wkf w ON (i.workflow = w.id) " \
|
||||
"WHERE i.id IN (" \
|
||||
"SELECT instance FROM wkf_workitem " \
|
||||
"WHERE subflow = %d)", (inst_id,))
|
||||
"WHERE subflow = %s)", (inst_id,))
|
||||
for i in cursor.fetchall():
|
||||
for act_name in act_names:
|
||||
validate(cursor, i[0], (ident[0], i[1], i[2]),
|
||||
|
||||
@@ -25,7 +25,7 @@ class WorkflowService(Service):
|
||||
"Trigger write"
|
||||
ident = (user, res_type, res_id)
|
||||
cursor.execute('SELECT id FROM wkf_instance ' \
|
||||
'WHERE res_id = %d AND res_type = %s AND state = %s',
|
||||
'WHERE res_id = %s AND res_type = %s AND state = %s',
|
||||
(res_id, res_type, 'active'))
|
||||
for (instance_id,) in cursor.fetchall():
|
||||
instance.update(cursor, instance_id, ident)
|
||||
@@ -33,11 +33,11 @@ class WorkflowService(Service):
|
||||
def trg_trigger(self, user, res_type, res_id, cursor):
|
||||
"Trigger trigger"
|
||||
cursor.execute('SELECT instance_id FROM wkf_trigger ' \
|
||||
'WHERE res_id = %d AND model = %s', (res_id, res_type))
|
||||
'WHERE res_id = %s AND model = %s', (res_id, res_type))
|
||||
# TODO remove the query from for statement
|
||||
for (instance_id,) in cursor.fetchall():
|
||||
cursor.execute('SELECT user, res_type, res_id FROM wkf_instance ' \
|
||||
'WHERE id = %d', (instance_id,))
|
||||
'WHERE id = %s', (instance_id,))
|
||||
ident = cursor.fetchone()
|
||||
instance.update(cursor, instance_id, ident)
|
||||
|
||||
@@ -66,7 +66,7 @@ class WorkflowService(Service):
|
||||
# ids of all active workflow instances
|
||||
# for a corresponding resource (id, model_name)
|
||||
cursor.execute('SELECT id FROM wkf_instance ' \
|
||||
'WHERE res_id = %d AND res_type = %s AND state = %s',
|
||||
'WHERE res_id = %s AND res_type = %s AND state = %s',
|
||||
(res_id, res_type, 'active'))
|
||||
for (instance_id,) in cursor.fetchall():
|
||||
instance.validate(cursor, instance_id, ident, signal)
|
||||
@@ -81,23 +81,23 @@ class WorkflowService(Service):
|
||||
# get ids of wkf instances for the old resource (res_id)
|
||||
# XXX shouldn't we get only active instances?
|
||||
cursor.execute('SELECT id, workflow FROM wkf_instance ' \
|
||||
'WHERE res_id = %d AND res_type = %s', (res_id, res_type))
|
||||
'WHERE res_id = %s AND res_type = %s', (res_id, res_type))
|
||||
for old_inst_id, wkf_id in cursor.fetchall():
|
||||
# first active instance for new resource (new_rid), using same wkf
|
||||
cursor.execute(
|
||||
'SELECT id '\
|
||||
'FROM wkf_instance '\
|
||||
'WHERE res_id = %d AND res_type = %s ' \
|
||||
'AND workflow = %d AND state = %s',
|
||||
'WHERE res_id = %s AND res_type = %s ' \
|
||||
'AND workflow = %s AND state = %s',
|
||||
(new_rid, res_type, wkf_id, 'active'))
|
||||
new_id = cursor.fetchone()
|
||||
if new_id:
|
||||
# select all workitems which "wait" for the old instance
|
||||
cursor.execute('SELECT id FROM wkf_workitem ' \
|
||||
'WHERE subflow = %d', (old_inst_id,))
|
||||
'WHERE subflow = %s', (old_inst_id,))
|
||||
for (item_id,) in cursor.fetchall():
|
||||
# redirect all those workitems
|
||||
# to the wkf instance of the new resource
|
||||
cursor.execute('UPDATE wkf_workitem ' \
|
||||
'SET subflow = %d ' \
|
||||
'WHERE id = %d', (new_id[0], item_id))
|
||||
'SET subflow = %s ' \
|
||||
'WHERE id = %s', (new_id[0], item_id))
|
||||
@@ -8,14 +8,14 @@ def create(cursor, act_datas, inst_id, ident):
|
||||
cursor.execute("SELECT NEXTVAL('wkf_workitem_id_seq')")
|
||||
(id_new,) = cursor.fetchone()
|
||||
cursor.execute("INSERT INTO wkf_workitem " \
|
||||
"(id, activity, instance, state) VALUES (%d, %s, %s, 'active')",
|
||||
"(id, activity, instance, state) VALUES (%s, %s, %s, 'active')",
|
||||
(id_new, act['id'], inst_id))
|
||||
cursor.execute('SELECT * FROM wkf_workitem WHERE id=%d', (id_new,))
|
||||
cursor.execute('SELECT * FROM wkf_workitem WHERE id=%s', (id_new,))
|
||||
res = cursor.dictfetchone()
|
||||
process(cursor, res, ident)
|
||||
|
||||
def process(cursor, workitem, ident, signal=None, force_running=False):
|
||||
cursor.execute('SELECT * FROM wkf_activity WHERE id = %d',
|
||||
cursor.execute('SELECT * FROM wkf_activity WHERE id = %s',
|
||||
(workitem['activity'],))
|
||||
activity = cursor.dictfetchone()
|
||||
triggers = False
|
||||
@@ -34,7 +34,7 @@ def process(cursor, workitem, ident, signal=None, force_running=False):
|
||||
|
||||
if triggers:
|
||||
cursor.execute('SELECT * FROM wkf_transition ' \
|
||||
'WHERE act_from = %d', (workitem['activity'],))
|
||||
'WHERE act_from = %s', (workitem['activity'],))
|
||||
alltrans = cursor.dictfetchall()
|
||||
for trans in alltrans:
|
||||
if trans['trigger_model']:
|
||||
@@ -45,14 +45,14 @@ def process(cursor, workitem, ident, signal=None, force_running=False):
|
||||
(new_id,) = cursor.fetchone()
|
||||
cursor.execute('INSERT INTO wkf_trigger ' \
|
||||
'(model, res_id, instance, workitem, id) ' \
|
||||
'VALUES (%s, %d, %d, %d, %d)',
|
||||
'VALUES (%s, %s, %s, %s, %s)',
|
||||
(trans['trigger_model'], res_id,
|
||||
workitem['inst_id'], workitem['id'], new_id))
|
||||
return True
|
||||
|
||||
def _state_set(cursor, workitem, state):
|
||||
cursor.execute('UPDATE wkf_workitem ' \
|
||||
'SET state = %s WHERE id = %d', (state, workitem['id']))
|
||||
'SET state = %s WHERE id = %s', (state, workitem['id']))
|
||||
workitem['state'] = state
|
||||
|
||||
def _execute(cursor, workitem, activity, ident):
|
||||
@@ -66,7 +66,7 @@ def _execute(cursor, workitem, activity, ident):
|
||||
"ON (i.workflow = w.id) " \
|
||||
"WHERE i.id in (" \
|
||||
"SELECT instance FROM wkf_workitem " \
|
||||
"WHERE subflow = %d)", (workitem['inst_id'],))
|
||||
"WHERE subflow = %s)", (workitem['inst_id'],))
|
||||
for i in cursor.fetchall():
|
||||
instance.validate(cursor, i[0], (ident[0], i[1], i[2]),
|
||||
activity['signal_send'], force_running=True)
|
||||
@@ -83,7 +83,7 @@ def _execute(cursor, workitem, activity, ident):
|
||||
if workitem['state'] == 'active':
|
||||
_state_set(cursor, workitem, 'running')
|
||||
cursor.execute('DELETE FROM wkf_workitem ' \
|
||||
'WHERE instance = %d AND id <> %d',
|
||||
'WHERE instance = %s AND id <> %s',
|
||||
(workitem['inst_id'], workitem['id']))
|
||||
if activity['action']:
|
||||
wkf_expr.execute(cursor, ident, workitem, activity)
|
||||
@@ -101,18 +101,18 @@ def _execute(cursor, workitem, activity, ident):
|
||||
'Wrong return value: ' + str(id_new) + ' ' + \
|
||||
str(type(id_new))
|
||||
cursor.execute('SELECT id FROM wkf_instance ' \
|
||||
'WHERE res_id = %d AND workflow = %d',
|
||||
'WHERE res_id = %s AND workflow = %s',
|
||||
(id_new, activity['subflow_id']))
|
||||
(id_new,) = cursor.fetchone()
|
||||
else:
|
||||
id_new = instance.create(cursor, ident, activity['subflow_id'])
|
||||
cursor.execute('UPDATE wkf_workitem ' \
|
||||
'SET subflow = %d WHERE id = %d',
|
||||
'SET subflow = %s WHERE id = %s',
|
||||
(id_new, workitem['id']))
|
||||
workitem['subflow_id'] = id_new
|
||||
if workitem['state'] == 'running':
|
||||
cursor.execute("SELECT state FROM wkf_instance " \
|
||||
"WHERE id = %d", (workitem['subflow_id'],))
|
||||
"WHERE id = %s", (workitem['subflow_id'],))
|
||||
(state,) = cursor.fetchone()
|
||||
if state == 'complete':
|
||||
_state_set(cursor, workitem, 'complete')
|
||||
@@ -122,7 +122,7 @@ def _split_test(cursor, workitem, split_mode, ident, signal=None):
|
||||
test = False
|
||||
transitions = []
|
||||
cursor.execute('SELECT * FROM wkf_transition ' \
|
||||
'WHERE act_from = %d', (workitem['activity'],))
|
||||
'WHERE act_from = %s', (workitem['activity'],))
|
||||
alltrans = cursor.dictfetchall()
|
||||
if split_mode == 'XOR' or split_mode == 'OR':
|
||||
for transition in alltrans:
|
||||
@@ -138,15 +138,15 @@ def _split_test(cursor, workitem, split_mode, ident, signal=None):
|
||||
test = False
|
||||
break
|
||||
cursor.execute('SELECT COUNT(*) ' \
|
||||
'FROM wkf_witm_trans WHERE trans_id = %d AND inst_id = %d',
|
||||
'FROM wkf_witm_trans WHERE trans_id = %s AND inst_id = %s',
|
||||
(transition['id'], workitem['inst_id']))
|
||||
(count,) = cursor.fetchone()
|
||||
if not count:
|
||||
transitions.append((transition['id'], workitem['inst_id']))
|
||||
if test and len(transitions):
|
||||
cursor.executemany('INSERT INTO wkf_witm_trans ' \
|
||||
'(trans_id, inst_id) values (%d, %d)', transitions)
|
||||
cursor.execute('DELETE FROM wkf_workitem WHERE id = %d',
|
||||
'(trans_id, inst_id) values (%s, %s)', transitions)
|
||||
cursor.execute('DELETE FROM wkf_workitem WHERE id = %s',
|
||||
(workitem['id'],))
|
||||
for transition in transitions:
|
||||
_join_test(cursor, transition[0], transition[1], ident)
|
||||
@@ -156,21 +156,21 @@ def _split_test(cursor, workitem, split_mode, ident, signal=None):
|
||||
def _join_test(cursor, trans_id, inst_id, ident):
|
||||
# TODO remove the subquery
|
||||
cursor.execute('SELECT * FROM wkf_activity ' \
|
||||
'WHERE id = (SELECT act_to FROM wkf_transition WHERE id = %d)',
|
||||
'WHERE id = (SELECT act_to FROM wkf_transition WHERE id = %s)',
|
||||
(trans_id,))
|
||||
activity = cursor.dictfetchone()
|
||||
if activity['join_mode'] == 'XOR':
|
||||
create(cursor, [activity], inst_id, ident)
|
||||
cursor.execute('DELETE FROM wkf_witm_trans ' \
|
||||
'WHERE inst_id = %d AND trans_id = %d', (inst_id, trans_id))
|
||||
'WHERE inst_id = %s AND trans_id = %s', (inst_id, trans_id))
|
||||
else:
|
||||
cursor.execute('SELECT id FROM wkf_transition ' \
|
||||
'WHERE act_to = %d', (activity['id'],))
|
||||
'WHERE act_to = %s', (activity['id'],))
|
||||
trans_ids = cursor.fetchall()
|
||||
delete = True
|
||||
for (trans_id,) in trans_ids:
|
||||
cursor.execute('SELECT COUNT(*) FROM wkf_witm_trans ' \
|
||||
'WHERE trans_id = %d AND inst_id = %d',
|
||||
'WHERE trans_id = %s AND inst_id = %s',
|
||||
(trans_id, inst_id))
|
||||
(count,) = cursor.fetchone()
|
||||
if not count:
|
||||
@@ -179,6 +179,6 @@ def _join_test(cursor, trans_id, inst_id, ident):
|
||||
if delete:
|
||||
for (trans_id,) in trans_ids:
|
||||
cursor.execute('DELETE FROM wkf_witm_trans ' \
|
||||
'WHERE trans_id = %d AND inst_id = %d',
|
||||
'WHERE trans_id = %s AND inst_id = %s',
|
||||
(trans_id, inst_id))
|
||||
create(cursor, [activity], inst_id, ident)
|
||||
Reference in new issue
Block a user