This commit is contained in:
Cédric Krier
2008-02-03 02:22:32 +01:00
2 changed files with 42 additions and 27 deletions
+12 -9
View File
@@ -215,11 +215,11 @@ class ModelData(OSV):
if (fs_id, module) in self.fs2db[cursor.dbname]:
return self.fs2db[cursor.dbname][(fs_id, module)][0]
else:
raise Exception("Reference to %s not found"% ".".join([module,fs_id]))
raise Exception("Reference to %s not found"%\
".".join([module,fs_id]))
def _clean_value(self, key, browse_record, object_ref):
# XXX self is no use, move this outside the class ?
@staticmethod
def _clean_value(key, browse_record, object_ref):
"""
Take a field name, a browse_record, and a reference to the
corresponding object. Return a raw value has it must look on the
@@ -278,7 +278,7 @@ class ModelData(OSV):
for key in values:
try:
db_field = self._clean_value(key, db_values, object_ref)
db_field = ModelData._clean_value(key, db_values, object_ref)
except Unhandled_field:
logger = Logger()
logger.notify_channel('init', LOG_WARNING,
@@ -301,11 +301,13 @@ class ModelData(OSV):
(key, db_id, model, fs_id))
continue
elif (old_values[key] and db_field) and old_values[key] != db_field:
elif (old_values[key] and db_field) and \
old_values[key] != db_field:
logger = Logger()
logger.notify_channel('init', LOG_WARNING,
"Field %s of %s@%s not updated (id: %s), because "\
"it has changed since the last update."% (key, db_id, model, fs_id))
"it has changed since the last update."%\
(key, db_id, model, fs_id))
continue
# so, the field in the fs and in the db are different,
@@ -321,7 +323,8 @@ class ModelData(OSV):
db_val = object_ref.browse(cursor, user, db_id)
for key in to_update:
try:
values[key] = self._clean_value(key, db_val, object_ref)
values[key] = ModelData._clean_value(
key, db_val, object_ref)
except Unhandled_field:
continue
@@ -346,7 +349,7 @@ class ModelData(OSV):
db_val = object_ref.browse(cursor, user, db_id)
for key in values:
try:
values[key] = self._clean_value(key, db_val, object_ref)
values[key] = ModelData._clean_value(key, db_val, object_ref)
except Unhandled_field:
continue
+30 -18
View File
@@ -1846,9 +1846,9 @@ class ORM(object):
tables = ['"' + self._table + '"']
joins = []
while i < len(args):
if args[i][1] == 'inselect':
raise ExceptORM('ValidateError',
'The clause \'inselect\' can not be used!')
if args[i][1] not in ('child_of','=','like','ilike','','!=','in'):
raise ExceptORM("Argument '%s' not supported"% args[i][1],"")
table = self
if args[i][0] in self._inherit_fields:
table = self.pool.get(self._inherit_fields[args[i][0]][0])
@@ -1910,10 +1910,13 @@ class ORM(object):
for i in range((len(ids2) / ID_MAX) + \
(len(ids2) % ID_MAX)):
sub_ids = ids2[ID_MAX * i:ID_MAX * (i + 1)]
cursor.execute('SELECT "' + field._fields_id + \
'" FROM "' + field_obj._table + '" ' \
'WHERE id IN (' + \
','.join([str(x) for x in sub_ids2]) + ')')
cursor.execute(
'SELECT "' + field._fields_id + \
'" FROM "' + field_obj._table + '" ' \
'WHERE id IN (' + \
','.join(['%s' for x in sub_ids2]) + ')',
[str(x) for x in sub_ids2])
ids3.extend([x[0] for x in cursor.fetchall()])
args[i] = ('id', 'in', ids3)
@@ -1940,10 +1943,13 @@ class ORM(object):
return ids
if not len(ids):
return []
cursor.execute('SELECT "' + field._id1 + '" ' \
'FROM "' + field._rel + '" ' \
'WHERE "' + field._id2 + '" IN (' + \
','.join([str(x) for x in ids]) + ')')
cursor.execute(
'SELECT "' + field._id1 + '" ' \
'FROM "' + field._rel + '" ' \
'WHERE "' + field._id2 + '" IN (' + \
','.join(['%s' for x in ids]) + ')',
[str(x) for x in ids])
ids = [x[0] for x in cursor.fetchall()]
return ids
@@ -1959,10 +1965,13 @@ class ORM(object):
if not len(res_ids):
args[i] = ('id', 'in', [0])
else:
cursor.execute('SELECT "' + field._id1 + '" ' \
'FROM "' + field._rel + '" ' \
'WHERE "' + field._id2 + '" IN (' + \
','.join([str(x) for x in res_ids]) + ')')
cursor.execute(
'SELECT "' + field._id1 + '" ' \
'FROM "' + field._rel + '" ' \
'WHERE "' + field._id2 + '" IN (' + \
','.join(['%s' for x in res_ids]) + ')',
[str(x) for x in res_ids])
args[i] = ('id', 'in',
[x[0] for x in cursor.fetchall()])
i += 1
@@ -2125,10 +2134,13 @@ class ORM(object):
qu1 = ' WHERE ' + ' AND '.join(qu1)
else:
qu1 = ''
order_by = order or self._order
#XXX should be better if order where smthg like [('name','desc'),('name','asc')]:
order_by = order and order.replace(';','\;') or self._order
limit_str = limit and ' LIMIT %d' % limit or ''
offset_str = offset and ' OFFSET %d' % offset or ''
limit_str = limit and (type(limit) in (float, int, long))\
and ' LIMIT %d' % limit or ''
offset_str = offset and (type(limit) in (float, int, long))\
and ' OFFSET %d' % offset or ''
# construct a clause for the rules :