|
1 """Common subpackage of cubicweb : defines library functions used both on the |
|
2 hg stserver side and on the client side |
|
3 |
|
4 :organization: Logilab |
|
5 :copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
|
6 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
7 """ |
|
8 |
|
9 from logilab.common.adbh import FunctionDescr |
|
10 |
|
11 from cubicweb._exceptions import * # bw compat |
|
12 |
|
13 from rql.utils import register_function, iter_funcnode_variables |
|
14 |
|
15 class COMMA_JOIN(FunctionDescr): |
|
16 supported_backends = ('postgres', 'sqlite',) |
|
17 rtype = 'String' |
|
18 |
|
19 @classmethod |
|
20 def st_description(cls, funcnode): |
|
21 return ', '.join(term.get_description() |
|
22 for term in iter_funcnode_variables(funcnode)) |
|
23 |
|
24 register_function(COMMA_JOIN) # XXX do not expose? |
|
25 |
|
26 |
|
27 class CONCAT_STRINGS(COMMA_JOIN): |
|
28 aggregat = True |
|
29 |
|
30 register_function(CONCAT_STRINGS) # XXX bw compat |
|
31 |
|
32 class GROUP_CONCAT(CONCAT_STRINGS): |
|
33 supported_backends = ('mysql', 'postgres', 'sqlite',) |
|
34 |
|
35 register_function(GROUP_CONCAT) |
|
36 |
|
37 |
|
38 class LIMIT_SIZE(FunctionDescr): |
|
39 supported_backends = ('postgres', 'sqlite',) |
|
40 rtype = 'String' |
|
41 |
|
42 @classmethod |
|
43 def st_description(cls, funcnode): |
|
44 return funcnode.children[0].get_description() |
|
45 |
|
46 register_function(LIMIT_SIZE) |
|
47 |
|
48 |
|
49 class TEXT_LIMIT_SIZE(LIMIT_SIZE): |
|
50 supported_backends = ('mysql', 'postgres', 'sqlite',) |
|
51 |
|
52 register_function(TEXT_LIMIT_SIZE) |