X-Git-Url: https://git.jsancho.org/?p=mojodb.git;a=blobdiff_plain;f=cursor.py;h=ca9e2a4cc0f902dd8a3261b854ba35d64207b97e;hp=73a0c1361ace1aaba045091ce9599f5bbddd742e;hb=4a34db8a057d135225e70ede89b767e89f827c8f;hpb=792f961fb96bb8533e540970c54f43b958d77296 diff --git a/cursor.py b/cursor.py index 73a0c13..ca9e2a4 100644 --- a/cursor.py +++ b/cursor.py @@ -89,14 +89,20 @@ class Cursor(object): query['where'] = [] for k, v in self.spec.iteritems(): table_f = '%s$%s' % (self.collection.table_name, k) - field_q = self._get_cursor_field(table_id, table_f) - query['where'].append((field_q, '=', v)) + if k == u'_id': + query['where'].append(((table_id, 'id'), '=', cPickle.dumps(v))) + elif type(v) in (int, float): + field_q = self._get_cursor_field(table_id, table_f, field_name='number') + query['where'].append((field_q, '=', v)) + else: + field_q = self._get_cursor_field(table_id, table_f) + query['where'].append((field_q, '=', cPickle.dumps(v))) return self.collection.database.connection._get_cursor(self.collection.database.db_name, query) - def _get_cursor_field(self, table_id, table_field): + def _get_cursor_field(self, table_id, table_field, field_name='value'): return { - 'select': [(table_field, 'value')], + 'select': [(table_field, field_name)], 'from': [table_field], 'where': [((table_field, 'id'), '=', (table_id, 'id'))], } @@ -111,9 +117,9 @@ class Cursor(object): raise StopIteration else: document = {} - if '_id' in self.fields: - document['_id'] = res[0] - fields_without_id = filter(lambda x: x != '_id', self.fields) + if u'_id' in self.fields: + document[u'_id'] = cPickle.loads(res[0]) + fields_without_id = filter(lambda x: x != u'_id', self.fields) for i in xrange(len(fields_without_id)): if not res[i + 1] is None: document[fields_without_id[i]] = cPickle.loads(res[i + 1])