X-Git-Url: https://git.stderr.nl/gitweb?p=matthijs%2Fupstream%2Fdjango-ldapdb.git;a=blobdiff_plain;f=ldapdb%2Fbackends%2Fldap%2Fcompiler.py;h=0b6eb7f5336e2b581e9e9097b7b3db38628991e1;hp=7d81981adec2bc95cdde5aedfe992b0946981b42;hb=128dc2edeee9d41b7288f0ef3e3e6183aec70a69;hpb=0dcc0b21337a6bf4859c2a4f13c1951accf7639e 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