anothr attempt to fix mongodb adapter
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 1.99.7 (2012-05-10 08:17:55) dev
|
Version 1.99.7 (2012-05-10 15:12:10) dev
|
||||||
|
|||||||
+33
-45
@@ -4623,30 +4623,19 @@ class MongoDBAdapter(NoSQLAdapter):
|
|||||||
if orderby:
|
if orderby:
|
||||||
#print "in if orderby %s" % orderby
|
#print "in if orderby %s" % orderby
|
||||||
if isinstance(orderby, (list, tuple)):
|
if isinstance(orderby, (list, tuple)):
|
||||||
print "in xorify"
|
|
||||||
orderby = xorify(orderby)
|
orderby = xorify(orderby)
|
||||||
|
|
||||||
|
|
||||||
# !!!! need to add 'random'
|
# !!!! need to add 'random'
|
||||||
for f in self.expand(orderby).split(','):
|
for f in self.expand(orderby).split(','):
|
||||||
if f.startswith('-'):
|
if f.startswith('-'):
|
||||||
mongosort_list.append((f[1:],-1))
|
mongosort_list.append((f[1:],-1))
|
||||||
else:
|
else:
|
||||||
mongosort_list.append((f,1))
|
mongosort_list.append((f,1))
|
||||||
print "mongosort_list = %s" % mongosort_list
|
|
||||||
|
|
||||||
if limitby:
|
if limitby:
|
||||||
# a tuple
|
limitby_skip, limitby_limit = limitby
|
||||||
limitby_skip,limitby_limit = limitby
|
|
||||||
else:
|
else:
|
||||||
limitby_skip = 0
|
limitby_skip = limitby_limit = 0
|
||||||
limitby_limit = 0
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if distinct:
|
|
||||||
#print "in distinct %s" % distinct
|
|
||||||
|
|
||||||
mongofields_dict = son.SON()
|
mongofields_dict = son.SON()
|
||||||
mongoqry_dict = {}
|
mongoqry_dict = {}
|
||||||
@@ -4662,52 +4651,51 @@ class MongoDBAdapter(NoSQLAdapter):
|
|||||||
tablename = fields[0].tablename
|
tablename = fields[0].tablename
|
||||||
else:
|
else:
|
||||||
raise SyntaxError, "The table name could not be found in the query nor from the select statement."
|
raise SyntaxError, "The table name could not be found in the query nor from the select statement."
|
||||||
fieldnames = [f for f in (fields or self.db[tablename])] # ie table.field
|
|
||||||
mongoqry_dict = self.expand(query)
|
mongoqry_dict = self.expand(query)
|
||||||
for f in fieldnames:
|
fields = fields or self.db[tablename]
|
||||||
mongofields_dict[f.name] = 1 # ie field=1
|
for field in fields:
|
||||||
return tablename, mongoqry_dict, mongofields_dict, mongosort_list, limitby_limit, limitby_skip
|
mongofields_dict[field.name] = 1
|
||||||
|
return tablename, mongoqry_dict, mongofields_dict, \
|
||||||
|
mongosort_list, limitby_limit, limitby_skip
|
||||||
|
|
||||||
# need to define all the 'sql' methods gt,lt etc....
|
# need to define all the 'sql' methods gt,lt etc....
|
||||||
|
|
||||||
def select(self,query,fields,attributes,count=False,snapshot=False):
|
def select(self,query,fields,attributes,count=False,snapshot=False):
|
||||||
withId=False
|
tablename, mongoqry_dict, mongofields_dict,
|
||||||
tablename, mongoqry_dict , mongofields_dict, mongosort_list, limitby_limit, limitby_skip = self._select(query,fields,attributes)
|
mongosort_list, limitby_limit, limitby_skip = \
|
||||||
for key in mongofields_dict.keys():
|
self._select(query,fields,attributes)
|
||||||
if key == 'id':
|
|
||||||
withId = True
|
|
||||||
break
|
|
||||||
try:
|
|
||||||
print "mongoqry_dict=%s" % mongoqry_dict
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
print "mongofields_dict=%s" % mongofields_dict
|
|
||||||
ctable = self.connection[tablename]
|
ctable = self.connection[tablename]
|
||||||
if count:
|
if count:
|
||||||
return {'count' : ctable.find(mongoqry_dict,mongofields_dict,
|
return {'count' : ctable.find(
|
||||||
skip=limitby_skip, limit=limitby_limit,
|
mongoqry_dict, mongofields_dict,
|
||||||
sort=mongosort_list,snapshot=snapshot).count()}
|
skip=limitby_skip, limit=limitby_limit,
|
||||||
|
sort=mongosort_list, snapshot=snapshot).count()}
|
||||||
else:
|
else:
|
||||||
mongo_list_dicts = ctable.find(mongoqry_dict,mongofields_dict,
|
mongo_list_dicts = ctable.find(
|
||||||
skip=limitby_skip, limit=limitby_limit,
|
mongoqry_dict, mongofields_dict,
|
||||||
sort=mongosort_list,snapshot=snapshot) # pymongo cursor object
|
skip=limitby_skip, limit=limitby_limit,
|
||||||
|
sort=mongosort_list, snapshot=snapshot) # pymongo cursor object
|
||||||
print "mongo_list_dicts=%s" % mongo_list_dicts
|
print "mongo_list_dicts=%s" % mongo_list_dicts
|
||||||
rows = []
|
rows = []
|
||||||
colnames = []
|
### populate row in proper order
|
||||||
|
if mongo_list_dicts:
|
||||||
|
def fix(id): return 'id' if id=='_id' else id
|
||||||
|
colnames = [fix(column) for column in mongo_list_dicts[0]]
|
||||||
|
else:
|
||||||
|
colnames = []
|
||||||
for k,record in enumerate(mongo_list_dicts):
|
for k,record in enumerate(mongo_list_dicts):
|
||||||
row=[]
|
row=[]
|
||||||
for column in record:
|
for column in record:
|
||||||
if k==0:
|
if column == '_id' and \
|
||||||
colnames.append(column)
|
isinstance(record[column],pymongo.objectid.ObjectId):
|
||||||
if withId and (column == '_id'):
|
value = int(str(record[column]),16)
|
||||||
if isinstance(record[column],pymongo.objectid.ObjectId):
|
elif column != '_id':
|
||||||
row.append( int(str(record[column]),16))
|
value = record[column]
|
||||||
else:
|
row.append(value)
|
||||||
#in case of alternative key
|
|
||||||
row.append( record[column] )
|
|
||||||
elif not (column == '_id'):
|
|
||||||
row.append(record[column])
|
|
||||||
rows.append(row)
|
rows.append(row)
|
||||||
|
|
||||||
|
table = self.db[tablename]
|
||||||
|
fields = [table[colname] for colname in colnames]
|
||||||
processor = attributes.get('processor',self.parse)
|
processor = attributes.get('processor',self.parse)
|
||||||
return processor(rows,fields,colnames,False)
|
return processor(rows,fields,colnames,False)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user