add a minimal execute_sql() method to compiler
authorjlaine <jlaine@e071eeec-0327-468d-9b6a-08194a12b294>
Mon, 11 Apr 2011 12:04:39 +0000 (12:04 +0000)
committerjlaine <jlaine@e071eeec-0327-468d-9b6a-08194a12b294>
Mon, 11 Apr 2011 12:04:39 +0000 (12:04 +0000)
git-svn-id: https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk@1033 e071eeec-0327-468d-9b6a-08194a12b294

ldapdb/backends/ldap/compiler.py

index 7d81981adec2bc95cdde5aedfe992b0946981b42..0b6eb7f5336e2b581e9e9097b7b3db38628991e1 100644 (file)
@@ -34,7 +34,7 @@
 
 import ldap
 
-from django.db.models.sql import compiler
+from django.db.models.sql import aggregates, compiler
 from django.db.models.sql.where import AND, OR
 
 def get_lookup_operator(lookup_type):
@@ -92,6 +92,27 @@ class SQLCompiler(object):
         self.connection = connection
         self.using = using
 
+    def execute_sql(self, result_type=compiler.MULTI):
+        if result_type !=compiler.SINGLE:
+            raise Exception("LDAP does not support MULTI queries")
+
+        try:
+            vals = self.connection.search_s(
+                self.query.model.base_dn,
+                self.query.model.search_scope,
+                filterstr=query_as_ldap(self.query),
+                attrlist=['dn'],
+            )
+        except ldap.NO_SUCH_OBJECT:
+            vals = []
+
+        output = []
+        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))
+        return output
+
     def results_iter(self):
         if self.query.select_fields:
             fields = self.query.select_fields