support for COUNT(DISTINCT ...) (closes: #71414)

authorSylvain Thénault <sylvain.thenault@logilab.fr>
changeset8b3c9374f940
branchdefault
phasepublic
hiddenno
parent revision#48df22505858 fix checking of maximum number of function (closes: #71413)
child revision#d0454b4f84df sqlite has no boolean type, should use 0 and 1
files modified by this revision
ChangeLog
__init__.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1311687728 -7200
# Tue Jul 26 15:42:08 2011 +0200
# Node ID 8b3c9374f940c096eb272b62a48d5bad02508361
# Parent 48df22505858d91b19a8f32278dbe7aaee4c62c4
support for COUNT(DISTINCT ...) (closes: #71414)

diff --git a/ChangeLog b/ChangeLog
@@ -3,10 +3,11 @@
1 
2  --
3      * [fti] exclude numbers from stop words in fti parser (closes: #69471)
4      * fix backup/restore commands for sqlite backend (closes: #69607)
5      * fix checking of maximum number of function (closes: #71413)
6 +    * support for COUNT(DISTINCT ...) (closes: #71414)
7 
8  2011-06-09  --  1.6.0
9      * new CAST function
10 
11      * new methods on db_helpers to support regexp-based pattern
diff --git a/__init__.py b/__init__.py
@@ -403,12 +403,19 @@
12      rtype = None
13 
14  class MAX(AggrFunctionDescr): pass
15  class MIN(AggrFunctionDescr): pass
16  class SUM(AggrFunctionDescr): pass
17 +
18  class COUNT(AggrFunctionDescr):
19      rtype = 'Int'
20 +    maxargs = 2
21 +
22 +    def as_sql(self, backend, args):
23 +        if len(args) == 2 and args[1] == get_db_helper(backend).boolean_value(True):
24 +            return '%s(DISTINCT %s)' % (self.name, args[0])
25 +        return '%s(%s)' % (self.name, args[0])
26 
27  class AVG(AggrFunctionDescr):
28      rtype = 'Float'
29 
30  class ABS(FunctionDescr):