From: jlaine Date: Mon, 11 Apr 2011 12:04:39 +0000 (+0000) Subject: add a minimal execute_sql() method to compiler X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=128dc2edeee9d41b7288f0ef3e3e6183aec70a69;p=matthijs%2Fupstream%2Fdjango-ldapdb.git add a minimal execute_sql() method to compiler git-svn-id: https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk@1033 e071eeec-0327-468d-9b6a-08194a12b294 --- diff --git a/ldapdb/backends/ldap/compiler.py b/ldapdb/backends/ldap/compiler.py index 7d81981..0b6eb7f 100644 --- a/ldapdb/backends/ldap/compiler.py +++ b/ldapdb/backends/ldap/compiler.py @@ -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