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