]> git.jsancho.org Git - mojodb.git/blobdiff - cursor.py
msgpack instead cPickle (for multiple platforms) and str instead unicode (thinking...
[mojodb.git] / cursor.py
index 202c6c78aabb6429a8b8cd012b616e9f921a6169..ef6328028141994ca9e775fb13f6a4be67f5604a 100644 (file)
--- a/cursor.py
+++ b/cursor.py
@@ -19,7 +19,7 @@
 #
 ##############################################################################
 
-import cPickle
+import msgpack
 
 class Cursor(object):
     def __init__(self, collection, spec=None, fields=None, **kwargs):
@@ -89,12 +89,14 @@ class Cursor(object):
             query['where'] = []
             for k, v in self.spec.iteritems():
                 table_f = '%s$%s' % (self.collection.table_name, k)
-                if type(v) in (int, float):
+                if k == '_id':
+                    query['where'].append(((table_id, 'id'), '=', msgpack.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)))
+                    query['where'].append((field_q, '=', msgpack.dumps(v)))
 
         return self.collection.database.connection._get_cursor(self.collection.database.db_name, query)
 
@@ -116,11 +118,11 @@ class Cursor(object):
             else:
                 document = {}
                 if '_id' in self.fields:
-                    document['_id'] = res[0]
+                    document['_id'] = msgpack.loads(res[0])
                 fields_without_id = filter(lambda x: x != '_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])
+                        document[fields_without_id[i]] = msgpack.loads(res[i + 1])
                 return document
         else:
             return None