From 9d47feca75ea3778021284608f2fd050ec7b1563 Mon Sep 17 00:00:00 2001 From: jlaine Date: Mon, 11 Apr 2011 12:29:59 +0000 Subject: [PATCH] improve phony execute_sql() git-svn-id: https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk@1034 e071eeec-0327-468d-9b6a-08194a12b294 --- ldapdb/backends/ldap/compiler.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) 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 -- 2.30.2