Commits

FrnkNglrt  committed c43c652

Added a sql like representation to the NonrelQuery to fix issues with the django cache machine extension

  • Participants
  • Parent commits 957ea5f

Comments (0)

Files changed (1)

File djangotoolbox/db/basecompiler.py

         self.connection = compiler.connection
         self.query = self.compiler.query
         self._negated = False
+        self.filters = {}
 
     def fetch(self, low_mark=0, high_mark=None):
         raise NotImplementedError('Not implemented')
                 continue
 
             column, lookup_type, db_type, value = self._decode_child(child)
+            
+            self.filters[str(column)] = " " + lookup_type + " " + str(value)
             self.add_filter(column, lookup_type, self._negated, db_type, value)
 
         if filters.negated:
 
     def convert_value_for_db(self, db_type, value):
         return self.compiler.convert_value_for_db(db_type, value)
+        
+    def _concat_list(self, list, start, delimiter):
+    	if len(list) == 0:
+    		return ""
+    	elif len(list) == 1:
+    		return start +" " + list[0]
+    	else:
+    		return start + " " + reduce(lambda a,b:a+delimiter+b, list)
+    
+    # This is needed for debugging
+    def __repr__(self):
+        where_filters = [key + value for key,value in self.filters.iteritems()]
+    	where_cond = self._concat_list(where_filters, "WHERE", " AND ")
+    	order_cond = self._concat_list(self.compiler._get_ordering(), "ORDER BY", ", ")
+            
+        return '<NonrelQuery: SELECT * from %s %s %s>' % (self.db_table, where_cond, order_cond)
 
 class NonrelCompiler(SQLCompiler):
     """
                     result.append(name)
                 else:
                     result.append('-' + name)
+
         return result
 
 class NonrelInsertCompiler(object):