improve phony execute_sql()
authorjlaine <jlaine@e071eeec-0327-468d-9b6a-08194a12b294>
Mon, 11 Apr 2011 12:29:59 +0000 (12:29 +0000)
committerjlaine <jlaine@e071eeec-0327-468d-9b6a-08194a12b294>
Mon, 11 Apr 2011 12:29:59 +0000 (12:29 +0000)
git-svn-id: https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk@1034 e071eeec-0327-468d-9b6a-08194a12b294

ldapdb/backends/ldap/compiler.py

index 0b6eb7f5336e2b581e9e9097b7b3db38628991e1..972606ff4589147a60ec52aa36b26038e047dbe5 100644 (file)
@@ -96,6 +96,10 @@ class SQLCompiler(object):
         if result_type !=compiler.SINGLE:
             raise Exception("LDAP does not support MULTI queries")
 
+        for key, aggregate in self.query.aggregate_select.items():
+            if not isinstance(aggregate, aggregates.Count):
+                raise Exception("Unsupported aggregate %s" % aggregate)
+
         try:
             vals = self.connection.search_s(
                 self.query.model.base_dn,
@@ -106,11 +110,17 @@ class SQLCompiler(object):
         except ldap.NO_SUCH_OBJECT:
             vals = []
 
+        if not vals:
+            return None
+
         output = []
+        for alias, col in self.query.extra_select.iteritems():
+            output.append(col[0])
         for key, aggregate in self.query.aggregate_select.items():
-            if not isinstance(aggregate, aggregates.Count):
-                raise Exception("Unsupported aggregate %s" % aggregate)
-            output.append(len(vals))
+            if isinstance(aggregate, aggregates.Count):
+                output.append(len(vals))
+            else:
+                output.append(None)
         return output
 
     def results_iter(self):
@@ -190,7 +200,7 @@ class SQLDeleteCompiler(compiler.SQLDeleteCompiler, SQLCompiler):
                 self.query.model.base_dn,
                 self.query.model.search_scope,
                 filterstr=query_as_ldap(self.query),
-                attrlist=[],
+                attrlist=['dn'],
             )
         except ldap.NO_SUCH_OBJECT:
             return