author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
Wed, 27 Mar 2013 17:09:55 +0100 | |
changeset 8812 | 52af67a2f0a5 |
parent 8695 | 358d8bed9626 |
child 8893 | eebf286b405e |
permissions | -rw-r--r-- |
8457
69ad9a509bc3
[rql2sql] fix generated SQL when an attribute relation with a variable is ored with another attribute relation. Closes #2410405
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8245
diff
changeset
|
1 |
# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
0 | 18 |
"""unit tests for module cubicweb.server.sources.rql2sql""" |
19 |
||
20 |
import sys |
|
7108
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
21 |
import os |
8109
67d540b7f8c8
fix tests broken by lgdb update
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7907
diff
changeset
|
22 |
from datetime import date |
3852
03121ca1f85e
test and fix case where remove_unsused_solutions remove some solutions that should be kept
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3815
diff
changeset
|
23 |
from logilab.common.testlib import TestCase, unittest_main, mock_object |
0 | 24 |
|
25 |
from rql import BadRQLQuery |
|
5768
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
26 |
from rql.utils import register_function, FunctionDescr |
0 | 27 |
|
5768
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
28 |
from cubicweb.devtools import TestServerConfiguration |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
29 |
from cubicweb.devtools.repotest import RQLGeneratorTC |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
30 |
from cubicweb.server.sources.rql2sql import remove_unused_solutions |
0 | 31 |
|
5768
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
32 |
|
0 | 33 |
# add a dumb registered procedure |
34 |
class stockproc(FunctionDescr): |
|
35 |
supported_backends = ('postgres', 'sqlite', 'mysql') |
|
36 |
try: |
|
37 |
register_function(stockproc) |
|
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8457
diff
changeset
|
38 |
except AssertionError as ex: |
0 | 39 |
pass # already registered |
40 |
||
7142
c47381851a3e
[sql generation test] avoid lgdb warnings when a db module is faked
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7108
diff
changeset
|
41 |
|
7108
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
42 |
from logilab import database as db |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
43 |
def monkey_patch_import_driver_module(driver, drivers, quiet=True): |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
44 |
if not driver in drivers: |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
45 |
raise db.UnknownDriver(driver) |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
46 |
for modname in drivers[driver]: |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
47 |
try: |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
48 |
if not quiet: |
7896
4c954e1e73ef
[lint] remove uses of "print >> sys.stderr" (closes #1908571)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7734
diff
changeset
|
49 |
sys.stderr.write('Trying %s\n' % modname) |
7108
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
50 |
module = db.load_module_from_name(modname, use_sys=False) |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
51 |
break |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
52 |
except ImportError: |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
53 |
if not quiet: |
7896
4c954e1e73ef
[lint] remove uses of "print >> sys.stderr" (closes #1908571)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7734
diff
changeset
|
54 |
sys.stderr.write('%s is not available\n' % modname) |
7108
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
55 |
continue |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
56 |
else: |
7142
c47381851a3e
[sql generation test] avoid lgdb warnings when a db module is faked
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7108
diff
changeset
|
57 |
return mock_object(STRING=1, BOOLEAN=2, BINARY=3, DATETIME=4, NUMBER=5), drivers[driver][0] |
7108
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
58 |
return module, modname |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
59 |
|
0 | 60 |
|
6781
5062d86d6ffe
[unittest2] use unittest2 module fixture api
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6631
diff
changeset
|
61 |
def setUpModule(): |
6631
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6493
diff
changeset
|
62 |
global config, schema |
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6493
diff
changeset
|
63 |
config = TestServerConfiguration('data', apphome=CWRQLTC.datadir) |
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6493
diff
changeset
|
64 |
config.bootstrap_cubes() |
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6493
diff
changeset
|
65 |
schema = config.load_schema() |
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6493
diff
changeset
|
66 |
schema['in_state'].inlined = True |
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6493
diff
changeset
|
67 |
schema['state_of'].inlined = False |
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6493
diff
changeset
|
68 |
schema['comments'].inlined = False |
7108
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
69 |
db._backup_import_driver_module = db._import_driver_module |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
70 |
db._import_driver_module = monkey_patch_import_driver_module |
0 | 71 |
|
6781
5062d86d6ffe
[unittest2] use unittest2 module fixture api
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6631
diff
changeset
|
72 |
def tearDownModule(): |
4766
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
73 |
global config, schema |
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
74 |
del config, schema |
7108
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
75 |
db._import_driver_module = db._backup_import_driver_module |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
76 |
del db._backup_import_driver_module |
4766
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
77 |
|
0 | 78 |
PARSER = [ |
79 |
(r"Personne P WHERE P nom 'Zig\'oto';", |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
80 |
'''SELECT _P.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
81 |
FROM cw_Personne AS _P |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
82 |
WHERE _P.cw_nom=Zig\'oto'''), |
0 | 83 |
|
84 |
(r'Personne P WHERE P nom ~= "Zig\"oto%";', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
85 |
'''SELECT _P.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
86 |
FROM cw_Personne AS _P |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
87 |
WHERE _P.cw_nom ILIKE Zig"oto%'''), |
0 | 88 |
] |
89 |
||
90 |
BASIC = [ |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
91 |
("Any AS WHERE AS is Affaire", |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
92 |
'''SELECT _AS.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
93 |
FROM cw_Affaire AS _AS'''), |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
94 |
|
0 | 95 |
("Any X WHERE X is Affaire", |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
96 |
'''SELECT _X.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
97 |
FROM cw_Affaire AS _X'''), |
1787 | 98 |
|
0 | 99 |
("Any X WHERE X eid 0", |
100 |
'''SELECT 0'''), |
|
1787 | 101 |
|
0 | 102 |
("Personne P", |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
103 |
'''SELECT _P.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
104 |
FROM cw_Personne AS _P'''), |
0 | 105 |
|
106 |
("Personne P WHERE P test TRUE", |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
107 |
'''SELECT _P.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
108 |
FROM cw_Personne AS _P |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
109 |
WHERE _P.cw_test=TRUE'''), |
0 | 110 |
|
111 |
("Personne P WHERE P test false", |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
112 |
'''SELECT _P.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
113 |
FROM cw_Personne AS _P |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
114 |
WHERE _P.cw_test=FALSE'''), |
0 | 115 |
|
116 |
("Personne P WHERE P eid -1", |
|
117 |
'''SELECT -1'''), |
|
118 |
||
119 |
("Personne P WHERE S is Societe, P travaille S, S nom 'Logilab';", |
|
120 |
'''SELECT rel_travaille0.eid_from |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
121 |
FROM cw_Societe AS _S, travaille_relation AS rel_travaille0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
122 |
WHERE rel_travaille0.eid_to=_S.cw_eid AND _S.cw_nom=Logilab'''), |
0 | 123 |
|
124 |
("Personne P WHERE P concerne A, A concerne S, S nom 'Logilab', S is Societe;", |
|
125 |
'''SELECT rel_concerne0.eid_from |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
126 |
FROM concerne_relation AS rel_concerne0, concerne_relation AS rel_concerne1, cw_Societe AS _S |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
127 |
WHERE rel_concerne0.eid_to=rel_concerne1.eid_from AND rel_concerne1.eid_to=_S.cw_eid AND _S.cw_nom=Logilab'''), |
0 | 128 |
|
129 |
("Note N WHERE X evaluee N, X nom 'Logilab';", |
|
130 |
'''SELECT rel_evaluee0.eid_to |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
131 |
FROM cw_Division AS _X, evaluee_relation AS rel_evaluee0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
132 |
WHERE rel_evaluee0.eid_from=_X.cw_eid AND _X.cw_nom=Logilab |
0 | 133 |
UNION ALL |
134 |
SELECT rel_evaluee0.eid_to |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
135 |
FROM cw_Personne AS _X, evaluee_relation AS rel_evaluee0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
136 |
WHERE rel_evaluee0.eid_from=_X.cw_eid AND _X.cw_nom=Logilab |
0 | 137 |
UNION ALL |
138 |
SELECT rel_evaluee0.eid_to |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
139 |
FROM cw_Societe AS _X, evaluee_relation AS rel_evaluee0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
140 |
WHERE rel_evaluee0.eid_from=_X.cw_eid AND _X.cw_nom=Logilab |
0 | 141 |
UNION ALL |
142 |
SELECT rel_evaluee0.eid_to |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
143 |
FROM cw_SubDivision AS _X, evaluee_relation AS rel_evaluee0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
144 |
WHERE rel_evaluee0.eid_from=_X.cw_eid AND _X.cw_nom=Logilab'''), |
0 | 145 |
|
146 |
("Note N WHERE X evaluee N, X nom in ('Logilab', 'Caesium');", |
|
147 |
'''SELECT rel_evaluee0.eid_to |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
148 |
FROM cw_Division AS _X, evaluee_relation AS rel_evaluee0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
149 |
WHERE rel_evaluee0.eid_from=_X.cw_eid AND _X.cw_nom IN(Logilab, Caesium) |
0 | 150 |
UNION ALL |
151 |
SELECT rel_evaluee0.eid_to |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
152 |
FROM cw_Personne AS _X, evaluee_relation AS rel_evaluee0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
153 |
WHERE rel_evaluee0.eid_from=_X.cw_eid AND _X.cw_nom IN(Logilab, Caesium) |
0 | 154 |
UNION ALL |
155 |
SELECT rel_evaluee0.eid_to |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
156 |
FROM cw_Societe AS _X, evaluee_relation AS rel_evaluee0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
157 |
WHERE rel_evaluee0.eid_from=_X.cw_eid AND _X.cw_nom IN(Logilab, Caesium) |
0 | 158 |
UNION ALL |
159 |
SELECT rel_evaluee0.eid_to |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
160 |
FROM cw_SubDivision AS _X, evaluee_relation AS rel_evaluee0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
161 |
WHERE rel_evaluee0.eid_from=_X.cw_eid AND _X.cw_nom IN(Logilab, Caesium)'''), |
0 | 162 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
163 |
("Any N WHERE G is CWGroup, G name N, E eid 12, E read_permission G", |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
164 |
'''SELECT _G.cw_name |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
165 |
FROM cw_CWGroup AS _G, read_permission_relation AS rel_read_permission0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
166 |
WHERE rel_read_permission0.eid_from=12 AND rel_read_permission0.eid_to=_G.cw_eid'''), |
0 | 167 |
|
168 |
('Any Y WHERE U login "admin", U login Y', # stupid but valid... |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
169 |
"""SELECT _U.cw_login |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
170 |
FROM cw_CWUser AS _U |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
171 |
WHERE _U.cw_login=admin"""), |
0 | 172 |
|
173 |
('Any T WHERE T tags X, X is State', |
|
174 |
'''SELECT rel_tags0.eid_from |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
175 |
FROM cw_State AS _X, tags_relation AS rel_tags0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
176 |
WHERE rel_tags0.eid_to=_X.cw_eid'''), |
0 | 177 |
|
178 |
('Any X,Y WHERE X eid 0, Y eid 1, X concerne Y', |
|
179 |
'''SELECT 0, 1 |
|
180 |
FROM concerne_relation AS rel_concerne0 |
|
181 |
WHERE rel_concerne0.eid_from=0 AND rel_concerne0.eid_to=1'''), |
|
182 |
||
183 |
("Any X WHERE X prenom 'lulu'," |
|
184 |
"EXISTS(X owned_by U, U in_group G, G name 'lulufanclub' OR G name 'managers');", |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
185 |
'''SELECT _X.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
186 |
FROM cw_Personne AS _X |
7193
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
187 |
WHERE _X.cw_prenom=lulu AND EXISTS(SELECT 1 FROM cw_CWGroup AS _G, in_group_relation AS rel_in_group1, owned_by_relation AS rel_owned_by0 WHERE rel_owned_by0.eid_from=_X.cw_eid AND rel_in_group1.eid_from=rel_owned_by0.eid_to AND rel_in_group1.eid_to=_G.cw_eid AND ((_G.cw_name=lulufanclub) OR (_G.cw_name=managers)))'''), |
0 | 188 |
|
189 |
("Any X WHERE X prenom 'lulu'," |
|
190 |
"NOT EXISTS(X owned_by U, U in_group G, G name 'lulufanclub' OR G name 'managers');", |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
191 |
'''SELECT _X.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
192 |
FROM cw_Personne AS _X |
7193
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
193 |
WHERE _X.cw_prenom=lulu AND NOT (EXISTS(SELECT 1 FROM cw_CWGroup AS _G, in_group_relation AS rel_in_group1, owned_by_relation AS rel_owned_by0 WHERE rel_owned_by0.eid_from=_X.cw_eid AND rel_in_group1.eid_from=rel_owned_by0.eid_to AND rel_in_group1.eid_to=_G.cw_eid AND ((_G.cw_name=lulufanclub) OR (_G.cw_name=managers))))'''), |
3815
50b87f759b5d
test and fix http://www.logilab.org/ticket/499838
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3762
diff
changeset
|
194 |
|
6940
1172c25655b7
[rql2sql] should not select a neged relation as principal + simplify code for sql generation for attribute relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6930
diff
changeset
|
195 |
('Any X WHERE X title V, NOT X wikiid V, NOT X title "parent", X is Card', |
1172c25655b7
[rql2sql] should not select a neged relation as principal + simplify code for sql generation for attribute relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6930
diff
changeset
|
196 |
'''SELECT _X.cw_eid |
1172c25655b7
[rql2sql] should not select a neged relation as principal + simplify code for sql generation for attribute relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6930
diff
changeset
|
197 |
FROM cw_Card AS _X |
7729
5f89f11143bc
[rql2sql] closes #1892471: support for unary expression introduced in rql 0.30
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7724
diff
changeset
|
198 |
WHERE NOT (_X.cw_wikiid=_X.cw_title) AND NOT (_X.cw_title=parent)'''), |
5f89f11143bc
[rql2sql] closes #1892471: support for unary expression introduced in rql 0.30
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7724
diff
changeset
|
199 |
|
5f89f11143bc
[rql2sql] closes #1892471: support for unary expression introduced in rql 0.30
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7724
diff
changeset
|
200 |
("Any -AS WHERE AS is Affaire", |
5f89f11143bc
[rql2sql] closes #1892471: support for unary expression introduced in rql 0.30
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7724
diff
changeset
|
201 |
'''SELECT -_AS.cw_eid |
5f89f11143bc
[rql2sql] closes #1892471: support for unary expression introduced in rql 0.30
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7724
diff
changeset
|
202 |
FROM cw_Affaire AS _AS'''), |
5f89f11143bc
[rql2sql] closes #1892471: support for unary expression introduced in rql 0.30
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7724
diff
changeset
|
203 |
|
5886 | 204 |
] |
3815
50b87f759b5d
test and fix http://www.logilab.org/ticket/499838
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3762
diff
changeset
|
205 |
|
7108
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
206 |
BASIC_WITH_LIMIT = [ |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
207 |
("Personne P LIMIT 20 OFFSET 10", |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
208 |
'''SELECT _P.cw_eid |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
209 |
FROM cw_Personne AS _P |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
210 |
LIMIT 20 |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
211 |
OFFSET 10'''), |
7596
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
212 |
("Any P ORDERBY N LIMIT 1 WHERE P is Personne, P travaille S, S eid %(eid)s, P nom N, P nom %(text)s", |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
213 |
'''SELECT _P.cw_eid |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
214 |
FROM cw_Personne AS _P, travaille_relation AS rel_travaille0 |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
215 |
WHERE rel_travaille0.eid_from=_P.cw_eid AND rel_travaille0.eid_to=12345 AND _P.cw_nom=hip hop momo |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
216 |
ORDER BY _P.cw_nom |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
217 |
LIMIT 1'''), |
7108
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
218 |
] |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
219 |
|
0 | 220 |
|
6929
e9464d975908
[rql2sql] fix bug with NOT in "fake" having terms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6781
diff
changeset
|
221 |
ADVANCED = [ |
8457
69ad9a509bc3
[rql2sql] fix generated SQL when an attribute relation with a variable is ored with another attribute relation. Closes #2410405
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8245
diff
changeset
|
222 |
("Societe S WHERE S2 is Societe, S2 nom SN, S nom 'Logilab' OR S nom SN", |
69ad9a509bc3
[rql2sql] fix generated SQL when an attribute relation with a variable is ored with another attribute relation. Closes #2410405
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8245
diff
changeset
|
223 |
'''SELECT _S.cw_eid |
69ad9a509bc3
[rql2sql] fix generated SQL when an attribute relation with a variable is ored with another attribute relation. Closes #2410405
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8245
diff
changeset
|
224 |
FROM cw_Societe AS _S, cw_Societe AS _S2 |
69ad9a509bc3
[rql2sql] fix generated SQL when an attribute relation with a variable is ored with another attribute relation. Closes #2410405
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8245
diff
changeset
|
225 |
WHERE ((_S.cw_nom=Logilab) OR (_S2.cw_nom=_S.cw_nom))'''), |
69ad9a509bc3
[rql2sql] fix generated SQL when an attribute relation with a variable is ored with another attribute relation. Closes #2410405
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8245
diff
changeset
|
226 |
|
0 | 227 |
("Societe S WHERE S nom 'Logilab' OR S nom 'Caesium'", |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
228 |
'''SELECT _S.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
229 |
FROM cw_Societe AS _S |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
230 |
WHERE ((_S.cw_nom=Logilab) OR (_S.cw_nom=Caesium))'''), |
1787 | 231 |
|
0 | 232 |
('Any X WHERE X nom "toto", X eid IN (9700, 9710, 1045, 674)', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
233 |
'''SELECT _X.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
234 |
FROM cw_Division AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
235 |
WHERE _X.cw_nom=toto AND _X.cw_eid IN(9700, 9710, 1045, 674) |
0 | 236 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
237 |
SELECT _X.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
238 |
FROM cw_Personne AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
239 |
WHERE _X.cw_nom=toto AND _X.cw_eid IN(9700, 9710, 1045, 674) |
0 | 240 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
241 |
SELECT _X.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
242 |
FROM cw_Societe AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
243 |
WHERE _X.cw_nom=toto AND _X.cw_eid IN(9700, 9710, 1045, 674) |
0 | 244 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
245 |
SELECT _X.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
246 |
FROM cw_SubDivision AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
247 |
WHERE _X.cw_nom=toto AND _X.cw_eid IN(9700, 9710, 1045, 674)'''), |
0 | 248 |
|
249 |
('Any Y, COUNT(N) GROUPBY Y WHERE Y evaluee N;', |
|
250 |
'''SELECT rel_evaluee0.eid_from, COUNT(rel_evaluee0.eid_to) |
|
251 |
FROM evaluee_relation AS rel_evaluee0 |
|
252 |
GROUP BY rel_evaluee0.eid_from'''), |
|
253 |
||
254 |
("Any X WHERE X concerne B or C concerne X", |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
255 |
'''SELECT _X.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
256 |
FROM concerne_relation AS rel_concerne0, concerne_relation AS rel_concerne1, cw_Affaire AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
257 |
WHERE ((rel_concerne0.eid_from=_X.cw_eid) OR (rel_concerne1.eid_to=_X.cw_eid))'''), |
0 | 258 |
|
259 |
("Any X WHERE X travaille S or X concerne A", |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
260 |
'''SELECT _X.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
261 |
FROM concerne_relation AS rel_concerne1, cw_Personne AS _X, travaille_relation AS rel_travaille0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
262 |
WHERE ((rel_travaille0.eid_from=_X.cw_eid) OR (rel_concerne1.eid_from=_X.cw_eid))'''), |
0 | 263 |
|
264 |
("Any N WHERE A evaluee N or N ecrit_par P", |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
265 |
'''SELECT _N.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
266 |
FROM cw_Note AS _N, evaluee_relation AS rel_evaluee0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
267 |
WHERE ((rel_evaluee0.eid_to=_N.cw_eid) OR (_N.cw_ecrit_par IS NOT NULL))'''), |
0 | 268 |
|
269 |
("Any N WHERE A evaluee N or EXISTS(N todo_by U)", |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
270 |
'''SELECT _N.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
271 |
FROM cw_Note AS _N, evaluee_relation AS rel_evaluee0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
272 |
WHERE ((rel_evaluee0.eid_to=_N.cw_eid) OR (EXISTS(SELECT 1 FROM todo_by_relation AS rel_todo_by1 WHERE rel_todo_by1.eid_from=_N.cw_eid)))'''), |
0 | 273 |
|
274 |
("Any N WHERE A evaluee N or N todo_by U", |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
275 |
'''SELECT _N.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
276 |
FROM cw_Note AS _N, evaluee_relation AS rel_evaluee0, todo_by_relation AS rel_todo_by1 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
277 |
WHERE ((rel_evaluee0.eid_to=_N.cw_eid) OR (rel_todo_by1.eid_from=_N.cw_eid))'''), |
1787 | 278 |
|
0 | 279 |
("Any X WHERE X concerne B or C concerne X, B eid 12, C eid 13", |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
280 |
'''SELECT _X.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
281 |
FROM concerne_relation AS rel_concerne0, concerne_relation AS rel_concerne1, cw_Affaire AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
282 |
WHERE ((rel_concerne0.eid_from=_X.cw_eid AND rel_concerne0.eid_to=12) OR (rel_concerne1.eid_from=13 AND rel_concerne1.eid_to=_X.cw_eid))'''), |
0 | 283 |
|
284 |
('Any X WHERE X created_by U, X concerne B OR C concerne X, B eid 12, C eid 13', |
|
285 |
'''SELECT rel_created_by0.eid_from |
|
286 |
FROM concerne_relation AS rel_concerne1, concerne_relation AS rel_concerne2, created_by_relation AS rel_created_by0 |
|
287 |
WHERE ((rel_concerne1.eid_from=rel_created_by0.eid_from AND rel_concerne1.eid_to=12) OR (rel_concerne2.eid_from=13 AND rel_concerne2.eid_to=rel_created_by0.eid_from))'''), |
|
288 |
||
289 |
('Any P WHERE P travaille_subdivision S1 OR P travaille_subdivision S2, S1 nom "logilab", S2 nom "caesium"', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
290 |
'''SELECT _P.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
291 |
FROM cw_Personne AS _P, cw_SubDivision AS _S1, cw_SubDivision AS _S2, travaille_subdivision_relation AS rel_travaille_subdivision0, travaille_subdivision_relation AS rel_travaille_subdivision1 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
292 |
WHERE ((rel_travaille_subdivision0.eid_from=_P.cw_eid AND rel_travaille_subdivision0.eid_to=_S1.cw_eid) OR (rel_travaille_subdivision1.eid_from=_P.cw_eid AND rel_travaille_subdivision1.eid_to=_S2.cw_eid)) AND _S1.cw_nom=logilab AND _S2.cw_nom=caesium'''), |
0 | 293 |
|
294 |
('Any X WHERE T tags X', |
|
295 |
'''SELECT rel_tags0.eid_to |
|
296 |
FROM tags_relation AS rel_tags0'''), |
|
1787 | 297 |
|
0 | 298 |
('Any X WHERE X in_basket B, B eid 12', |
299 |
'''SELECT rel_in_basket0.eid_from |
|
300 |
FROM in_basket_relation AS rel_in_basket0 |
|
301 |
WHERE rel_in_basket0.eid_to=12'''), |
|
1787 | 302 |
|
0 | 303 |
('Any SEN,RN,OEN WHERE X from_entity SE, SE eid 44, X relation_type R, R eid 139, X to_entity OE, OE eid 42, R name RN, SE name SEN, OE name OEN', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
304 |
'''SELECT _SE.cw_name, _R.cw_name, _OE.cw_name |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
305 |
FROM cw_CWAttribute AS _X, cw_CWEType AS _OE, cw_CWEType AS _SE, cw_CWRType AS _R |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
306 |
WHERE _X.cw_from_entity=44 AND _SE.cw_eid=44 AND _X.cw_relation_type=139 AND _R.cw_eid=139 AND _X.cw_to_entity=42 AND _OE.cw_eid=42 |
0 | 307 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
308 |
SELECT _SE.cw_name, _R.cw_name, _OE.cw_name |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
309 |
FROM cw_CWEType AS _OE, cw_CWEType AS _SE, cw_CWRType AS _R, cw_CWRelation AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
310 |
WHERE _X.cw_from_entity=44 AND _SE.cw_eid=44 AND _X.cw_relation_type=139 AND _R.cw_eid=139 AND _X.cw_to_entity=42 AND _OE.cw_eid=42'''), |
0 | 311 |
|
312 |
# Any O WHERE NOT S corrected_in O, S eid %(x)s, S concerns P, O version_of P, O in_state ST, NOT ST name "published", O modification_date MTIME ORDERBY MTIME DESC LIMIT 9 |
|
313 |
('Any O WHERE NOT S ecrit_par O, S eid 1, S inline1 P, O inline2 P', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
314 |
'''SELECT _O.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
315 |
FROM cw_Note AS _S, cw_Personne AS _O |
6003
5fbc1c4c13ff
[rql2sql] fix bug with NOT of inlined relation: NULL values are not properly handled and hence some rows won't be returned while the should
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5901
diff
changeset
|
316 |
WHERE (_S.cw_ecrit_par IS NULL OR _S.cw_ecrit_par!=_O.cw_eid) AND _S.cw_eid=1 AND _S.cw_inline1 IS NOT NULL AND _O.cw_inline2=_S.cw_inline1'''), |
0 | 317 |
|
318 |
('Any N WHERE N todo_by U, N is Note, U eid 2, N filed_under T, T eid 3', |
|
319 |
# N would actually be invarient if U eid 2 had given a specific type to U |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
320 |
'''SELECT _N.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
321 |
FROM cw_Note AS _N, filed_under_relation AS rel_filed_under1, todo_by_relation AS rel_todo_by0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
322 |
WHERE rel_todo_by0.eid_from=_N.cw_eid AND rel_todo_by0.eid_to=2 AND rel_filed_under1.eid_from=_N.cw_eid AND rel_filed_under1.eid_to=3'''), |
0 | 323 |
|
324 |
('Any N WHERE N todo_by U, U eid 2, P evaluee N, P eid 3', |
|
325 |
'''SELECT rel_evaluee1.eid_to |
|
326 |
FROM evaluee_relation AS rel_evaluee1, todo_by_relation AS rel_todo_by0 |
|
327 |
WHERE rel_evaluee1.eid_to=rel_todo_by0.eid_from AND rel_todo_by0.eid_to=2 AND rel_evaluee1.eid_from=3'''), |
|
328 |
||
1787 | 329 |
|
0 | 330 |
(' Any X,U WHERE C owned_by U, NOT X owned_by U, C eid 1, X eid 2', |
331 |
'''SELECT 2, rel_owned_by0.eid_to |
|
332 |
FROM owned_by_relation AS rel_owned_by0 |
|
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
333 |
WHERE rel_owned_by0.eid_from=1 AND NOT (EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by1 WHERE rel_owned_by1.eid_from=2 AND rel_owned_by0.eid_to=rel_owned_by1.eid_to))'''), |
0 | 334 |
|
335 |
('Any GN WHERE X in_group G, G name GN, (G name "managers" OR EXISTS(X copain T, T login in ("comme", "cochon")))', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
336 |
'''SELECT _G.cw_name |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
337 |
FROM cw_CWGroup AS _G, in_group_relation AS rel_in_group0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
338 |
WHERE rel_in_group0.eid_to=_G.cw_eid AND ((_G.cw_name=managers) OR (EXISTS(SELECT 1 FROM copain_relation AS rel_copain1, cw_CWUser AS _T WHERE rel_copain1.eid_from=rel_in_group0.eid_from AND rel_copain1.eid_to=_T.cw_eid AND _T.cw_login IN(comme, cochon))))'''), |
0 | 339 |
|
340 |
('Any C WHERE C is Card, EXISTS(X documented_by C)', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
341 |
"""SELECT _C.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
342 |
FROM cw_Card AS _C |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
343 |
WHERE EXISTS(SELECT 1 FROM documented_by_relation AS rel_documented_by0 WHERE rel_documented_by0.eid_to=_C.cw_eid)"""), |
1787 | 344 |
|
0 | 345 |
('Any C WHERE C is Card, EXISTS(X documented_by C, X eid 12)', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
346 |
"""SELECT _C.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
347 |
FROM cw_Card AS _C |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
348 |
WHERE EXISTS(SELECT 1 FROM documented_by_relation AS rel_documented_by0 WHERE rel_documented_by0.eid_from=12 AND rel_documented_by0.eid_to=_C.cw_eid)"""), |
0 | 349 |
|
350 |
('Any T WHERE C is Card, C title T, EXISTS(X documented_by C, X eid 12)', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
351 |
"""SELECT _C.cw_title |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
352 |
FROM cw_Card AS _C |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
353 |
WHERE EXISTS(SELECT 1 FROM documented_by_relation AS rel_documented_by0 WHERE rel_documented_by0.eid_from=12 AND rel_documented_by0.eid_to=_C.cw_eid)"""), |
0 | 354 |
|
355 |
('Any GN,L WHERE X in_group G, X login L, G name GN, EXISTS(X copain T, T login L, T login IN("comme", "cochon"))', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
356 |
'''SELECT _G.cw_name, _X.cw_login |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
357 |
FROM cw_CWGroup AS _G, cw_CWUser AS _X, in_group_relation AS rel_in_group0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
358 |
WHERE rel_in_group0.eid_from=_X.cw_eid AND rel_in_group0.eid_to=_G.cw_eid AND EXISTS(SELECT 1 FROM copain_relation AS rel_copain1, cw_CWUser AS _T WHERE rel_copain1.eid_from=_X.cw_eid AND rel_copain1.eid_to=_T.cw_eid AND _T.cw_login=_X.cw_login AND _T.cw_login IN(comme, cochon))'''), |
0 | 359 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
360 |
('Any X,S, MAX(T) GROUPBY X,S ORDERBY S WHERE X is CWUser, T tags X, S eid IN(32), X in_state S', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
361 |
'''SELECT _X.cw_eid, 32, MAX(rel_tags0.eid_from) |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
362 |
FROM cw_CWUser AS _X, tags_relation AS rel_tags0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
363 |
WHERE rel_tags0.eid_to=_X.cw_eid AND _X.cw_in_state=32 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
364 |
GROUP BY _X.cw_eid'''), |
0 | 365 |
|
366 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
367 |
('Any X WHERE Y evaluee X, Y is CWUser', |
0 | 368 |
'''SELECT rel_evaluee0.eid_to |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
369 |
FROM cw_CWUser AS _Y, evaluee_relation AS rel_evaluee0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
370 |
WHERE rel_evaluee0.eid_from=_Y.cw_eid'''), |
0 | 371 |
|
372 |
('Any L WHERE X login "admin", X identity Y, Y login L', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
373 |
'''SELECT _Y.cw_login |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
374 |
FROM cw_CWUser AS _X, cw_CWUser AS _Y |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
375 |
WHERE _X.cw_login=admin AND _X.cw_eid=_Y.cw_eid'''), |
0 | 376 |
|
377 |
('Any L WHERE X login "admin", NOT X identity Y, Y login L', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
378 |
'''SELECT _Y.cw_login |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
379 |
FROM cw_CWUser AS _X, cw_CWUser AS _Y |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
380 |
WHERE _X.cw_login=admin AND NOT (_X.cw_eid=_Y.cw_eid)'''), |
1787 | 381 |
|
0 | 382 |
('Any L WHERE X login "admin", X identity Y?, Y login L', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
383 |
'''SELECT _Y.cw_login |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
384 |
FROM cw_CWUser AS _X LEFT OUTER JOIN cw_CWUser AS _Y ON (_X.cw_eid=_Y.cw_eid) |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
385 |
WHERE _X.cw_login=admin'''), |
0 | 386 |
|
3587 | 387 |
('Any XN ORDERBY XN WHERE X name XN, X is IN (Basket,Folder,Tag)', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
388 |
'''SELECT _X.cw_name |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
389 |
FROM cw_Basket AS _X |
0 | 390 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
391 |
SELECT _X.cw_name |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
392 |
FROM cw_Folder AS _X |
0 | 393 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
394 |
SELECT _X.cw_name |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
395 |
FROM cw_Tag AS _X |
0 | 396 |
ORDER BY 1'''), |
397 |
||
2916
f42029293e59
cleanup, use striplines argument of assertLinesEquals
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2915
diff
changeset
|
398 |
# DISTINCT, can use relation under exists scope as principal |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
399 |
('DISTINCT Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), EXISTS(X read_permission Y)', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
400 |
'''SELECT DISTINCT _X.cw_eid, rel_read_permission0.eid_to |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
401 |
FROM cw_CWEType AS _X, read_permission_relation AS rel_read_permission0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
402 |
WHERE _X.cw_name=CWGroup AND rel_read_permission0.eid_to IN(1, 2, 3) AND EXISTS(SELECT 1 WHERE rel_read_permission0.eid_from=_X.cw_eid)'''), |
0 | 403 |
|
404 |
# no distinct, Y can't be invariant |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
405 |
('Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), EXISTS(X read_permission Y)', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
406 |
'''SELECT _X.cw_eid, _Y.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
407 |
FROM cw_CWEType AS _X, cw_CWGroup AS _Y |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
408 |
WHERE _X.cw_name=CWGroup AND _Y.cw_eid IN(1, 2, 3) AND EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=_X.cw_eid AND rel_read_permission0.eid_to=_Y.cw_eid) |
0 | 409 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
410 |
SELECT _X.cw_eid, _Y.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
411 |
FROM cw_CWEType AS _X, cw_RQLExpression AS _Y |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
412 |
WHERE _X.cw_name=CWGroup AND _Y.cw_eid IN(1, 2, 3) AND EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=_X.cw_eid AND rel_read_permission0.eid_to=_Y.cw_eid)'''), |
0 | 413 |
|
414 |
# DISTINCT but NEGED exists, can't be invariant |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
415 |
('DISTINCT Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), NOT EXISTS(X read_permission Y)', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
416 |
'''SELECT DISTINCT _X.cw_eid, _Y.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
417 |
FROM cw_CWEType AS _X, cw_CWGroup AS _Y |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
418 |
WHERE _X.cw_name=CWGroup AND _Y.cw_eid IN(1, 2, 3) AND NOT (EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=_X.cw_eid AND rel_read_permission0.eid_to=_Y.cw_eid)) |
0 | 419 |
UNION |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
420 |
SELECT DISTINCT _X.cw_eid, _Y.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
421 |
FROM cw_CWEType AS _X, cw_RQLExpression AS _Y |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
422 |
WHERE _X.cw_name=CWGroup AND _Y.cw_eid IN(1, 2, 3) AND NOT (EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=_X.cw_eid AND rel_read_permission0.eid_to=_Y.cw_eid))'''), |
0 | 423 |
|
424 |
# should generate the same query as above |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
425 |
('DISTINCT Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), NOT X read_permission Y', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
426 |
'''SELECT DISTINCT _X.cw_eid, _Y.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
427 |
FROM cw_CWEType AS _X, cw_CWGroup AS _Y |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
428 |
WHERE _X.cw_name=CWGroup AND _Y.cw_eid IN(1, 2, 3) AND NOT (EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=_X.cw_eid AND rel_read_permission0.eid_to=_Y.cw_eid)) |
0 | 429 |
UNION |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
430 |
SELECT DISTINCT _X.cw_eid, _Y.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
431 |
FROM cw_CWEType AS _X, cw_RQLExpression AS _Y |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
432 |
WHERE _X.cw_name=CWGroup AND _Y.cw_eid IN(1, 2, 3) AND NOT (EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=_X.cw_eid AND rel_read_permission0.eid_to=_Y.cw_eid))'''), |
1787 | 433 |
|
0 | 434 |
# neged relation, can't be inveriant |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
435 |
('Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), NOT X read_permission Y', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
436 |
'''SELECT _X.cw_eid, _Y.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
437 |
FROM cw_CWEType AS _X, cw_CWGroup AS _Y |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
438 |
WHERE _X.cw_name=CWGroup AND _Y.cw_eid IN(1, 2, 3) AND NOT (EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=_X.cw_eid AND rel_read_permission0.eid_to=_Y.cw_eid)) |
0 | 439 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
440 |
SELECT _X.cw_eid, _Y.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
441 |
FROM cw_CWEType AS _X, cw_RQLExpression AS _Y |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
442 |
WHERE _X.cw_name=CWGroup AND _Y.cw_eid IN(1, 2, 3) AND NOT (EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=_X.cw_eid AND rel_read_permission0.eid_to=_Y.cw_eid))'''), |
0 | 443 |
|
3587 | 444 |
('Any MAX(X)+MIN(X), N GROUPBY N WHERE X name N, X is IN (Basket, Folder, Tag);', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
445 |
'''SELECT (MAX(T1.C0) + MIN(T1.C0)), T1.C1 FROM (SELECT _X.cw_eid AS C0, _X.cw_name AS C1 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
446 |
FROM cw_Basket AS _X |
0 | 447 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
448 |
SELECT _X.cw_eid AS C0, _X.cw_name AS C1 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
449 |
FROM cw_Folder AS _X |
0 | 450 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
451 |
SELECT _X.cw_eid AS C0, _X.cw_name AS C1 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
452 |
FROM cw_Tag AS _X) AS T1 |
0 | 453 |
GROUP BY T1.C1'''), |
1787 | 454 |
|
3587 | 455 |
('Any MAX(X)+MIN(LENGTH(D)), N GROUPBY N ORDERBY 1, N, DF WHERE X data_name N, X data D, X data_format DF;', |
5575
8a531340c3ef
no more Image type w/ cw 3.9
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
456 |
'''SELECT (MAX(_X.cw_eid) + MIN(LENGTH(_X.cw_data))), _X.cw_data_name |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
457 |
FROM cw_File AS _X |
5575
8a531340c3ef
no more Image type w/ cw 3.9
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
458 |
GROUP BY _X.cw_data_name,_X.cw_data_format |
8a531340c3ef
no more Image type w/ cw 3.9
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
459 |
ORDER BY 1,2,_X.cw_data_format'''), |
0 | 460 |
|
461 |
# ambiguity in EXISTS() -> should union the sub-query |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
462 |
('Any T WHERE T is Tag, NOT T name in ("t1", "t2"), EXISTS(T tags X, X is IN (CWUser, CWGroup))', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
463 |
'''SELECT _T.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
464 |
FROM cw_Tag AS _T |
7193
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
465 |
WHERE NOT (_T.cw_name IN(t1, t2)) AND EXISTS(SELECT 1 FROM cw_CWGroup AS _X, tags_relation AS rel_tags0 WHERE rel_tags0.eid_from=_T.cw_eid AND rel_tags0.eid_to=_X.cw_eid UNION SELECT 1 FROM cw_CWUser AS _X, tags_relation AS rel_tags1 WHERE rel_tags1.eid_from=_T.cw_eid AND rel_tags1.eid_to=_X.cw_eid)'''), |
0 | 466 |
|
1787 | 467 |
# must not use a relation in EXISTS scope to inline a variable |
0 | 468 |
('Any U WHERE U eid IN (1,2), EXISTS(X owned_by U)', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
469 |
'''SELECT _U.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
470 |
FROM cw_CWUser AS _U |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
471 |
WHERE _U.cw_eid IN(1, 2) AND EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by0 WHERE rel_owned_by0.eid_to=_U.cw_eid)'''), |
0 | 472 |
|
473 |
('Any U WHERE EXISTS(U eid IN (1,2), X owned_by U)', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
474 |
'''SELECT _U.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
475 |
FROM cw_CWUser AS _U |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
476 |
WHERE EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by0 WHERE _U.cw_eid IN(1, 2) AND rel_owned_by0.eid_to=_U.cw_eid)'''), |
0 | 477 |
|
478 |
('Any COUNT(U) WHERE EXISTS (P owned_by U, P is IN (Note, Affaire))', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
479 |
'''SELECT COUNT(_U.cw_eid) |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
480 |
FROM cw_CWUser AS _U |
7193
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
481 |
WHERE EXISTS(SELECT 1 FROM cw_Affaire AS _P, owned_by_relation AS rel_owned_by0 WHERE rel_owned_by0.eid_from=_P.cw_eid AND rel_owned_by0.eid_to=_U.cw_eid UNION SELECT 1 FROM cw_Note AS _P, owned_by_relation AS rel_owned_by1 WHERE rel_owned_by1.eid_from=_P.cw_eid AND rel_owned_by1.eid_to=_U.cw_eid)'''), |
0 | 482 |
|
483 |
('Any MAX(X)', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
484 |
'''SELECT MAX(_X.eid) |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
485 |
FROM entities AS _X'''), |
0 | 486 |
|
487 |
('Any MAX(X) WHERE X is Note', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
488 |
'''SELECT MAX(_X.cw_eid) |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
489 |
FROM cw_Note AS _X'''), |
1787 | 490 |
|
0 | 491 |
('Any X WHERE X eid > 12', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
492 |
'''SELECT _X.eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
493 |
FROM entities AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
494 |
WHERE _X.eid>12'''), |
1787 | 495 |
|
0 | 496 |
('Any X WHERE X eid > 12, X is Note', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
497 |
"""SELECT _X.eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
498 |
FROM entities AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
499 |
WHERE _X.type='Note' AND _X.eid>12"""), |
1787 | 500 |
|
3520
eb508952ee81
update test, record a failing test (commented out)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3245
diff
changeset
|
501 |
('Any X, T WHERE X eid > 12, X title T, X is IN (Bookmark, Card)', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
502 |
"""SELECT _X.cw_eid, _X.cw_title |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
503 |
FROM cw_Bookmark AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
504 |
WHERE _X.cw_eid>12 |
0 | 505 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
506 |
SELECT _X.cw_eid, _X.cw_title |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
507 |
FROM cw_Card AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
508 |
WHERE _X.cw_eid>12"""), |
0 | 509 |
|
510 |
('Any X', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
511 |
'''SELECT _X.eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
512 |
FROM entities AS _X'''), |
0 | 513 |
|
514 |
('Any X GROUPBY X WHERE X eid 12', |
|
515 |
'''SELECT 12'''), |
|
1787 | 516 |
|
0 | 517 |
('Any X GROUPBY X ORDERBY Y WHERE X eid 12, X login Y', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
518 |
'''SELECT _X.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
519 |
FROM cw_CWUser AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
520 |
WHERE _X.cw_eid=12 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
521 |
GROUP BY _X.cw_eid,_X.cw_login |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
522 |
ORDER BY _X.cw_login'''), |
1787 | 523 |
|
0 | 524 |
('Any U,COUNT(X) GROUPBY U WHERE U eid 12, X owned_by U HAVING COUNT(X) > 10', |
525 |
'''SELECT rel_owned_by0.eid_to, COUNT(rel_owned_by0.eid_from) |
|
526 |
FROM owned_by_relation AS rel_owned_by0 |
|
527 |
WHERE rel_owned_by0.eid_to=12 |
|
528 |
GROUP BY rel_owned_by0.eid_to |
|
529 |
HAVING COUNT(rel_owned_by0.eid_from)>10'''), |
|
530 |
||
7108
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
531 |
|
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
532 |
("Any X WHERE X eid 0, X test TRUE", |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
533 |
'''SELECT _X.cw_eid |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
534 |
FROM cw_Personne AS _X |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
535 |
WHERE _X.cw_eid=0 AND _X.cw_test=TRUE'''), |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
536 |
|
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
537 |
('Any 1 WHERE X in_group G, X is CWUser', |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
538 |
'''SELECT 1 |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
539 |
FROM in_group_relation AS rel_in_group0'''), |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
540 |
|
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
541 |
('CWEType X WHERE X name CV, X description V HAVING NOT V=CV AND NOT V = "parent"', |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
542 |
'''SELECT _X.cw_eid |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
543 |
FROM cw_CWEType AS _X |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
544 |
WHERE NOT (EXISTS(SELECT 1 WHERE _X.cw_description=parent)) AND NOT (EXISTS(SELECT 1 WHERE _X.cw_description=_X.cw_name))'''), |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
545 |
('CWEType X WHERE X name CV, X description V HAVING V!=CV AND V != "parent"', |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
546 |
'''SELECT _X.cw_eid |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
547 |
FROM cw_CWEType AS _X |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
548 |
WHERE _X.cw_description!=parent AND _X.cw_description!=_X.cw_name'''), |
7421
5115daeeb2ff
[rql2sql] closes #1697862: ORDERBY SUM(C) cancel GROUPBY by wrongly adding C to grouped variables
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7396
diff
changeset
|
549 |
|
5115daeeb2ff
[rql2sql] closes #1697862: ORDERBY SUM(C) cancel GROUPBY by wrongly adding C to grouped variables
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7396
diff
changeset
|
550 |
('DISTINCT Any X, SUM(C) GROUPBY X ORDERBY SUM(C) DESC WHERE H todo_by X, H duration C', |
5115daeeb2ff
[rql2sql] closes #1697862: ORDERBY SUM(C) cancel GROUPBY by wrongly adding C to grouped variables
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7396
diff
changeset
|
551 |
'''SELECT DISTINCT rel_todo_by0.eid_to, SUM(_H.cw_duration) |
5115daeeb2ff
[rql2sql] closes #1697862: ORDERBY SUM(C) cancel GROUPBY by wrongly adding C to grouped variables
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7396
diff
changeset
|
552 |
FROM cw_Affaire AS _H, todo_by_relation AS rel_todo_by0 |
5115daeeb2ff
[rql2sql] closes #1697862: ORDERBY SUM(C) cancel GROUPBY by wrongly adding C to grouped variables
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7396
diff
changeset
|
553 |
WHERE rel_todo_by0.eid_from=_H.cw_eid |
5115daeeb2ff
[rql2sql] closes #1697862: ORDERBY SUM(C) cancel GROUPBY by wrongly adding C to grouped variables
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7396
diff
changeset
|
554 |
GROUP BY rel_todo_by0.eid_to |
5115daeeb2ff
[rql2sql] closes #1697862: ORDERBY SUM(C) cancel GROUPBY by wrongly adding C to grouped variables
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7396
diff
changeset
|
555 |
ORDER BY 2 DESC'''), |
5115daeeb2ff
[rql2sql] closes #1697862: ORDERBY SUM(C) cancel GROUPBY by wrongly adding C to grouped variables
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7396
diff
changeset
|
556 |
|
7497
7beb71d76d82
[rql2sql] add test case for 7493:3c46b9390871
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7473
diff
changeset
|
557 |
('Any R2 WHERE R2 concerne R, R eid RE, R2 eid > RE', |
7beb71d76d82
[rql2sql] add test case for 7493:3c46b9390871
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7473
diff
changeset
|
558 |
'''SELECT _R2.eid |
7beb71d76d82
[rql2sql] add test case for 7493:3c46b9390871
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7473
diff
changeset
|
559 |
FROM concerne_relation AS rel_concerne0, entities AS _R2 |
7beb71d76d82
[rql2sql] add test case for 7493:3c46b9390871
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7473
diff
changeset
|
560 |
WHERE _R2.eid=rel_concerne0.eid_from AND _R2.eid>rel_concerne0.eid_to'''), |
7651
7c0af7ef3325
[repo, ms] fix planning of some queries where variable 'non-invarianess' should be considered, leading for instance to junk in entities table on source deletion
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7642
diff
changeset
|
561 |
|
7c0af7ef3325
[repo, ms] fix planning of some queries where variable 'non-invarianess' should be considered, leading for instance to junk in entities table on source deletion
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7642
diff
changeset
|
562 |
('Note X WHERE X eid IN (999998, 999999), NOT X cw_source Y', |
7c0af7ef3325
[repo, ms] fix planning of some queries where variable 'non-invarianess' should be considered, leading for instance to junk in entities table on source deletion
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7642
diff
changeset
|
563 |
'''SELECT _X.cw_eid |
7c0af7ef3325
[repo, ms] fix planning of some queries where variable 'non-invarianess' should be considered, leading for instance to junk in entities table on source deletion
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7642
diff
changeset
|
564 |
FROM cw_Note AS _X |
7c0af7ef3325
[repo, ms] fix planning of some queries where variable 'non-invarianess' should be considered, leading for instance to junk in entities table on source deletion
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7642
diff
changeset
|
565 |
WHERE _X.cw_eid IN(999998, 999999) AND NOT (EXISTS(SELECT 1 FROM cw_source_relation AS rel_cw_source0 WHERE rel_cw_source0.eid_from=_X.cw_eid))'''), |
7108
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
566 |
] |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
567 |
|
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
568 |
ADVANCED_WITH_GROUP_CONCAT = [ |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
569 |
("Any X,GROUP_CONCAT(TN) GROUPBY X ORDERBY XN WHERE T tags X, X name XN, T name TN, X is CWGroup", |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
570 |
'''SELECT _X.cw_eid, GROUP_CONCAT(_T.cw_name) |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
571 |
FROM cw_CWGroup AS _X, cw_Tag AS _T, tags_relation AS rel_tags0 |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
572 |
WHERE rel_tags0.eid_from=_T.cw_eid AND rel_tags0.eid_to=_X.cw_eid |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
573 |
GROUP BY _X.cw_eid,_X.cw_name |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
574 |
ORDER BY _X.cw_name'''), |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
575 |
|
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
576 |
("Any X,GROUP_CONCAT(TN) GROUPBY X ORDERBY XN WHERE T tags X, X name XN, T name TN", |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
577 |
'''SELECT T1.C0, GROUP_CONCAT(T1.C1) FROM (SELECT _X.cw_eid AS C0, _T.cw_name AS C1, _X.cw_name AS C2 |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
578 |
FROM cw_CWGroup AS _X, cw_Tag AS _T, tags_relation AS rel_tags0 |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
579 |
WHERE rel_tags0.eid_from=_T.cw_eid AND rel_tags0.eid_to=_X.cw_eid |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
580 |
UNION ALL |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
581 |
SELECT _X.cw_eid AS C0, _T.cw_name AS C1, _X.cw_name AS C2 |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
582 |
FROM cw_State AS _X, cw_Tag AS _T, tags_relation AS rel_tags0 |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
583 |
WHERE rel_tags0.eid_from=_T.cw_eid AND rel_tags0.eid_to=_X.cw_eid |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
584 |
UNION ALL |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
585 |
SELECT _X.cw_eid AS C0, _T.cw_name AS C1, _X.cw_name AS C2 |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
586 |
FROM cw_Tag AS _T, cw_Tag AS _X, tags_relation AS rel_tags0 |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
587 |
WHERE rel_tags0.eid_from=_T.cw_eid AND rel_tags0.eid_to=_X.cw_eid) AS T1 |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
588 |
GROUP BY T1.C0,T1.C2 |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
589 |
ORDER BY T1.C2'''), |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
590 |
|
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
591 |
] |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
592 |
|
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
593 |
ADVANCED_WITH_LIMIT_OR_ORDERBY = [ |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
594 |
('Any COUNT(S),CS GROUPBY CS ORDERBY 1 DESC LIMIT 10 WHERE S is Affaire, C is Societe, S concerne C, C nom CS, (EXISTS(S owned_by 1)) OR (EXISTS(S documented_by N, N title "published"))', |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
595 |
'''SELECT COUNT(rel_concerne0.eid_from), _C.cw_nom |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
596 |
FROM concerne_relation AS rel_concerne0, cw_Societe AS _C |
7193
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
597 |
WHERE rel_concerne0.eid_to=_C.cw_eid AND ((EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by1 WHERE rel_concerne0.eid_from=rel_owned_by1.eid_from AND rel_owned_by1.eid_to=1)) OR (EXISTS(SELECT 1 FROM cw_Card AS _N, documented_by_relation AS rel_documented_by2 WHERE rel_concerne0.eid_from=rel_documented_by2.eid_from AND rel_documented_by2.eid_to=_N.cw_eid AND _N.cw_title=published))) |
7108
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
598 |
GROUP BY _C.cw_nom |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
599 |
ORDER BY 1 DESC |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
600 |
LIMIT 10'''), |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
601 |
('DISTINCT Any S ORDERBY stockproc(SI) WHERE NOT S ecrit_par O, S para SI', |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
602 |
'''SELECT T1.C0 FROM (SELECT DISTINCT _S.cw_eid AS C0, STOCKPROC(_S.cw_para) AS C1 |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
603 |
FROM cw_Note AS _S |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
604 |
WHERE _S.cw_ecrit_par IS NULL |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
605 |
ORDER BY 2) AS T1'''), |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
606 |
|
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
607 |
('DISTINCT Any MAX(X)+MIN(LENGTH(D)), N GROUPBY N ORDERBY 2, DF WHERE X data_name N, X data D, X data_format DF;', |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
608 |
'''SELECT T1.C0,T1.C1 FROM (SELECT DISTINCT (MAX(_X.cw_eid) + MIN(LENGTH(_X.cw_data))) AS C0, _X.cw_data_name AS C1, _X.cw_data_format AS C2 |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
609 |
FROM cw_File AS _X |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
610 |
GROUP BY _X.cw_data_name,_X.cw_data_format |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
611 |
ORDER BY 2,3) AS T1 |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
612 |
'''), |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
613 |
|
0 | 614 |
('DISTINCT Any X ORDERBY stockproc(X) WHERE U login X', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
615 |
'''SELECT T1.C0 FROM (SELECT DISTINCT _U.cw_login AS C0, STOCKPROC(_U.cw_login) AS C1 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
616 |
FROM cw_CWUser AS _U |
0 | 617 |
ORDER BY 2) AS T1'''), |
1787 | 618 |
|
0 | 619 |
('DISTINCT Any X ORDERBY Y WHERE B bookmarked_by X, X login Y', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
620 |
'''SELECT T1.C0 FROM (SELECT DISTINCT _X.cw_eid AS C0, _X.cw_login AS C1 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
621 |
FROM bookmarked_by_relation AS rel_bookmarked_by0, cw_CWUser AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
622 |
WHERE rel_bookmarked_by0.eid_to=_X.cw_eid |
0 | 623 |
ORDER BY 2) AS T1'''), |
624 |
||
625 |
('DISTINCT Any X ORDERBY SN WHERE X in_state S, S name SN', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
626 |
'''SELECT T1.C0 FROM (SELECT DISTINCT _X.cw_eid AS C0, _S.cw_name AS C1 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
627 |
FROM cw_Affaire AS _X, cw_State AS _S |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
628 |
WHERE _X.cw_in_state=_S.cw_eid |
0 | 629 |
UNION |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
630 |
SELECT DISTINCT _X.cw_eid AS C0, _S.cw_name AS C1 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
631 |
FROM cw_CWUser AS _X, cw_State AS _S |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
632 |
WHERE _X.cw_in_state=_S.cw_eid |
0 | 633 |
UNION |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
634 |
SELECT DISTINCT _X.cw_eid AS C0, _S.cw_name AS C1 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
635 |
FROM cw_Note AS _X, cw_State AS _S |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
636 |
WHERE _X.cw_in_state=_S.cw_eid |
0 | 637 |
ORDER BY 2) AS T1'''), |
638 |
||
3238
988a72e59b2b
[querier] fix sql generated w/ NOT relation and shared variable: ensure variable's table is in parent select'scope
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
639 |
('Any O,AA,AB,AC ORDERBY AC DESC ' |
988a72e59b2b
[querier] fix sql generated w/ NOT relation and shared variable: ensure variable's table is in parent select'scope
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
640 |
'WHERE NOT S use_email O, S eid 1, O is EmailAddress, O address AA, O alias AB, O modification_date AC, ' |
988a72e59b2b
[querier] fix sql generated w/ NOT relation and shared variable: ensure variable's table is in parent select'scope
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
641 |
'EXISTS(A use_email O, EXISTS(A identity B, NOT B in_group D, D name "guests", D is CWGroup), A is CWUser), B eid 2', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
642 |
'''SELECT _O.cw_eid, _O.cw_address, _O.cw_alias, _O.cw_modification_date |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
643 |
FROM cw_EmailAddress AS _O |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
644 |
WHERE NOT (EXISTS(SELECT 1 FROM use_email_relation AS rel_use_email0 WHERE rel_use_email0.eid_from=1 AND rel_use_email0.eid_to=_O.cw_eid)) AND EXISTS(SELECT 1 FROM use_email_relation AS rel_use_email1 WHERE rel_use_email1.eid_to=_O.cw_eid AND EXISTS(SELECT 1 FROM cw_CWGroup AS _D WHERE rel_use_email1.eid_from=2 AND NOT (EXISTS(SELECT 1 FROM in_group_relation AS rel_in_group2 WHERE rel_in_group2.eid_from=2 AND rel_in_group2.eid_to=_D.cw_eid)) AND _D.cw_name=guests)) |
3238
988a72e59b2b
[querier] fix sql generated w/ NOT relation and shared variable: ensure variable's table is in parent select'scope
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
645 |
ORDER BY 4 DESC'''), |
3632
874f5a73e89f
[rql2sql] test we don't crash on dumb queries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3587
diff
changeset
|
646 |
|
874f5a73e89f
[rql2sql] test we don't crash on dumb queries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3587
diff
changeset
|
647 |
|
0 | 648 |
] |
649 |
||
650 |
MULTIPLE_SEL = [ |
|
651 |
("DISTINCT Any X,Y where P is Personne, P nom X , P prenom Y;", |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
652 |
'''SELECT DISTINCT _P.cw_nom, _P.cw_prenom |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
653 |
FROM cw_Personne AS _P'''), |
0 | 654 |
("Any X,Y where P is Personne, P nom X , P prenom Y, not P nom NULL;", |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
655 |
'''SELECT _P.cw_nom, _P.cw_prenom |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
656 |
FROM cw_Personne AS _P |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
657 |
WHERE NOT (_P.cw_nom IS NULL)'''), |
0 | 658 |
("Personne X,Y where X nom NX, Y nom NX, X eid XE, not Y eid XE", |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
659 |
'''SELECT _X.cw_eid, _Y.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
660 |
FROM cw_Personne AS _X, cw_Personne AS _Y |
7396
8345ee2c2ea6
[rql2sql] fix in 7394:d11d88bd08e8 was actually not needed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7357
diff
changeset
|
661 |
WHERE _Y.cw_nom=_X.cw_nom AND NOT (_Y.cw_eid=_X.cw_eid)'''), |
8345ee2c2ea6
[rql2sql] fix in 7394:d11d88bd08e8 was actually not needed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7357
diff
changeset
|
662 |
|
8345ee2c2ea6
[rql2sql] fix in 7394:d11d88bd08e8 was actually not needed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7357
diff
changeset
|
663 |
('Any X,Y WHERE X is Personne, Y is Personne, X nom XD, Y nom XD, X eid Z, Y eid > Z', |
8345ee2c2ea6
[rql2sql] fix in 7394:d11d88bd08e8 was actually not needed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7357
diff
changeset
|
664 |
'''SELECT _X.cw_eid, _Y.cw_eid |
8345ee2c2ea6
[rql2sql] fix in 7394:d11d88bd08e8 was actually not needed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7357
diff
changeset
|
665 |
FROM cw_Personne AS _X, cw_Personne AS _Y |
8345ee2c2ea6
[rql2sql] fix in 7394:d11d88bd08e8 was actually not needed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7357
diff
changeset
|
666 |
WHERE _Y.cw_nom=_X.cw_nom AND _Y.cw_eid>_X.cw_eid'''), |
0 | 667 |
] |
668 |
||
5886 | 669 |
|
0 | 670 |
NEGATIONS = [ |
5886 | 671 |
|
0 | 672 |
("Personne X WHERE NOT X evaluee Y;", |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
673 |
'''SELECT _X.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
674 |
FROM cw_Personne AS _X |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
675 |
WHERE NOT (EXISTS(SELECT 1 FROM evaluee_relation AS rel_evaluee0 WHERE rel_evaluee0.eid_from=_X.cw_eid))'''), |
1787 | 676 |
|
0 | 677 |
("Note N WHERE NOT X evaluee N, X eid 0", |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
678 |
'''SELECT _N.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
679 |
FROM cw_Note AS _N |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
680 |
WHERE NOT (EXISTS(SELECT 1 FROM evaluee_relation AS rel_evaluee0 WHERE rel_evaluee0.eid_from=0 AND rel_evaluee0.eid_to=_N.cw_eid))'''), |
1787 | 681 |
|
0 | 682 |
('Any X WHERE NOT X travaille S, X is Personne', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
683 |
'''SELECT _X.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
684 |
FROM cw_Personne AS _X |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
685 |
WHERE NOT (EXISTS(SELECT 1 FROM travaille_relation AS rel_travaille0 WHERE rel_travaille0.eid_from=_X.cw_eid))'''), |
1787 | 686 |
|
0 | 687 |
("Personne P where NOT P concerne A", |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
688 |
'''SELECT _P.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
689 |
FROM cw_Personne AS _P |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
690 |
WHERE NOT (EXISTS(SELECT 1 FROM concerne_relation AS rel_concerne0 WHERE rel_concerne0.eid_from=_P.cw_eid))'''), |
1787 | 691 |
|
0 | 692 |
("Affaire A where not P concerne A", |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
693 |
'''SELECT _A.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
694 |
FROM cw_Affaire AS _A |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
695 |
WHERE NOT (EXISTS(SELECT 1 FROM concerne_relation AS rel_concerne0 WHERE rel_concerne0.eid_to=_A.cw_eid))'''), |
0 | 696 |
("Personne P where not P concerne A, A sujet ~= 'TEST%'", |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
697 |
'''SELECT _P.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
698 |
FROM cw_Affaire AS _A, cw_Personne AS _P |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
699 |
WHERE NOT (EXISTS(SELECT 1 FROM concerne_relation AS rel_concerne0 WHERE rel_concerne0.eid_from=_P.cw_eid AND rel_concerne0.eid_to=_A.cw_eid)) AND _A.cw_sujet ILIKE TEST%'''), |
0 | 700 |
|
701 |
('Any S WHERE NOT T eid 28258, T tags S', |
|
702 |
'''SELECT rel_tags0.eid_to |
|
703 |
FROM tags_relation AS rel_tags0 |
|
704 |
WHERE NOT (rel_tags0.eid_from=28258)'''), |
|
1787 | 705 |
|
0 | 706 |
('Any S WHERE T is Tag, T name TN, NOT T eid 28258, T tags S, S name SN', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
707 |
'''SELECT _S.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
708 |
FROM cw_CWGroup AS _S, cw_Tag AS _T, tags_relation AS rel_tags0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
709 |
WHERE NOT (_T.cw_eid=28258) AND rel_tags0.eid_from=_T.cw_eid AND rel_tags0.eid_to=_S.cw_eid |
0 | 710 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
711 |
SELECT _S.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
712 |
FROM cw_State AS _S, cw_Tag AS _T, tags_relation AS rel_tags0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
713 |
WHERE NOT (_T.cw_eid=28258) AND rel_tags0.eid_from=_T.cw_eid AND rel_tags0.eid_to=_S.cw_eid |
0 | 714 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
715 |
SELECT _S.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
716 |
FROM cw_Tag AS _S, cw_Tag AS _T, tags_relation AS rel_tags0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
717 |
WHERE NOT (_T.cw_eid=28258) AND rel_tags0.eid_from=_T.cw_eid AND rel_tags0.eid_to=_S.cw_eid'''), |
0 | 718 |
|
719 |
('Any X,Y WHERE X created_by Y, X eid 5, NOT Y eid 6', |
|
720 |
'''SELECT 5, rel_created_by0.eid_to |
|
721 |
FROM created_by_relation AS rel_created_by0 |
|
722 |
WHERE rel_created_by0.eid_from=5 AND NOT (rel_created_by0.eid_to=6)'''), |
|
723 |
||
724 |
('Note X WHERE NOT Y evaluee X', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
725 |
'''SELECT _X.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
726 |
FROM cw_Note AS _X |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
727 |
WHERE NOT (EXISTS(SELECT 1 FROM evaluee_relation AS rel_evaluee0 WHERE rel_evaluee0.eid_to=_X.cw_eid))'''), |
0 | 728 |
|
729 |
('Any Y WHERE NOT Y evaluee X', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
730 |
'''SELECT _Y.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
731 |
FROM cw_CWUser AS _Y |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
732 |
WHERE NOT (EXISTS(SELECT 1 FROM evaluee_relation AS rel_evaluee0 WHERE rel_evaluee0.eid_from=_Y.cw_eid)) |
0 | 733 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
734 |
SELECT _Y.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
735 |
FROM cw_Division AS _Y |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
736 |
WHERE NOT (EXISTS(SELECT 1 FROM evaluee_relation AS rel_evaluee0 WHERE rel_evaluee0.eid_from=_Y.cw_eid)) |
0 | 737 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
738 |
SELECT _Y.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
739 |
FROM cw_Personne AS _Y |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
740 |
WHERE NOT (EXISTS(SELECT 1 FROM evaluee_relation AS rel_evaluee0 WHERE rel_evaluee0.eid_from=_Y.cw_eid)) |
0 | 741 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
742 |
SELECT _Y.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
743 |
FROM cw_Societe AS _Y |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
744 |
WHERE NOT (EXISTS(SELECT 1 FROM evaluee_relation AS rel_evaluee0 WHERE rel_evaluee0.eid_from=_Y.cw_eid)) |
0 | 745 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
746 |
SELECT _Y.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
747 |
FROM cw_SubDivision AS _Y |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
748 |
WHERE NOT (EXISTS(SELECT 1 FROM evaluee_relation AS rel_evaluee0 WHERE rel_evaluee0.eid_from=_Y.cw_eid))'''), |
0 | 749 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
750 |
('Any X WHERE NOT Y evaluee X, Y is CWUser', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
751 |
'''SELECT _X.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
752 |
FROM cw_Note AS _X |
7193
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
753 |
WHERE NOT (EXISTS(SELECT 1 FROM cw_CWUser AS _Y, evaluee_relation AS rel_evaluee0 WHERE rel_evaluee0.eid_from=_Y.cw_eid AND rel_evaluee0.eid_to=_X.cw_eid))'''), |
1787 | 754 |
|
3520
eb508952ee81
update test, record a failing test (commented out)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3245
diff
changeset
|
755 |
('Any X,RT WHERE X relation_type RT, NOT X is CWAttribute', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
756 |
'''SELECT _X.cw_eid, _X.cw_relation_type |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
757 |
FROM cw_CWRelation AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
758 |
WHERE _X.cw_relation_type IS NOT NULL'''), |
0 | 759 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
760 |
('Any K,V WHERE P is CWProperty, P pkey K, P value V, NOT P for_user U', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
761 |
'''SELECT _P.cw_pkey, _P.cw_value |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
762 |
FROM cw_CWProperty AS _P |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
763 |
WHERE _P.cw_for_user IS NULL'''), |
0 | 764 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
765 |
('Any S WHERE NOT X in_state S, X is IN(Affaire, CWUser)', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
766 |
'''SELECT _S.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
767 |
FROM cw_State AS _S |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
768 |
WHERE NOT (EXISTS(SELECT 1 FROM cw_Affaire AS _X WHERE _X.cw_in_state=_S.cw_eid UNION SELECT 1 FROM cw_CWUser AS _X WHERE _X.cw_in_state=_S.cw_eid))'''), |
3520
eb508952ee81
update test, record a failing test (commented out)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3245
diff
changeset
|
769 |
|
eb508952ee81
update test, record a failing test (commented out)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3245
diff
changeset
|
770 |
('Any S WHERE NOT(X in_state S, S name "somename"), X is CWUser', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
771 |
'''SELECT _S.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
772 |
FROM cw_State AS _S |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
773 |
WHERE NOT (EXISTS(SELECT 1 FROM cw_CWUser AS _X WHERE _X.cw_in_state=_S.cw_eid AND _S.cw_name=somename))'''), |
7108
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
774 |
] |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
775 |
|
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
776 |
HAS_TEXT_LG_INDEXER = [ |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
777 |
('Any X WHERE X has_text "toto tata"', |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
778 |
"""SELECT DISTINCT appears0.uid |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
779 |
FROM appears AS appears0 |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
780 |
WHERE appears0.word_id IN (SELECT word_id FROM word WHERE word in ('toto', 'tata'))"""), |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
781 |
('Personne X WHERE X has_text "toto tata"', |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
782 |
"""SELECT DISTINCT _X.eid |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
783 |
FROM appears AS appears0, entities AS _X |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
784 |
WHERE appears0.word_id IN (SELECT word_id FROM word WHERE word in ('toto', 'tata')) AND appears0.uid=_X.eid AND _X.type='Personne'"""), |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
785 |
('Personne X WHERE X has_text %(text)s', |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
786 |
"""SELECT DISTINCT _X.eid |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
787 |
FROM appears AS appears0, entities AS _X |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
788 |
WHERE appears0.word_id IN (SELECT word_id FROM word WHERE word in ('hip', 'hop', 'momo')) AND appears0.uid=_X.eid AND _X.type='Personne' |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
789 |
"""), |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
790 |
('Any X WHERE X has_text "toto tata", X name "tutu", X is IN (Basket,Folder)', |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
791 |
"""SELECT DISTINCT _X.cw_eid |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
792 |
FROM appears AS appears0, cw_Basket AS _X |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
793 |
WHERE appears0.word_id IN (SELECT word_id FROM word WHERE word in ('toto', 'tata')) AND appears0.uid=_X.cw_eid AND _X.cw_name=tutu |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
794 |
UNION |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
795 |
SELECT DISTINCT _X.cw_eid |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
796 |
FROM appears AS appears0, cw_Folder AS _X |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
797 |
WHERE appears0.word_id IN (SELECT word_id FROM word WHERE word in ('toto', 'tata')) AND appears0.uid=_X.cw_eid AND _X.cw_name=tutu""") |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
798 |
] |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
799 |
|
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
800 |
|
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
801 |
|
3520
eb508952ee81
update test, record a failing test (commented out)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3245
diff
changeset
|
802 |
# XXXFIXME fail |
eb508952ee81
update test, record a failing test (commented out)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3245
diff
changeset
|
803 |
# ('Any X,RT WHERE X relation_type RT?, NOT X is CWAttribute', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
804 |
# '''SELECT _X.cw_eid, _X.cw_relation_type |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
805 |
# FROM cw_CWRelation AS _X'''), |
7108
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
806 |
|
0 | 807 |
|
808 |
OUTER_JOIN = [ |
|
7707
936530f8d32c
[sql gen] handle optional on comparison node (eg HAVING expression) and on rhs of final relation. Closes #1859609
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7705
diff
changeset
|
809 |
|
936530f8d32c
[sql gen] handle optional on comparison node (eg HAVING expression) and on rhs of final relation. Closes #1859609
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7705
diff
changeset
|
810 |
('Any U,G WHERE U login L, G name L?, G is CWGroup', |
936530f8d32c
[sql gen] handle optional on comparison node (eg HAVING expression) and on rhs of final relation. Closes #1859609
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7705
diff
changeset
|
811 |
'''SELECT _U.cw_eid, _G.cw_eid |
936530f8d32c
[sql gen] handle optional on comparison node (eg HAVING expression) and on rhs of final relation. Closes #1859609
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7705
diff
changeset
|
812 |
FROM cw_CWUser AS _U LEFT OUTER JOIN cw_CWGroup AS _G ON (_G.cw_name=_U.cw_login)'''), |
936530f8d32c
[sql gen] handle optional on comparison node (eg HAVING expression) and on rhs of final relation. Closes #1859609
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7705
diff
changeset
|
813 |
|
0 | 814 |
('Any X,S WHERE X travaille S?', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
815 |
'''SELECT _X.cw_eid, rel_travaille0.eid_to |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
816 |
FROM cw_Personne AS _X LEFT OUTER JOIN travaille_relation AS rel_travaille0 ON (rel_travaille0.eid_from=_X.cw_eid)''' |
0 | 817 |
), |
818 |
('Any S,X WHERE X? travaille S, S is Societe', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
819 |
'''SELECT _S.cw_eid, rel_travaille0.eid_from |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
820 |
FROM cw_Societe AS _S LEFT OUTER JOIN travaille_relation AS rel_travaille0 ON (rel_travaille0.eid_to=_S.cw_eid)''' |
0 | 821 |
), |
822 |
||
823 |
('Any N,A WHERE N inline1 A?', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
824 |
'''SELECT _N.cw_eid, _N.cw_inline1 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
825 |
FROM cw_Note AS _N'''), |
0 | 826 |
|
827 |
('Any SN WHERE X from_state S?, S name SN', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
828 |
'''SELECT _S.cw_name |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
829 |
FROM cw_TrInfo AS _X LEFT OUTER JOIN cw_State AS _S ON (_X.cw_from_state=_S.cw_eid)''' |
0 | 830 |
), |
831 |
||
832 |
('Any A,N WHERE N? inline1 A', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
833 |
'''SELECT _A.cw_eid, _N.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
834 |
FROM cw_Affaire AS _A LEFT OUTER JOIN cw_Note AS _N ON (_N.cw_inline1=_A.cw_eid)''' |
0 | 835 |
), |
836 |
||
837 |
('Any A,B,C,D,E,F,G WHERE A eid 12,A creation_date B,A modification_date C,A comment D,A from_state E?,A to_state F?,A wf_info_for G?', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
838 |
'''SELECT _A.cw_eid, _A.cw_creation_date, _A.cw_modification_date, _A.cw_comment, _A.cw_from_state, _A.cw_to_state, _A.cw_wf_info_for |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
839 |
FROM cw_TrInfo AS _A |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
840 |
WHERE _A.cw_eid=12'''), |
0 | 841 |
|
842 |
('Any FS,TS,C,D,U ORDERBY D DESC WHERE WF wf_info_for X,WF from_state FS?, WF to_state TS, WF comment C,WF creation_date D, WF owned_by U, X eid 1', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
843 |
'''SELECT _WF.cw_from_state, _WF.cw_to_state, _WF.cw_comment, _WF.cw_creation_date, rel_owned_by0.eid_to |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
844 |
FROM cw_TrInfo AS _WF, owned_by_relation AS rel_owned_by0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
845 |
WHERE _WF.cw_wf_info_for=1 AND _WF.cw_to_state IS NOT NULL AND rel_owned_by0.eid_from=_WF.cw_eid |
0 | 846 |
ORDER BY 4 DESC'''), |
847 |
||
848 |
('Any X WHERE X is Affaire, S is Societe, EXISTS(X owned_by U OR (X concerne S?, S owned_by U))', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
849 |
'''SELECT _X.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
850 |
FROM cw_Affaire AS _X |
7193
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
851 |
WHERE EXISTS(SELECT 1 FROM cw_CWUser AS _U, owned_by_relation AS rel_owned_by0, owned_by_relation AS rel_owned_by2, cw_Affaire AS _A LEFT OUTER JOIN concerne_relation AS rel_concerne1 ON (rel_concerne1.eid_from=_A.cw_eid) LEFT OUTER JOIN cw_Societe AS _S ON (rel_concerne1.eid_to=_S.cw_eid) WHERE ((rel_owned_by0.eid_from=_A.cw_eid AND rel_owned_by0.eid_to=_U.cw_eid) OR (rel_owned_by2.eid_from=_S.cw_eid AND rel_owned_by2.eid_to=_U.cw_eid)) AND _X.cw_eid=_A.cw_eid)'''), |
0 | 852 |
|
853 |
('Any C,M WHERE C travaille G?, G evaluee M?, G is Societe', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
854 |
'''SELECT _C.cw_eid, rel_evaluee1.eid_to |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
855 |
FROM cw_Personne AS _C LEFT OUTER JOIN travaille_relation AS rel_travaille0 ON (rel_travaille0.eid_from=_C.cw_eid) LEFT OUTER JOIN cw_Societe AS _G ON (rel_travaille0.eid_to=_G.cw_eid) LEFT OUTER JOIN evaluee_relation AS rel_evaluee1 ON (rel_evaluee1.eid_from=_G.cw_eid)''' |
0 | 856 |
), |
857 |
||
858 |
('Any A,C WHERE A documented_by C?, (C is NULL) OR (EXISTS(C require_permission F, ' |
|
859 |
'F name "read", F require_group E, U in_group E)), U eid 1', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
860 |
'''SELECT _A.cw_eid, rel_documented_by0.eid_to |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
861 |
FROM cw_Affaire AS _A LEFT OUTER JOIN documented_by_relation AS rel_documented_by0 ON (rel_documented_by0.eid_from=_A.cw_eid) |
7193
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
862 |
WHERE ((rel_documented_by0.eid_to IS NULL) OR (EXISTS(SELECT 1 FROM cw_CWPermission AS _F, in_group_relation AS rel_in_group3, require_group_relation AS rel_require_group2, require_permission_relation AS rel_require_permission1 WHERE rel_documented_by0.eid_to=rel_require_permission1.eid_from AND rel_require_permission1.eid_to=_F.cw_eid AND _F.cw_name=read AND rel_require_group2.eid_from=_F.cw_eid AND rel_in_group3.eid_to=rel_require_group2.eid_to AND rel_in_group3.eid_from=1)))'''), |
0 | 863 |
|
864 |
("Any X WHERE X eid 12, P? connait X", |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
865 |
'''SELECT _X.cw_eid |
7193
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
866 |
FROM cw_Personne AS _X LEFT OUTER JOIN connait_relation AS rel_connait0 ON (rel_connait0.eid_to=_X.cw_eid) |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
867 |
WHERE _X.cw_eid=12''' |
0 | 868 |
), |
7193
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
869 |
("Any P WHERE X eid 12, P? concerne X, X todo_by S", |
7357
5ad3154a8810
[rql2sql] fix bug avoiding outer join relation to be used as a variable principal. Closes #1659395
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7252
diff
changeset
|
870 |
'''SELECT rel_concerne1.eid_from |
5ad3154a8810
[rql2sql] fix bug avoiding outer join relation to be used as a variable principal. Closes #1659395
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7252
diff
changeset
|
871 |
FROM todo_by_relation AS rel_todo_by0 LEFT OUTER JOIN concerne_relation AS rel_concerne1 ON (rel_concerne1.eid_to=12) |
5ad3154a8810
[rql2sql] fix bug avoiding outer join relation to be used as a variable principal. Closes #1659395
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7252
diff
changeset
|
872 |
WHERE rel_todo_by0.eid_from=12''' |
7193
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
873 |
), |
0 | 874 |
|
875 |
('Any GN, TN ORDERBY GN WHERE T tags G?, T name TN, G name GN', |
|
1787 | 876 |
''' |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
877 |
SELECT _T0.C1, _T.cw_name |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
878 |
FROM cw_Tag AS _T LEFT OUTER JOIN tags_relation AS rel_tags0 ON (rel_tags0.eid_from=_T.cw_eid) LEFT OUTER JOIN (SELECT _G.cw_eid AS C0, _G.cw_name AS C1 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
879 |
FROM cw_CWGroup AS _G |
0 | 880 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
881 |
SELECT _G.cw_eid AS C0, _G.cw_name AS C1 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
882 |
FROM cw_State AS _G |
0 | 883 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
884 |
SELECT _G.cw_eid AS C0, _G.cw_name AS C1 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
885 |
FROM cw_Tag AS _G) AS _T0 ON (rel_tags0.eid_to=_T0.C0) |
0 | 886 |
ORDER BY 1'''), |
887 |
||
888 |
||
889 |
# optional variable with additional restriction |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
890 |
('Any T,G WHERE T tags G?, G name "hop", G is CWGroup', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
891 |
'''SELECT _T.cw_eid, _G.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
892 |
FROM cw_Tag AS _T LEFT OUTER JOIN tags_relation AS rel_tags0 ON (rel_tags0.eid_from=_T.cw_eid) LEFT OUTER JOIN cw_CWGroup AS _G ON (rel_tags0.eid_to=_G.cw_eid AND _G.cw_name=hop)'''), |
0 | 893 |
|
894 |
# optional variable with additional invariant restriction |
|
895 |
('Any T,G WHERE T tags G?, G eid 12', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
896 |
'''SELECT _T.cw_eid, rel_tags0.eid_to |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
897 |
FROM cw_Tag AS _T LEFT OUTER JOIN tags_relation AS rel_tags0 ON (rel_tags0.eid_from=_T.cw_eid AND rel_tags0.eid_to=12)'''), |
0 | 898 |
|
899 |
# optional variable with additional restriction appearing before the relation |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
900 |
('Any T,G WHERE G name "hop", T tags G?, G is CWGroup', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
901 |
'''SELECT _T.cw_eid, _G.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
902 |
FROM cw_Tag AS _T LEFT OUTER JOIN tags_relation AS rel_tags0 ON (rel_tags0.eid_from=_T.cw_eid) LEFT OUTER JOIN cw_CWGroup AS _G ON (rel_tags0.eid_to=_G.cw_eid AND _G.cw_name=hop)'''), |
0 | 903 |
|
904 |
# optional variable with additional restriction on inlined relation |
|
905 |
# XXX the expected result should be as the query below. So what, raise BadRQLQuery ? |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
906 |
('Any T,G,S WHERE T tags G?, G in_state S, S name "hop", G is CWUser', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
907 |
'''SELECT _T.cw_eid, _G.cw_eid, _S.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
908 |
FROM cw_State AS _S, cw_Tag AS _T LEFT OUTER JOIN tags_relation AS rel_tags0 ON (rel_tags0.eid_from=_T.cw_eid) LEFT OUTER JOIN cw_CWUser AS _G ON (rel_tags0.eid_to=_G.cw_eid) |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
909 |
WHERE _G.cw_in_state=_S.cw_eid AND _S.cw_name=hop |
0 | 910 |
'''), |
911 |
||
912 |
# optional variable with additional invariant restriction on an inlined relation |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
913 |
('Any T,G,S WHERE T tags G, G in_state S?, S eid 1, G is CWUser', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
914 |
'''SELECT rel_tags0.eid_from, _G.cw_eid, _G.cw_in_state |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
915 |
FROM cw_CWUser AS _G, tags_relation AS rel_tags0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
916 |
WHERE rel_tags0.eid_to=_G.cw_eid AND (_G.cw_in_state=1 OR _G.cw_in_state IS NULL)'''), |
0 | 917 |
|
918 |
# two optional variables with additional invariant restriction on an inlined relation |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
919 |
('Any T,G,S WHERE T tags G?, G in_state S?, S eid 1, G is CWUser', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
920 |
'''SELECT _T.cw_eid, _G.cw_eid, _G.cw_in_state |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
921 |
FROM cw_Tag AS _T LEFT OUTER JOIN tags_relation AS rel_tags0 ON (rel_tags0.eid_from=_T.cw_eid) LEFT OUTER JOIN cw_CWUser AS _G ON (rel_tags0.eid_to=_G.cw_eid AND (_G.cw_in_state=1 OR _G.cw_in_state IS NULL))'''), |
0 | 922 |
|
923 |
# two optional variables with additional restriction on an inlined relation |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
924 |
('Any T,G,S WHERE T tags G?, G in_state S?, S name "hop", G is CWUser', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
925 |
'''SELECT _T.cw_eid, _G.cw_eid, _S.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
926 |
FROM cw_Tag AS _T LEFT OUTER JOIN tags_relation AS rel_tags0 ON (rel_tags0.eid_from=_T.cw_eid) LEFT OUTER JOIN cw_CWUser AS _G ON (rel_tags0.eid_to=_G.cw_eid) LEFT OUTER JOIN cw_State AS _S ON (_G.cw_in_state=_S.cw_eid AND _S.cw_name=hop)'''), |
1787 | 927 |
|
0 | 928 |
# two optional variables with additional restriction on an ambigous inlined relation |
929 |
('Any T,G,S WHERE T tags G?, G in_state S?, S name "hop"', |
|
1787 | 930 |
''' |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
931 |
SELECT _T.cw_eid, _T0.C0, _T0.C1 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
932 |
FROM cw_Tag AS _T LEFT OUTER JOIN tags_relation AS rel_tags0 ON (rel_tags0.eid_from=_T.cw_eid) LEFT OUTER JOIN (SELECT _G.cw_eid AS C0, _S.cw_eid AS C1 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
933 |
FROM cw_Affaire AS _G LEFT OUTER JOIN cw_State AS _S ON (_G.cw_in_state=_S.cw_eid AND _S.cw_name=hop) |
0 | 934 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
935 |
SELECT _G.cw_eid AS C0, _S.cw_eid AS C1 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
936 |
FROM cw_CWUser AS _G LEFT OUTER JOIN cw_State AS _S ON (_G.cw_in_state=_S.cw_eid AND _S.cw_name=hop) |
0 | 937 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
938 |
SELECT _G.cw_eid AS C0, _S.cw_eid AS C1 |
7193
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
939 |
FROM cw_Note AS _G LEFT OUTER JOIN cw_State AS _S ON (_G.cw_in_state=_S.cw_eid AND _S.cw_name=hop)) AS _T0 ON (rel_tags0.eid_to=_T0.C0)'''), |
0 | 940 |
|
2915
651bbe1526b6
[rql2sql] test and fix a bug triggered when editing a ticket in jpl
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2720
diff
changeset
|
941 |
('Any O,AD WHERE NOT S inline1 O, S eid 123, O todo_by AD?', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
942 |
'''SELECT _O.cw_eid, rel_todo_by0.eid_to |
7193
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
943 |
FROM cw_Note AS _S, cw_Affaire AS _O LEFT OUTER JOIN todo_by_relation AS rel_todo_by0 ON (rel_todo_by0.eid_from=_O.cw_eid) |
7252
adb1673efa5f
[sql generation] fix crash on outer join + ambiguous inlined relation + attribute selection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7194
diff
changeset
|
944 |
WHERE (_S.cw_inline1 IS NULL OR _S.cw_inline1!=_O.cw_eid) AND _S.cw_eid=123'''), |
adb1673efa5f
[sql generation] fix crash on outer join + ambiguous inlined relation + attribute selection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7194
diff
changeset
|
945 |
|
adb1673efa5f
[sql generation] fix crash on outer join + ambiguous inlined relation + attribute selection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7194
diff
changeset
|
946 |
('Any X,AE WHERE X multisource_inlined_rel S?, S ambiguous_inlined A, A modification_date AE', |
adb1673efa5f
[sql generation] fix crash on outer join + ambiguous inlined relation + attribute selection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7194
diff
changeset
|
947 |
'''SELECT _X.cw_eid, _T0.C2 |
adb1673efa5f
[sql generation] fix crash on outer join + ambiguous inlined relation + attribute selection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7194
diff
changeset
|
948 |
FROM cw_Card AS _X LEFT OUTER JOIN (SELECT _S.cw_eid AS C0, _A.cw_eid AS C1, _A.cw_modification_date AS C2 |
adb1673efa5f
[sql generation] fix crash on outer join + ambiguous inlined relation + attribute selection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7194
diff
changeset
|
949 |
FROM cw_Affaire AS _S, cw_CWUser AS _A |
adb1673efa5f
[sql generation] fix crash on outer join + ambiguous inlined relation + attribute selection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7194
diff
changeset
|
950 |
WHERE _S.cw_ambiguous_inlined=_A.cw_eid |
adb1673efa5f
[sql generation] fix crash on outer join + ambiguous inlined relation + attribute selection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7194
diff
changeset
|
951 |
UNION ALL |
adb1673efa5f
[sql generation] fix crash on outer join + ambiguous inlined relation + attribute selection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7194
diff
changeset
|
952 |
SELECT _S.cw_eid AS C0, _A.cw_eid AS C1, _A.cw_modification_date AS C2 |
adb1673efa5f
[sql generation] fix crash on outer join + ambiguous inlined relation + attribute selection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7194
diff
changeset
|
953 |
FROM cw_CWUser AS _A, cw_Note AS _S |
adb1673efa5f
[sql generation] fix crash on outer join + ambiguous inlined relation + attribute selection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7194
diff
changeset
|
954 |
WHERE _S.cw_ambiguous_inlined=_A.cw_eid) AS _T0 ON (_X.cw_multisource_inlined_rel=_T0.C0) |
adb1673efa5f
[sql generation] fix crash on outer join + ambiguous inlined relation + attribute selection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7194
diff
changeset
|
955 |
UNION ALL |
adb1673efa5f
[sql generation] fix crash on outer join + ambiguous inlined relation + attribute selection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7194
diff
changeset
|
956 |
SELECT _X.cw_eid, _T0.C2 |
adb1673efa5f
[sql generation] fix crash on outer join + ambiguous inlined relation + attribute selection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7194
diff
changeset
|
957 |
FROM cw_Note AS _X LEFT OUTER JOIN (SELECT _S.cw_eid AS C0, _A.cw_eid AS C1, _A.cw_modification_date AS C2 |
adb1673efa5f
[sql generation] fix crash on outer join + ambiguous inlined relation + attribute selection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7194
diff
changeset
|
958 |
FROM cw_Affaire AS _S, cw_CWUser AS _A |
adb1673efa5f
[sql generation] fix crash on outer join + ambiguous inlined relation + attribute selection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7194
diff
changeset
|
959 |
WHERE _S.cw_ambiguous_inlined=_A.cw_eid |
adb1673efa5f
[sql generation] fix crash on outer join + ambiguous inlined relation + attribute selection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7194
diff
changeset
|
960 |
UNION ALL |
adb1673efa5f
[sql generation] fix crash on outer join + ambiguous inlined relation + attribute selection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7194
diff
changeset
|
961 |
SELECT _S.cw_eid AS C0, _A.cw_eid AS C1, _A.cw_modification_date AS C2 |
adb1673efa5f
[sql generation] fix crash on outer join + ambiguous inlined relation + attribute selection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7194
diff
changeset
|
962 |
FROM cw_CWUser AS _A, cw_Note AS _S |
adb1673efa5f
[sql generation] fix crash on outer join + ambiguous inlined relation + attribute selection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7194
diff
changeset
|
963 |
WHERE _S.cw_ambiguous_inlined=_A.cw_eid) AS _T0 ON (_X.cw_multisource_inlined_rel=_T0.C0)''' |
adb1673efa5f
[sql generation] fix crash on outer join + ambiguous inlined relation + attribute selection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7194
diff
changeset
|
964 |
), |
adb1673efa5f
[sql generation] fix crash on outer join + ambiguous inlined relation + attribute selection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7194
diff
changeset
|
965 |
|
7357
5ad3154a8810
[rql2sql] fix bug avoiding outer join relation to be used as a variable principal. Closes #1659395
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7252
diff
changeset
|
966 |
('Any X,T,OT WHERE X tags T, OT? tags X, X is Tag, X eid 123', |
5ad3154a8810
[rql2sql] fix bug avoiding outer join relation to be used as a variable principal. Closes #1659395
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7252
diff
changeset
|
967 |
'''SELECT rel_tags0.eid_from, rel_tags0.eid_to, rel_tags1.eid_from |
5ad3154a8810
[rql2sql] fix bug avoiding outer join relation to be used as a variable principal. Closes #1659395
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7252
diff
changeset
|
968 |
FROM tags_relation AS rel_tags0 LEFT OUTER JOIN tags_relation AS rel_tags1 ON (rel_tags1.eid_to=123) |
5ad3154a8810
[rql2sql] fix bug avoiding outer join relation to be used as a variable principal. Closes #1659395
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7252
diff
changeset
|
969 |
WHERE rel_tags0.eid_from=123'''), |
7630
f4b954676721
closes #1784285: [rql2sql] crash when using a relation for inner and outer join
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7596
diff
changeset
|
970 |
|
f4b954676721
closes #1784285: [rql2sql] crash when using a relation for inner and outer join
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7596
diff
changeset
|
971 |
('Any CASE, CALIBCFG, CFG ' |
f4b954676721
closes #1784285: [rql2sql] crash when using a relation for inner and outer join
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7596
diff
changeset
|
972 |
'WHERE CASE eid 1, CFG ecrit_par CASE, CALIBCFG? ecrit_par CASE', |
f4b954676721
closes #1784285: [rql2sql] crash when using a relation for inner and outer join
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7596
diff
changeset
|
973 |
'''SELECT _CFG.cw_ecrit_par, _CALIBCFG.cw_eid, _CFG.cw_eid |
7734
59fea81647e5
[rql2sql] closes #1892473: enhance handling of optional inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7729
diff
changeset
|
974 |
FROM cw_Note AS _CFG LEFT OUTER JOIN cw_Note AS _CALIBCFG ON (_CALIBCFG.cw_ecrit_par=1) |
7630
f4b954676721
closes #1784285: [rql2sql] crash when using a relation for inner and outer join
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7596
diff
changeset
|
975 |
WHERE _CFG.cw_ecrit_par=1'''), |
7707
936530f8d32c
[sql gen] handle optional on comparison node (eg HAVING expression) and on rhs of final relation. Closes #1859609
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7705
diff
changeset
|
976 |
|
936530f8d32c
[sql gen] handle optional on comparison node (eg HAVING expression) and on rhs of final relation. Closes #1859609
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7705
diff
changeset
|
977 |
('Any U,G WHERE U login UL, G name GL, G is CWGroup HAVING UPPER(UL)=UPPER(GL)?', |
936530f8d32c
[sql gen] handle optional on comparison node (eg HAVING expression) and on rhs of final relation. Closes #1859609
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7705
diff
changeset
|
978 |
'''SELECT _U.cw_eid, _G.cw_eid |
936530f8d32c
[sql gen] handle optional on comparison node (eg HAVING expression) and on rhs of final relation. Closes #1859609
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7705
diff
changeset
|
979 |
FROM cw_CWUser AS _U LEFT OUTER JOIN cw_CWGroup AS _G ON (UPPER(_U.cw_login)=UPPER(_G.cw_name))'''), |
936530f8d32c
[sql gen] handle optional on comparison node (eg HAVING expression) and on rhs of final relation. Closes #1859609
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7705
diff
changeset
|
980 |
|
936530f8d32c
[sql gen] handle optional on comparison node (eg HAVING expression) and on rhs of final relation. Closes #1859609
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7705
diff
changeset
|
981 |
('Any U,G WHERE U login UL, G name GL, G is CWGroup HAVING UPPER(UL)?=UPPER(GL)', |
936530f8d32c
[sql gen] handle optional on comparison node (eg HAVING expression) and on rhs of final relation. Closes #1859609
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7705
diff
changeset
|
982 |
'''SELECT _U.cw_eid, _G.cw_eid |
936530f8d32c
[sql gen] handle optional on comparison node (eg HAVING expression) and on rhs of final relation. Closes #1859609
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7705
diff
changeset
|
983 |
FROM cw_CWGroup AS _G LEFT OUTER JOIN cw_CWUser AS _U ON (UPPER(_U.cw_login)=UPPER(_G.cw_name))'''), |
936530f8d32c
[sql gen] handle optional on comparison node (eg HAVING expression) and on rhs of final relation. Closes #1859609
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7705
diff
changeset
|
984 |
|
936530f8d32c
[sql gen] handle optional on comparison node (eg HAVING expression) and on rhs of final relation. Closes #1859609
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7705
diff
changeset
|
985 |
('Any U,G WHERE U login UL, G name GL, G is CWGroup HAVING UPPER(UL)?=UPPER(GL)?', |
936530f8d32c
[sql gen] handle optional on comparison node (eg HAVING expression) and on rhs of final relation. Closes #1859609
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7705
diff
changeset
|
986 |
'''SELECT _U.cw_eid, _G.cw_eid |
936530f8d32c
[sql gen] handle optional on comparison node (eg HAVING expression) and on rhs of final relation. Closes #1859609
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7705
diff
changeset
|
987 |
FROM cw_CWUser AS _U FULL OUTER JOIN cw_CWGroup AS _G ON (UPPER(_U.cw_login)=UPPER(_G.cw_name))'''), |
7734
59fea81647e5
[rql2sql] closes #1892473: enhance handling of optional inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7729
diff
changeset
|
988 |
|
59fea81647e5
[rql2sql] closes #1892473: enhance handling of optional inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7729
diff
changeset
|
989 |
('Any H, COUNT(X), SUM(XCE)/1000 ' |
59fea81647e5
[rql2sql] closes #1892473: enhance handling of optional inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7729
diff
changeset
|
990 |
'WHERE X type "0", X date XSCT, X para XCE, X? ecrit_par F, F eid 999999, F is Personne, ' |
59fea81647e5
[rql2sql] closes #1892473: enhance handling of optional inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7729
diff
changeset
|
991 |
'DH is Affaire, DH ref H ' |
59fea81647e5
[rql2sql] closes #1892473: enhance handling of optional inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7729
diff
changeset
|
992 |
'HAVING XSCT?=H', |
59fea81647e5
[rql2sql] closes #1892473: enhance handling of optional inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7729
diff
changeset
|
993 |
'''SELECT _DH.cw_ref, COUNT(_X.cw_eid), (SUM(_X.cw_para) / 1000) |
59fea81647e5
[rql2sql] closes #1892473: enhance handling of optional inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7729
diff
changeset
|
994 |
FROM cw_Affaire AS _DH LEFT OUTER JOIN cw_Note AS _X ON (_X.cw_date=_DH.cw_ref AND _X.cw_type=0 AND _X.cw_ecrit_par=999999)'''), |
59fea81647e5
[rql2sql] closes #1892473: enhance handling of optional inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7729
diff
changeset
|
995 |
|
59fea81647e5
[rql2sql] closes #1892473: enhance handling of optional inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7729
diff
changeset
|
996 |
('Any C WHERE X ecrit_par C?, X? inline1 F, F eid 1, X type XT, Z is Personne, Z nom ZN HAVING ZN=XT?', |
59fea81647e5
[rql2sql] closes #1892473: enhance handling of optional inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7729
diff
changeset
|
997 |
'''SELECT _X.cw_ecrit_par |
59fea81647e5
[rql2sql] closes #1892473: enhance handling of optional inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7729
diff
changeset
|
998 |
FROM cw_Personne AS _Z LEFT OUTER JOIN cw_Note AS _X ON (_Z.cw_nom=_X.cw_type AND _X.cw_inline1=1)'''), |
0 | 999 |
] |
1000 |
||
1001 |
VIRTUAL_VARS = [ |
|
3815
50b87f759b5d
test and fix http://www.logilab.org/ticket/499838
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3762
diff
changeset
|
1002 |
|
50b87f759b5d
test and fix http://www.logilab.org/ticket/499838
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3762
diff
changeset
|
1003 |
('Any X WHERE X is CWUser, X creation_date > D1, Y creation_date D1, Y login "SWEB09"', |
50b87f759b5d
test and fix http://www.logilab.org/ticket/499838
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3762
diff
changeset
|
1004 |
'''SELECT _X.cw_eid |
50b87f759b5d
test and fix http://www.logilab.org/ticket/499838
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3762
diff
changeset
|
1005 |
FROM cw_CWUser AS _X, cw_CWUser AS _Y |
50b87f759b5d
test and fix http://www.logilab.org/ticket/499838
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3762
diff
changeset
|
1006 |
WHERE _X.cw_creation_date>_Y.cw_creation_date AND _Y.cw_login=SWEB09'''), |
50b87f759b5d
test and fix http://www.logilab.org/ticket/499838
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3762
diff
changeset
|
1007 |
|
50b87f759b5d
test and fix http://www.logilab.org/ticket/499838
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3762
diff
changeset
|
1008 |
('Any X WHERE X is CWUser, Y creation_date D1, Y login "SWEB09", X creation_date > D1', |
50b87f759b5d
test and fix http://www.logilab.org/ticket/499838
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3762
diff
changeset
|
1009 |
'''SELECT _X.cw_eid |
50b87f759b5d
test and fix http://www.logilab.org/ticket/499838
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3762
diff
changeset
|
1010 |
FROM cw_CWUser AS _X, cw_CWUser AS _Y |
50b87f759b5d
test and fix http://www.logilab.org/ticket/499838
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3762
diff
changeset
|
1011 |
WHERE _Y.cw_login=SWEB09 AND _X.cw_creation_date>_Y.cw_creation_date'''), |
50b87f759b5d
test and fix http://www.logilab.org/ticket/499838
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3762
diff
changeset
|
1012 |
|
50b87f759b5d
test and fix http://www.logilab.org/ticket/499838
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3762
diff
changeset
|
1013 |
('Personne P WHERE P travaille S, S tel T, S fax T, S is Societe', |
0 | 1014 |
'''SELECT rel_travaille0.eid_from |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1015 |
FROM cw_Societe AS _S, travaille_relation AS rel_travaille0 |
3815
50b87f759b5d
test and fix http://www.logilab.org/ticket/499838
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3762
diff
changeset
|
1016 |
WHERE rel_travaille0.eid_to=_S.cw_eid AND _S.cw_tel=_S.cw_fax'''), |
1787 | 1017 |
|
0 | 1018 |
("Personne P where X eid 0, X creation_date D, P datenaiss < D, X is Affaire", |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1019 |
'''SELECT _P.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1020 |
FROM cw_Affaire AS _X, cw_Personne AS _P |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1021 |
WHERE _X.cw_eid=0 AND _P.cw_datenaiss<_X.cw_creation_date'''), |
0 | 1022 |
|
1023 |
("Any N,T WHERE N is Note, N type T;", |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1024 |
'''SELECT _N.cw_eid, _N.cw_type |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1025 |
FROM cw_Note AS _N'''), |
0 | 1026 |
|
1027 |
("Personne P where X is Personne, X tel T, X fax F, P fax T+F", |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1028 |
'''SELECT _P.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1029 |
FROM cw_Personne AS _P, cw_Personne AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1030 |
WHERE _P.cw_fax=(_X.cw_tel + _X.cw_fax)'''), |
0 | 1031 |
|
1032 |
("Personne P where X tel T, X fax F, P fax IN (T,F)", |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1033 |
'''SELECT _P.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1034 |
FROM cw_Division AS _X, cw_Personne AS _P |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1035 |
WHERE _P.cw_fax IN(_X.cw_tel, _X.cw_fax) |
0 | 1036 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1037 |
SELECT _P.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1038 |
FROM cw_Personne AS _P, cw_Personne AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1039 |
WHERE _P.cw_fax IN(_X.cw_tel, _X.cw_fax) |
0 | 1040 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1041 |
SELECT _P.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1042 |
FROM cw_Personne AS _P, cw_Societe AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1043 |
WHERE _P.cw_fax IN(_X.cw_tel, _X.cw_fax) |
0 | 1044 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1045 |
SELECT _P.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1046 |
FROM cw_Personne AS _P, cw_SubDivision AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1047 |
WHERE _P.cw_fax IN(_X.cw_tel, _X.cw_fax)'''), |
0 | 1048 |
|
1049 |
("Personne P where X tel T, X fax F, P fax IN (T,F,0832542332)", |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1050 |
'''SELECT _P.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1051 |
FROM cw_Division AS _X, cw_Personne AS _P |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1052 |
WHERE _P.cw_fax IN(_X.cw_tel, _X.cw_fax, 832542332) |
0 | 1053 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1054 |
SELECT _P.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1055 |
FROM cw_Personne AS _P, cw_Personne AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1056 |
WHERE _P.cw_fax IN(_X.cw_tel, _X.cw_fax, 832542332) |
0 | 1057 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1058 |
SELECT _P.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1059 |
FROM cw_Personne AS _P, cw_Societe AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1060 |
WHERE _P.cw_fax IN(_X.cw_tel, _X.cw_fax, 832542332) |
0 | 1061 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1062 |
SELECT _P.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1063 |
FROM cw_Personne AS _P, cw_SubDivision AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1064 |
WHERE _P.cw_fax IN(_X.cw_tel, _X.cw_fax, 832542332)'''), |
0 | 1065 |
] |
1066 |
||
1067 |
FUNCS = [ |
|
1068 |
("Any COUNT(P) WHERE P is Personne", |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1069 |
'''SELECT COUNT(_P.cw_eid) |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1070 |
FROM cw_Personne AS _P'''), |
0 | 1071 |
] |
1072 |
||
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
1073 |
SYMMETRIC = [ |
0 | 1074 |
('Any P WHERE X eid 0, X connait P', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1075 |
'''SELECT DISTINCT _P.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1076 |
FROM connait_relation AS rel_connait0, cw_Personne AS _P |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1077 |
WHERE (rel_connait0.eid_from=0 AND rel_connait0.eid_to=_P.cw_eid OR rel_connait0.eid_to=0 AND rel_connait0.eid_from=_P.cw_eid)''' |
0 | 1078 |
), |
1787 | 1079 |
|
0 | 1080 |
('Any P WHERE X connait P', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1081 |
'''SELECT DISTINCT _P.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1082 |
FROM connait_relation AS rel_connait0, cw_Personne AS _P |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1083 |
WHERE (rel_connait0.eid_to=_P.cw_eid OR rel_connait0.eid_from=_P.cw_eid)''' |
0 | 1084 |
), |
1787 | 1085 |
|
0 | 1086 |
('Any X WHERE X connait P', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1087 |
'''SELECT DISTINCT _X.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1088 |
FROM connait_relation AS rel_connait0, cw_Personne AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1089 |
WHERE (rel_connait0.eid_from=_X.cw_eid OR rel_connait0.eid_to=_X.cw_eid)''' |
0 | 1090 |
), |
1787 | 1091 |
|
0 | 1092 |
('Any P WHERE X eid 0, NOT X connait P', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1093 |
'''SELECT _P.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1094 |
FROM cw_Personne AS _P |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
1095 |
WHERE NOT (EXISTS(SELECT 1 FROM connait_relation AS rel_connait0 WHERE (rel_connait0.eid_from=0 AND rel_connait0.eid_to=_P.cw_eid OR rel_connait0.eid_to=0 AND rel_connait0.eid_from=_P.cw_eid)))'''), |
1787 | 1096 |
|
0 | 1097 |
('Any P WHERE NOT X connait P', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1098 |
'''SELECT _P.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1099 |
FROM cw_Personne AS _P |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
1100 |
WHERE NOT (EXISTS(SELECT 1 FROM connait_relation AS rel_connait0 WHERE (rel_connait0.eid_to=_P.cw_eid OR rel_connait0.eid_from=_P.cw_eid)))'''), |
1787 | 1101 |
|
0 | 1102 |
('Any X WHERE NOT X connait P', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1103 |
'''SELECT _X.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1104 |
FROM cw_Personne AS _X |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
1105 |
WHERE NOT (EXISTS(SELECT 1 FROM connait_relation AS rel_connait0 WHERE (rel_connait0.eid_from=_X.cw_eid OR rel_connait0.eid_to=_X.cw_eid)))'''), |
0 | 1106 |
|
1107 |
('Any P WHERE X connait P, P nom "nom"', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1108 |
'''SELECT DISTINCT _P.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1109 |
FROM connait_relation AS rel_connait0, cw_Personne AS _P |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1110 |
WHERE (rel_connait0.eid_to=_P.cw_eid OR rel_connait0.eid_from=_P.cw_eid) AND _P.cw_nom=nom'''), |
1787 | 1111 |
|
0 | 1112 |
('Any X WHERE X connait P, P nom "nom"', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1113 |
'''SELECT DISTINCT _X.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1114 |
FROM connait_relation AS rel_connait0, cw_Personne AS _P, cw_Personne AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1115 |
WHERE (rel_connait0.eid_from=_X.cw_eid AND rel_connait0.eid_to=_P.cw_eid OR rel_connait0.eid_to=_X.cw_eid AND rel_connait0.eid_from=_P.cw_eid) AND _P.cw_nom=nom''' |
0 | 1116 |
), |
1117 |
||
7108
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1118 |
('DISTINCT Any P WHERE P connait S OR S connait P, S nom "chouette"', |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1119 |
'''SELECT DISTINCT _P.cw_eid |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1120 |
FROM connait_relation AS rel_connait0, cw_Personne AS _P, cw_Personne AS _S |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1121 |
WHERE (rel_connait0.eid_from=_P.cw_eid AND rel_connait0.eid_to=_S.cw_eid OR rel_connait0.eid_to=_P.cw_eid AND rel_connait0.eid_from=_S.cw_eid) AND _S.cw_nom=chouette''' |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1122 |
) |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1123 |
] |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1124 |
|
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1125 |
SYMMETRIC_WITH_LIMIT = [ |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1126 |
('Any X ORDERBY X DESC LIMIT 9 WHERE E eid 0, E connait X', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1127 |
'''SELECT DISTINCT _X.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1128 |
FROM connait_relation AS rel_connait0, cw_Personne AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1129 |
WHERE (rel_connait0.eid_from=0 AND rel_connait0.eid_to=_X.cw_eid OR rel_connait0.eid_to=0 AND rel_connait0.eid_from=_X.cw_eid) |
0 | 1130 |
ORDER BY 1 DESC |
1131 |
LIMIT 9''' |
|
1132 |
), |
|
7108
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1133 |
] |
0 | 1134 |
|
1135 |
INLINE = [ |
|
5844
df7608ecea29
[sql generation] fix bug with inlined relation and referenced by other neged relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5793
diff
changeset
|
1136 |
|
df7608ecea29
[sql generation] fix bug with inlined relation and referenced by other neged relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5793
diff
changeset
|
1137 |
('Any P WHERE N eid 1, N ecrit_par P, NOT P owned_by P2', |
df7608ecea29
[sql generation] fix bug with inlined relation and referenced by other neged relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5793
diff
changeset
|
1138 |
'''SELECT _N.cw_ecrit_par |
df7608ecea29
[sql generation] fix bug with inlined relation and referenced by other neged relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5793
diff
changeset
|
1139 |
FROM cw_Note AS _N |
df7608ecea29
[sql generation] fix bug with inlined relation and referenced by other neged relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5793
diff
changeset
|
1140 |
WHERE _N.cw_eid=1 AND _N.cw_ecrit_par IS NOT NULL AND NOT (EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by0 WHERE _N.cw_ecrit_par=rel_owned_by0.eid_from))'''), |
df7608ecea29
[sql generation] fix bug with inlined relation and referenced by other neged relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5793
diff
changeset
|
1141 |
|
0 | 1142 |
('Any P, L WHERE N ecrit_par P, P nom L, N eid 0', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1143 |
'''SELECT _P.cw_eid, _P.cw_nom |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1144 |
FROM cw_Note AS _N, cw_Personne AS _P |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1145 |
WHERE _N.cw_ecrit_par=_P.cw_eid AND _N.cw_eid=0'''), |
1787 | 1146 |
|
0 | 1147 |
('Any N WHERE NOT N ecrit_par P, P nom "toto"', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1148 |
'''SELECT _N.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1149 |
FROM cw_Note AS _N, cw_Personne AS _P |
6003
5fbc1c4c13ff
[rql2sql] fix bug with NOT of inlined relation: NULL values are not properly handled and hence some rows won't be returned while the should
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5901
diff
changeset
|
1150 |
WHERE (_N.cw_ecrit_par IS NULL OR _N.cw_ecrit_par!=_P.cw_eid) AND _P.cw_nom=toto'''), |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
1151 |
|
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
1152 |
('Any P WHERE NOT N ecrit_par P, P nom "toto"', |
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
1153 |
'''SELECT _P.cw_eid |
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
1154 |
FROM cw_Personne AS _P |
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
1155 |
WHERE NOT (EXISTS(SELECT 1 FROM cw_Note AS _N WHERE _N.cw_ecrit_par=_P.cw_eid)) AND _P.cw_nom=toto'''), |
1787 | 1156 |
|
0 | 1157 |
('Any P WHERE N ecrit_par P, N eid 0', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1158 |
'''SELECT _N.cw_ecrit_par |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1159 |
FROM cw_Note AS _N |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1160 |
WHERE _N.cw_ecrit_par IS NOT NULL AND _N.cw_eid=0'''), |
0 | 1161 |
|
1162 |
('Any P WHERE N ecrit_par P, P is Personne, N eid 0', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1163 |
'''SELECT _P.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1164 |
FROM cw_Note AS _N, cw_Personne AS _P |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1165 |
WHERE _N.cw_ecrit_par=_P.cw_eid AND _N.cw_eid=0'''), |
0 | 1166 |
|
1167 |
('Any P WHERE NOT N ecrit_par P, P is Personne, N eid 512', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1168 |
'''SELECT _P.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1169 |
FROM cw_Note AS _N, cw_Personne AS _P |
6003
5fbc1c4c13ff
[rql2sql] fix bug with NOT of inlined relation: NULL values are not properly handled and hence some rows won't be returned while the should
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5901
diff
changeset
|
1170 |
WHERE (_N.cw_ecrit_par IS NULL OR _N.cw_ecrit_par!=_P.cw_eid) AND _N.cw_eid=512'''), |
0 | 1171 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1172 |
('Any S,ES,T WHERE S state_of ET, ET name "CWUser", ES allowed_transition T, T destination_state S', |
5844
df7608ecea29
[sql generation] fix bug with inlined relation and referenced by other neged relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5793
diff
changeset
|
1173 |
# XXX "_T.cw_destination_state IS NOT NULL" could be avoided here but it's not worth it |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1174 |
'''SELECT _T.cw_destination_state, rel_allowed_transition1.eid_from, _T.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1175 |
FROM allowed_transition_relation AS rel_allowed_transition1, cw_Transition AS _T, cw_Workflow AS _ET, state_of_relation AS rel_state_of0 |
5844
df7608ecea29
[sql generation] fix bug with inlined relation and referenced by other neged relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5793
diff
changeset
|
1176 |
WHERE _T.cw_destination_state=rel_state_of0.eid_from AND rel_state_of0.eid_to=_ET.cw_eid AND _ET.cw_name=CWUser AND rel_allowed_transition1.eid_to=_T.cw_eid AND _T.cw_destination_state IS NOT NULL'''), |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2916
diff
changeset
|
1177 |
|
0 | 1178 |
('Any O WHERE S eid 0, S in_state O', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1179 |
'''SELECT _S.cw_in_state |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1180 |
FROM cw_Affaire AS _S |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1181 |
WHERE _S.cw_eid=0 AND _S.cw_in_state IS NOT NULL |
0 | 1182 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1183 |
SELECT _S.cw_in_state |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1184 |
FROM cw_CWUser AS _S |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1185 |
WHERE _S.cw_eid=0 AND _S.cw_in_state IS NOT NULL |
0 | 1186 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1187 |
SELECT _S.cw_in_state |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1188 |
FROM cw_Note AS _S |
3987
f85ef29f6214
fix sql generation bug with neged inlined relation where the object is invariant and subject is only referenced by the relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3852
diff
changeset
|
1189 |
WHERE _S.cw_eid=0 AND _S.cw_in_state IS NOT NULL'''), |
f85ef29f6214
fix sql generation bug with neged inlined relation where the object is invariant and subject is only referenced by the relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3852
diff
changeset
|
1190 |
|
f85ef29f6214
fix sql generation bug with neged inlined relation where the object is invariant and subject is only referenced by the relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3852
diff
changeset
|
1191 |
('Any X WHERE NOT Y for_user X, X eid 123', |
f85ef29f6214
fix sql generation bug with neged inlined relation where the object is invariant and subject is only referenced by the relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3852
diff
changeset
|
1192 |
'''SELECT 123 |
5898
5630bd8f98d9
imported patch rql2sqlfix.diff
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5887
diff
changeset
|
1193 |
WHERE NOT (EXISTS(SELECT 1 FROM cw_CWProperty AS _Y WHERE _Y.cw_for_user=123))'''), |
1787 | 1194 |
|
5898
5630bd8f98d9
imported patch rql2sqlfix.diff
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5887
diff
changeset
|
1195 |
('DISTINCT Any X WHERE X from_entity OET, NOT X from_entity NET, OET name "Image", NET eid 1', |
5630bd8f98d9
imported patch rql2sqlfix.diff
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5887
diff
changeset
|
1196 |
'''SELECT DISTINCT _X.cw_eid |
5630bd8f98d9
imported patch rql2sqlfix.diff
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5887
diff
changeset
|
1197 |
FROM cw_CWAttribute AS _X, cw_CWEType AS _OET |
6003
5fbc1c4c13ff
[rql2sql] fix bug with NOT of inlined relation: NULL values are not properly handled and hence some rows won't be returned while the should
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5901
diff
changeset
|
1198 |
WHERE _X.cw_from_entity=_OET.cw_eid AND (_X.cw_from_entity IS NULL OR _X.cw_from_entity!=1) AND _OET.cw_name=Image |
5898
5630bd8f98d9
imported patch rql2sqlfix.diff
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5887
diff
changeset
|
1199 |
UNION |
5630bd8f98d9
imported patch rql2sqlfix.diff
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5887
diff
changeset
|
1200 |
SELECT DISTINCT _X.cw_eid |
5630bd8f98d9
imported patch rql2sqlfix.diff
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5887
diff
changeset
|
1201 |
FROM cw_CWEType AS _OET, cw_CWRelation AS _X |
6003
5fbc1c4c13ff
[rql2sql] fix bug with NOT of inlined relation: NULL values are not properly handled and hence some rows won't be returned while the should
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5901
diff
changeset
|
1202 |
WHERE _X.cw_from_entity=_OET.cw_eid AND (_X.cw_from_entity IS NULL OR _X.cw_from_entity!=1) AND _OET.cw_name=Image'''), |
5fbc1c4c13ff
[rql2sql] fix bug with NOT of inlined relation: NULL values are not properly handled and hence some rows won't be returned while the should
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5901
diff
changeset
|
1203 |
|
0 | 1204 |
] |
1205 |
||
438 | 1206 |
INTERSECT = [ |
1207 |
('Any SN WHERE NOT X in_state S, S name SN', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1208 |
'''SELECT _S.cw_name |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1209 |
FROM cw_State AS _S |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
1210 |
WHERE NOT (EXISTS(SELECT 1 FROM cw_Affaire AS _X WHERE _X.cw_in_state=_S.cw_eid UNION SELECT 1 FROM cw_Note AS _X WHERE _X.cw_in_state=_S.cw_eid UNION SELECT 1 FROM cw_CWUser AS _X WHERE _X.cw_in_state=_S.cw_eid))'''), |
0 | 1211 |
|
438 | 1212 |
('Any PN WHERE NOT X travaille S, X nom PN, S is IN(Division, Societe)', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1213 |
'''SELECT _X.cw_nom |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1214 |
FROM cw_Personne AS _X |
7193
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
1215 |
WHERE NOT (EXISTS(SELECT 1 FROM cw_Division AS _S, travaille_relation AS rel_travaille0 WHERE rel_travaille0.eid_from=_X.cw_eid AND rel_travaille0.eid_to=_S.cw_eid UNION SELECT 1 FROM cw_Societe AS _S, travaille_relation AS rel_travaille1 WHERE rel_travaille1.eid_from=_X.cw_eid AND rel_travaille1.eid_to=_S.cw_eid))'''), |
1787 | 1216 |
|
438 | 1217 |
('Any PN WHERE NOT X travaille S, S nom PN, S is IN(Division, Societe)', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1218 |
'''SELECT _S.cw_nom |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1219 |
FROM cw_Division AS _S |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
1220 |
WHERE NOT (EXISTS(SELECT 1 FROM travaille_relation AS rel_travaille0 WHERE rel_travaille0.eid_to=_S.cw_eid)) |
438 | 1221 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1222 |
SELECT _S.cw_nom |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1223 |
FROM cw_Societe AS _S |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
1224 |
WHERE NOT (EXISTS(SELECT 1 FROM travaille_relation AS rel_travaille0 WHERE rel_travaille0.eid_to=_S.cw_eid))'''), |
1787 | 1225 |
|
438 | 1226 |
('Personne X WHERE NOT X travaille S, S nom "chouette"', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1227 |
'''SELECT _X.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1228 |
FROM cw_Division AS _S, cw_Personne AS _X |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
1229 |
WHERE NOT (EXISTS(SELECT 1 FROM travaille_relation AS rel_travaille0 WHERE rel_travaille0.eid_from=_X.cw_eid AND rel_travaille0.eid_to=_S.cw_eid)) AND _S.cw_nom=chouette |
438 | 1230 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1231 |
SELECT _X.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1232 |
FROM cw_Personne AS _X, cw_Societe AS _S |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
1233 |
WHERE NOT (EXISTS(SELECT 1 FROM travaille_relation AS rel_travaille0 WHERE rel_travaille0.eid_from=_X.cw_eid AND rel_travaille0.eid_to=_S.cw_eid)) AND _S.cw_nom=chouette |
438 | 1234 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1235 |
SELECT _X.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1236 |
FROM cw_Personne AS _X, cw_SubDivision AS _S |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
1237 |
WHERE NOT (EXISTS(SELECT 1 FROM travaille_relation AS rel_travaille0 WHERE rel_travaille0.eid_from=_X.cw_eid AND rel_travaille0.eid_to=_S.cw_eid)) AND _S.cw_nom=chouette'''), |
1787 | 1238 |
|
438 | 1239 |
('Any X WHERE X is ET, ET eid 2', |
1240 |
'''SELECT rel_is0.eid_from |
|
1241 |
FROM is_relation AS rel_is0 |
|
1242 |
WHERE rel_is0.eid_to=2'''), |
|
1243 |
||
1244 |
] |
|
2720
405c09e7df6e
[rql test] add non regression test for rql (fail with current rql head)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2642
diff
changeset
|
1245 |
class CWRQLTC(RQLGeneratorTC): |
5768
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1246 |
backend = 'sqlite' |
6631
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6493
diff
changeset
|
1247 |
|
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6493
diff
changeset
|
1248 |
def setUp(self): |
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6493
diff
changeset
|
1249 |
self.__class__.schema = schema |
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6493
diff
changeset
|
1250 |
super(CWRQLTC, self).setUp() |
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6493
diff
changeset
|
1251 |
|
2720
405c09e7df6e
[rql test] add non regression test for rql (fail with current rql head)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2642
diff
changeset
|
1252 |
def test_nonregr_sol(self): |
405c09e7df6e
[rql test] add non regression test for rql (fail with current rql head)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2642
diff
changeset
|
1253 |
delete = self.rqlhelper.parse( |
405c09e7df6e
[rql test] add non regression test for rql (fail with current rql head)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2642
diff
changeset
|
1254 |
'DELETE X read_permission READ_PERMISSIONSUBJECT,X add_permission ADD_PERMISSIONSUBJECT,' |
405c09e7df6e
[rql test] add non regression test for rql (fail with current rql head)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2642
diff
changeset
|
1255 |
'X in_basket IN_BASKETSUBJECT,X delete_permission DELETE_PERMISSIONSUBJECT,' |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2916
diff
changeset
|
1256 |
'X update_permission UPDATE_PERMISSIONSUBJECT,' |
2720
405c09e7df6e
[rql test] add non regression test for rql (fail with current rql head)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2642
diff
changeset
|
1257 |
'X created_by CREATED_BYSUBJECT,X is ISSUBJECT,X is_instance_of IS_INSTANCE_OFSUBJECT,' |
405c09e7df6e
[rql test] add non regression test for rql (fail with current rql head)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2642
diff
changeset
|
1258 |
'X owned_by OWNED_BYSUBJECT,X specializes SPECIALIZESSUBJECT,ISOBJECT is X,' |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2916
diff
changeset
|
1259 |
'SPECIALIZESOBJECT specializes X,IS_INSTANCE_OFOBJECT is_instance_of X,' |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2916
diff
changeset
|
1260 |
'TO_ENTITYOBJECT to_entity X,FROM_ENTITYOBJECT from_entity X ' |
2720
405c09e7df6e
[rql test] add non regression test for rql (fail with current rql head)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2642
diff
changeset
|
1261 |
'WHERE X is CWEType') |
405c09e7df6e
[rql test] add non regression test for rql (fail with current rql head)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2642
diff
changeset
|
1262 |
self.rqlhelper.compute_solutions(delete) |
405c09e7df6e
[rql test] add non regression test for rql (fail with current rql head)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2642
diff
changeset
|
1263 |
def var_sols(var): |
405c09e7df6e
[rql test] add non regression test for rql (fail with current rql head)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2642
diff
changeset
|
1264 |
s = set() |
405c09e7df6e
[rql test] add non regression test for rql (fail with current rql head)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2642
diff
changeset
|
1265 |
for sol in delete.solutions: |
405c09e7df6e
[rql test] add non regression test for rql (fail with current rql head)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2642
diff
changeset
|
1266 |
s.add(sol.get(var)) |
405c09e7df6e
[rql test] add non regression test for rql (fail with current rql head)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2642
diff
changeset
|
1267 |
return s |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6297
diff
changeset
|
1268 |
self.assertEqual(var_sols('FROM_ENTITYOBJECT'), set(('CWAttribute', 'CWRelation'))) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6297
diff
changeset
|
1269 |
self.assertEqual(var_sols('FROM_ENTITYOBJECT'), delete.defined_vars['FROM_ENTITYOBJECT'].stinfo['possibletypes']) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6297
diff
changeset
|
1270 |
self.assertEqual(var_sols('ISOBJECT'), |
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3632
diff
changeset
|
1271 |
set(x.type for x in self.schema.entities() if not x.final)) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6297
diff
changeset
|
1272 |
self.assertEqual(var_sols('ISOBJECT'), delete.defined_vars['ISOBJECT'].stinfo['possibletypes']) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6297
diff
changeset
|
1273 |
|
2720
405c09e7df6e
[rql test] add non regression test for rql (fail with current rql head)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2642
diff
changeset
|
1274 |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6297
diff
changeset
|
1275 |
def strip(text): |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6297
diff
changeset
|
1276 |
return '\n'.join(l.strip() for l in text.strip().splitlines()) |
2720
405c09e7df6e
[rql test] add non regression test for rql (fail with current rql head)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2642
diff
changeset
|
1277 |
|
0 | 1278 |
class PostgresSQLGeneratorTC(RQLGeneratorTC): |
5768
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1279 |
backend = 'postgres' |
0 | 1280 |
|
6631
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6493
diff
changeset
|
1281 |
def setUp(self): |
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6493
diff
changeset
|
1282 |
self.__class__.schema = schema |
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6493
diff
changeset
|
1283 |
super(PostgresSQLGeneratorTC, self).setUp() |
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6493
diff
changeset
|
1284 |
|
0 | 1285 |
def _norm_sql(self, sql): |
1286 |
return sql.strip() |
|
1787 | 1287 |
|
2071
6ebada01a4a1
new test for missing from close when using a var map
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
1288 |
def _check(self, rql, sql, varmap=None, args=None): |
6ebada01a4a1
new test for missing from close when using a var map
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
1289 |
if args is None: |
7596
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1290 |
args = {'text': 'hip hop momo', 'eid': 12345} |
0 | 1291 |
try: |
1292 |
union = self._prepare(rql) |
|
5013
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5010
diff
changeset
|
1293 |
r, nargs, cbs = self.o.generate(union, args, |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5010
diff
changeset
|
1294 |
varmap=varmap) |
2071
6ebada01a4a1
new test for missing from close when using a var map
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
1295 |
args.update(nargs) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6297
diff
changeset
|
1296 |
self.assertMultiLineEqual(strip(r % args), self._norm_sql(sql)) |
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8457
diff
changeset
|
1297 |
except Exception as ex: |
0 | 1298 |
if 'r' in locals(): |
2071
6ebada01a4a1
new test for missing from close when using a var map
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
1299 |
try: |
6ebada01a4a1
new test for missing from close when using a var map
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
1300 |
print (r%args).strip() |
6ebada01a4a1
new test for missing from close when using a var map
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
1301 |
except KeyError: |
6ebada01a4a1
new test for missing from close when using a var map
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
1302 |
print 'strange, missing substitution' |
6ebada01a4a1
new test for missing from close when using a var map
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
1303 |
print r, nargs |
0 | 1304 |
print '!=' |
1305 |
print sql.strip() |
|
7193
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
1306 |
print 'RQL:', rql |
0 | 1307 |
raise |
1787 | 1308 |
|
0 | 1309 |
def _parse(self, rqls): |
1310 |
for rql, sql in rqls: |
|
1311 |
yield self._check, rql, sql |
|
1787 | 1312 |
|
0 | 1313 |
def _checkall(self, rql, sql): |
7166
dde161937d3e
[time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
1314 |
if isinstance(rql, tuple): |
dde161937d3e
[time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
1315 |
rql, args = rql |
dde161937d3e
[time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
1316 |
else: |
dde161937d3e
[time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
1317 |
args = None |
0 | 1318 |
try: |
1319 |
rqlst = self._prepare(rql) |
|
7166
dde161937d3e
[time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
1320 |
r, args, cbs = self.o.generate(rqlst, args) |
0 | 1321 |
self.assertEqual((r.strip(), args), sql) |
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8457
diff
changeset
|
1322 |
except Exception as ex: |
0 | 1323 |
print rql |
1324 |
if 'r' in locals(): |
|
1325 |
print r.strip() |
|
1326 |
print '!=' |
|
1327 |
print sql[0].strip() |
|
1328 |
raise |
|
1329 |
return |
|
1330 |
||
1331 |
def test1(self): |
|
7166
dde161937d3e
[time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
1332 |
self._checkall(('Any count(RDEF) WHERE RDEF relation_type X, X eid %(x)s', {'x': None}), |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1333 |
("""SELECT COUNT(T1.C0) FROM (SELECT _RDEF.cw_eid AS C0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1334 |
FROM cw_CWAttribute AS _RDEF |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1335 |
WHERE _RDEF.cw_relation_type=%(x)s |
0 | 1336 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1337 |
SELECT _RDEF.cw_eid AS C0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1338 |
FROM cw_CWRelation AS _RDEF |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1339 |
WHERE _RDEF.cw_relation_type=%(x)s) AS T1""", {}), |
0 | 1340 |
) |
1341 |
||
1342 |
def test2(self): |
|
7166
dde161937d3e
[time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
1343 |
self._checkall(('Any X WHERE C comments X, C eid %(x)s', {'x': None}), |
0 | 1344 |
('''SELECT rel_comments0.eid_to |
1345 |
FROM comments_relation AS rel_comments0 |
|
1346 |
WHERE rel_comments0.eid_from=%(x)s''', {}) |
|
1347 |
) |
|
1348 |
||
1349 |
def test_cache_1(self): |
|
1350 |
self._check('Any X WHERE X in_basket B, B eid 12', |
|
1351 |
'''SELECT rel_in_basket0.eid_from |
|
1352 |
FROM in_basket_relation AS rel_in_basket0 |
|
1353 |
WHERE rel_in_basket0.eid_to=12''') |
|
1787 | 1354 |
|
0 | 1355 |
self._check('Any X WHERE X in_basket B, B eid 12', |
1356 |
'''SELECT rel_in_basket0.eid_from |
|
1357 |
FROM in_basket_relation AS rel_in_basket0 |
|
1358 |
WHERE rel_in_basket0.eid_to=12''') |
|
1359 |
||
2071
6ebada01a4a1
new test for missing from close when using a var map
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
1360 |
def test_varmap1(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1361 |
self._check('Any X,L WHERE X is CWUser, X in_group G, X login L, G name "users"', |
0 | 1362 |
'''SELECT T00.x, T00.l |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1363 |
FROM T00, cw_CWGroup AS _G, in_group_relation AS rel_in_group0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1364 |
WHERE rel_in_group0.eid_from=T00.x AND rel_in_group0.eid_to=_G.cw_eid AND _G.cw_name=users''', |
0 | 1365 |
varmap={'X': 'T00.x', 'X.login': 'T00.l'}) |
2071
6ebada01a4a1
new test for missing from close when using a var map
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
1366 |
|
6ebada01a4a1
new test for missing from close when using a var map
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
1367 |
def test_varmap2(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1368 |
self._check('Any X,L,GN WHERE X is CWUser, X in_group G, X login L, G name GN', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1369 |
'''SELECT T00.x, T00.l, _G.cw_name |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1370 |
FROM T00, cw_CWGroup AS _G, in_group_relation AS rel_in_group0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1371 |
WHERE rel_in_group0.eid_from=T00.x AND rel_in_group0.eid_to=_G.cw_eid''', |
0 | 1372 |
varmap={'X': 'T00.x', 'X.login': 'T00.l'}) |
1373 |
||
2071
6ebada01a4a1
new test for missing from close when using a var map
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
1374 |
def test_varmap3(self): |
6ebada01a4a1
new test for missing from close when using a var map
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
1375 |
self._check('Any %(x)s,D WHERE F data D, F is File', |
6ebada01a4a1
new test for missing from close when using a var map
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
1376 |
'SELECT 728, _TDF0.C0\nFROM _TDF0', |
6ebada01a4a1
new test for missing from close when using a var map
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
1377 |
args={'x': 728}, |
6ebada01a4a1
new test for missing from close when using a var map
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
1378 |
varmap={'F.data': '_TDF0.C0', 'D': '_TDF0.C0'}) |
6ebada01a4a1
new test for missing from close when using a var map
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
1379 |
|
1862
94dc8ccd320b
#343322: should generate IS NULL in sql w/ None values in substitution
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1787
diff
changeset
|
1380 |
def test_is_null_transform(self): |
94dc8ccd320b
#343322: should generate IS NULL in sql w/ None values in substitution
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1787
diff
changeset
|
1381 |
union = self._prepare('Any X WHERE X login %(login)s') |
5013
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5010
diff
changeset
|
1382 |
r, args, cbs = self.o.generate(union, {'login': None}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6297
diff
changeset
|
1383 |
self.assertMultiLineEqual((r % args).strip(), |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1384 |
'''SELECT _X.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1385 |
FROM cw_CWUser AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1386 |
WHERE _X.cw_login IS NULL''') |
1862
94dc8ccd320b
#343322: should generate IS NULL in sql w/ None values in substitution
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1787
diff
changeset
|
1387 |
|
8217
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
1388 |
def test_today(self): |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
1389 |
for t in self._parse([("Any X WHERE X creation_date TODAY, X is Affaire", |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
1390 |
'''SELECT _X.cw_eid |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
1391 |
FROM cw_Affaire AS _X |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
1392 |
WHERE DATE(_X.cw_creation_date)=CAST(clock_timestamp() AS DATE)'''), |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
1393 |
("Personne P where not P datenaiss TODAY", |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
1394 |
'''SELECT _P.cw_eid |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
1395 |
FROM cw_Personne AS _P |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
1396 |
WHERE NOT (DATE(_P.cw_datenaiss)=CAST(clock_timestamp() AS DATE))'''), |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
1397 |
]): |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
1398 |
yield t |
4831
c5aec27c1bf7
[repo] use logilab.db instead of lgc.adbh/lgc.db/lgc.sqlgen/indexer, test new date extranction functions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
1399 |
|
c5aec27c1bf7
[repo] use logilab.db instead of lgc.adbh/lgc.db/lgc.sqlgen/indexer, test new date extranction functions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
1400 |
def test_date_extraction(self): |
c5aec27c1bf7
[repo] use logilab.db instead of lgc.adbh/lgc.db/lgc.sqlgen/indexer, test new date extranction functions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
1401 |
self._check("Any MONTH(D) WHERE P is Personne, P creation_date D", |
c5aec27c1bf7
[repo] use logilab.db instead of lgc.adbh/lgc.db/lgc.sqlgen/indexer, test new date extranction functions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
1402 |
'''SELECT CAST(EXTRACT(MONTH from _P.cw_creation_date) AS INTEGER) |
c5aec27c1bf7
[repo] use logilab.db instead of lgc.adbh/lgc.db/lgc.sqlgen/indexer, test new date extranction functions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
1403 |
FROM cw_Personne AS _P''') |
c5aec27c1bf7
[repo] use logilab.db instead of lgc.adbh/lgc.db/lgc.sqlgen/indexer, test new date extranction functions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
1404 |
|
7904
f41bb38dda7c
[rql, sql] support for weekday function introduced in lgdp 1.7 (closes #1979717)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7902
diff
changeset
|
1405 |
def test_weekday_extraction(self): |
f41bb38dda7c
[rql, sql] support for weekday function introduced in lgdp 1.7 (closes #1979717)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7902
diff
changeset
|
1406 |
self._check("Any WEEKDAY(D) WHERE P is Personne, P creation_date D", |
f41bb38dda7c
[rql, sql] support for weekday function introduced in lgdp 1.7 (closes #1979717)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7902
diff
changeset
|
1407 |
'''SELECT (CAST(EXTRACT(DOW from _P.cw_creation_date) AS INTEGER) + 1) |
f41bb38dda7c
[rql, sql] support for weekday function introduced in lgdp 1.7 (closes #1979717)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7902
diff
changeset
|
1408 |
FROM cw_Personne AS _P''') |
f41bb38dda7c
[rql, sql] support for weekday function introduced in lgdp 1.7 (closes #1979717)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7902
diff
changeset
|
1409 |
|
5233
673b63953e7a
ticket #787103, entity schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
5016
diff
changeset
|
1410 |
def test_substring(self): |
673b63953e7a
ticket #787103, entity schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
5016
diff
changeset
|
1411 |
self._check("Any SUBSTRING(N, 1, 1) WHERE P nom N, P is Personne", |
673b63953e7a
ticket #787103, entity schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
5016
diff
changeset
|
1412 |
'''SELECT SUBSTR(_P.cw_nom, 1, 1) |
673b63953e7a
ticket #787103, entity schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
5016
diff
changeset
|
1413 |
FROM cw_Personne AS _P''') |
4831
c5aec27c1bf7
[repo] use logilab.db instead of lgc.adbh/lgc.db/lgc.sqlgen/indexer, test new date extranction functions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
1414 |
|
7256
ccd44caeb936
[rql] support CAST() Function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7252
diff
changeset
|
1415 |
def test_cast(self): |
ccd44caeb936
[rql] support CAST() Function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7252
diff
changeset
|
1416 |
self._check("Any CAST(String, P) WHERE P is Personne", |
ccd44caeb936
[rql] support CAST() Function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7252
diff
changeset
|
1417 |
'''SELECT CAST(_P.cw_eid AS text) |
ccd44caeb936
[rql] support CAST() Function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7252
diff
changeset
|
1418 |
FROM cw_Personne AS _P''') |
ccd44caeb936
[rql] support CAST() Function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7252
diff
changeset
|
1419 |
|
7257
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7256
diff
changeset
|
1420 |
def test_regexp(self): |
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7256
diff
changeset
|
1421 |
self._check("Any X WHERE X login REGEXP '[0-9].*'", |
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7256
diff
changeset
|
1422 |
'''SELECT _X.cw_eid |
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7256
diff
changeset
|
1423 |
FROM cw_CWUser AS _X |
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7256
diff
changeset
|
1424 |
WHERE _X.cw_login ~ [0-9].* |
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7256
diff
changeset
|
1425 |
''') |
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7256
diff
changeset
|
1426 |
|
0 | 1427 |
def test_parser_parse(self): |
1428 |
for t in self._parse(PARSER): |
|
1429 |
yield t |
|
1787 | 1430 |
|
0 | 1431 |
def test_basic_parse(self): |
7108
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1432 |
for t in self._parse(BASIC + BASIC_WITH_LIMIT): |
0 | 1433 |
yield t |
1434 |
||
1435 |
def test_advanced_parse(self): |
|
7108
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1436 |
for t in self._parse(ADVANCED + ADVANCED_WITH_LIMIT_OR_ORDERBY + ADVANCED_WITH_GROUP_CONCAT): |
0 | 1437 |
yield t |
1438 |
||
1439 |
def test_outer_join_parse(self): |
|
1440 |
for t in self._parse(OUTER_JOIN): |
|
1441 |
yield t |
|
1442 |
||
1443 |
def test_virtual_vars_parse(self): |
|
1444 |
for t in self._parse(VIRTUAL_VARS): |
|
1445 |
yield t |
|
1446 |
||
1447 |
def test_multiple_sel_parse(self): |
|
1448 |
for t in self._parse(MULTIPLE_SEL): |
|
1449 |
yield t |
|
1787 | 1450 |
|
0 | 1451 |
def test_functions(self): |
1452 |
for t in self._parse(FUNCS): |
|
1453 |
yield t |
|
1787 | 1454 |
|
0 | 1455 |
def test_negation(self): |
1456 |
for t in self._parse(NEGATIONS): |
|
1457 |
yield t |
|
1787 | 1458 |
|
438 | 1459 |
def test_intersection(self): |
1460 |
for t in self._parse(INTERSECT): |
|
1461 |
yield t |
|
0 | 1462 |
|
1463 |
def test_union(self): |
|
1464 |
for t in self._parse(( |
|
1465 |
('(Any N ORDERBY 1 WHERE X name N, X is State)' |
|
1466 |
' UNION ' |
|
1467 |
'(Any NN ORDERBY 1 WHERE XX name NN, XX is Transition)', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1468 |
'''(SELECT _X.cw_name |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1469 |
FROM cw_State AS _X |
0 | 1470 |
ORDER BY 1) |
1471 |
UNION ALL |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1472 |
(SELECT _XX.cw_name |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1473 |
FROM cw_Transition AS _XX |
0 | 1474 |
ORDER BY 1)'''), |
1475 |
)): |
|
1476 |
yield t |
|
1787 | 1477 |
|
0 | 1478 |
def test_subquery(self): |
1479 |
for t in self._parse(( |
|
1480 |
||
1481 |
('Any N ORDERBY 1 WITH N BEING ' |
|
1482 |
'((Any N WHERE X name N, X is State)' |
|
1483 |
' UNION ' |
|
1484 |
'(Any NN WHERE XX name NN, XX is Transition))', |
|
1485 |
'''SELECT _T0.C0 |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1486 |
FROM ((SELECT _X.cw_name AS C0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1487 |
FROM cw_State AS _X) |
0 | 1488 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1489 |
(SELECT _XX.cw_name AS C0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1490 |
FROM cw_Transition AS _XX)) AS _T0 |
0 | 1491 |
ORDER BY 1'''), |
1787 | 1492 |
|
0 | 1493 |
('Any N,NX ORDERBY NX WITH N,NX BEING ' |
1494 |
'((Any N,COUNT(X) GROUPBY N WHERE X name N, X is State HAVING COUNT(X)>1)' |
|
1495 |
' UNION ' |
|
1496 |
'(Any N,COUNT(X) GROUPBY N WHERE X name N, X is Transition HAVING COUNT(X)>1))', |
|
1497 |
'''SELECT _T0.C0, _T0.C1 |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1498 |
FROM ((SELECT _X.cw_name AS C0, COUNT(_X.cw_eid) AS C1 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1499 |
FROM cw_State AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1500 |
GROUP BY _X.cw_name |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1501 |
HAVING COUNT(_X.cw_eid)>1) |
0 | 1502 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1503 |
(SELECT _X.cw_name AS C0, COUNT(_X.cw_eid) AS C1 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1504 |
FROM cw_Transition AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1505 |
GROUP BY _X.cw_name |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1506 |
HAVING COUNT(_X.cw_eid)>1)) AS _T0 |
1787 | 1507 |
ORDER BY 2'''), |
0 | 1508 |
|
1509 |
('Any N,COUNT(X) GROUPBY N HAVING COUNT(X)>1 ' |
|
1510 |
'WITH X, N BEING ((Any X, N WHERE X name N, X is State) UNION ' |
|
1511 |
' (Any X, N WHERE X name N, X is Transition))', |
|
1512 |
'''SELECT _T0.C1, COUNT(_T0.C0) |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1513 |
FROM ((SELECT _X.cw_eid AS C0, _X.cw_name AS C1 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1514 |
FROM cw_State AS _X) |
0 | 1515 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1516 |
(SELECT _X.cw_eid AS C0, _X.cw_name AS C1 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1517 |
FROM cw_Transition AS _X)) AS _T0 |
0 | 1518 |
GROUP BY _T0.C1 |
1519 |
HAVING COUNT(_T0.C0)>1'''), |
|
1520 |
||
1521 |
('Any ETN,COUNT(X) GROUPBY ETN WHERE X is ET, ET name ETN ' |
|
1522 |
'WITH X BEING ((Any X WHERE X is Societe) UNION (Any X WHERE X is Affaire, (EXISTS(X owned_by 1)) OR ((EXISTS(D concerne B?, B owned_by 1, X identity D, B is Note)) OR (EXISTS(F concerne E?, E owned_by 1, E is Societe, X identity F)))))', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1523 |
'''SELECT _ET.cw_name, COUNT(_T0.C0) |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1524 |
FROM ((SELECT _X.cw_eid AS C0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1525 |
FROM cw_Societe AS _X) |
0 | 1526 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1527 |
(SELECT _X.cw_eid AS C0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1528 |
FROM cw_Affaire AS _X |
7193
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
1529 |
WHERE ((EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by0 WHERE rel_owned_by0.eid_from=_X.cw_eid AND rel_owned_by0.eid_to=1)) OR (((EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by2, cw_Affaire AS _D LEFT OUTER JOIN concerne_relation AS rel_concerne1 ON (rel_concerne1.eid_from=_D.cw_eid) LEFT OUTER JOIN cw_Note AS _B ON (rel_concerne1.eid_to=_B.cw_eid) WHERE rel_owned_by2.eid_from=_B.cw_eid AND rel_owned_by2.eid_to=1 AND _X.cw_eid=_D.cw_eid)) OR (EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by4, cw_Affaire AS _F LEFT OUTER JOIN concerne_relation AS rel_concerne3 ON (rel_concerne3.eid_from=_F.cw_eid) LEFT OUTER JOIN cw_Societe AS _E ON (rel_concerne3.eid_to=_E.cw_eid) WHERE rel_owned_by4.eid_from=_E.cw_eid AND rel_owned_by4.eid_to=1 AND _X.cw_eid=_F.cw_eid))))))) AS _T0, cw_CWEType AS _ET, is_relation AS rel_is0 |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1530 |
WHERE rel_is0.eid_from=_T0.C0 AND rel_is0.eid_to=_ET.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1531 |
GROUP BY _ET.cw_name'''), |
7472
9833c09460f1
[rql2sql] fix missing sql restriction w/ attribute restriction where value comes from a subquery
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7421
diff
changeset
|
1532 |
|
9833c09460f1
[rql2sql] fix missing sql restriction w/ attribute restriction where value comes from a subquery
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7421
diff
changeset
|
1533 |
('Any A WHERE A ordernum O, A is CWAttribute WITH O BEING (Any MAX(O) WHERE A ordernum O, A is CWAttribute)', |
9833c09460f1
[rql2sql] fix missing sql restriction w/ attribute restriction where value comes from a subquery
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7421
diff
changeset
|
1534 |
'''SELECT _A.cw_eid |
9833c09460f1
[rql2sql] fix missing sql restriction w/ attribute restriction where value comes from a subquery
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7421
diff
changeset
|
1535 |
FROM (SELECT MAX(_A.cw_ordernum) AS C0 |
9833c09460f1
[rql2sql] fix missing sql restriction w/ attribute restriction where value comes from a subquery
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7421
diff
changeset
|
1536 |
FROM cw_CWAttribute AS _A) AS _T0, cw_CWAttribute AS _A |
9833c09460f1
[rql2sql] fix missing sql restriction w/ attribute restriction where value comes from a subquery
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7421
diff
changeset
|
1537 |
WHERE _A.cw_ordernum=_T0.C0'''), |
7902
2ada3052e626
[rql2sql] support for outer join on column alias (closes #1979645)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7734
diff
changeset
|
1538 |
|
2ada3052e626
[rql2sql] support for outer join on column alias (closes #1979645)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7734
diff
changeset
|
1539 |
('Any O1 HAVING O1=O2? WITH O1 BEING (Any MAX(O) WHERE A ordernum O, A is CWAttribute), O2 BEING (Any MAX(O) WHERE A ordernum O, A is CWRelation)', |
2ada3052e626
[rql2sql] support for outer join on column alias (closes #1979645)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7734
diff
changeset
|
1540 |
'''SELECT _T0.C0 |
2ada3052e626
[rql2sql] support for outer join on column alias (closes #1979645)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7734
diff
changeset
|
1541 |
FROM (SELECT MAX(_A.cw_ordernum) AS C0 |
2ada3052e626
[rql2sql] support for outer join on column alias (closes #1979645)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7734
diff
changeset
|
1542 |
FROM cw_CWAttribute AS _A) AS _T0 LEFT OUTER JOIN (SELECT MAX(_A.cw_ordernum) AS C0 |
2ada3052e626
[rql2sql] support for outer join on column alias (closes #1979645)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7734
diff
changeset
|
1543 |
FROM cw_CWRelation AS _A) AS _T1 ON (_T0.C0=_T1.C0)'''), |
0 | 1544 |
)): |
1545 |
yield t |
|
1546 |
||
1787 | 1547 |
|
0 | 1548 |
def test_subquery_error(self): |
1549 |
rql = ('Any N WHERE X name N WITH X BEING ' |
|
1550 |
'((Any X WHERE X is State)' |
|
1551 |
' UNION ' |
|
1552 |
' (Any X WHERE X is Transition))') |
|
1553 |
rqlst = self._prepare(rql) |
|
1554 |
self.assertRaises(BadRQLQuery, self.o.generate, rqlst) |
|
1787 | 1555 |
|
4467
0e73d299730a
fix long-waiting symetric typo: should be spelled symmetric. Add auto database migration on schema deserialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4290
diff
changeset
|
1556 |
def test_symmetric(self): |
7108
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1557 |
for t in self._parse(SYMMETRIC + SYMMETRIC_WITH_LIMIT): |
0 | 1558 |
yield t |
1787 | 1559 |
|
0 | 1560 |
def test_inline(self): |
1561 |
for t in self._parse(INLINE): |
|
1562 |
yield t |
|
1787 | 1563 |
|
0 | 1564 |
def test_has_text(self): |
1565 |
for t in self._parse(( |
|
1566 |
('Any X WHERE X has_text "toto tata"', |
|
1567 |
"""SELECT appears0.uid |
|
1568 |
FROM appears AS appears0 |
|
1569 |
WHERE appears0.words @@ to_tsquery('default', 'toto&tata')"""), |
|
1787 | 1570 |
|
0 | 1571 |
('Personne X WHERE X has_text "toto tata"', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1572 |
"""SELECT _X.eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1573 |
FROM appears AS appears0, entities AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1574 |
WHERE appears0.words @@ to_tsquery('default', 'toto&tata') AND appears0.uid=_X.eid AND _X.type='Personne'"""), |
1787 | 1575 |
|
0 | 1576 |
('Personne X WHERE X has_text %(text)s', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1577 |
"""SELECT _X.eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1578 |
FROM appears AS appears0, entities AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1579 |
WHERE appears0.words @@ to_tsquery('default', 'hip&hop&momo') AND appears0.uid=_X.eid AND _X.type='Personne'"""), |
1787 | 1580 |
|
3587 | 1581 |
('Any X WHERE X has_text "toto tata", X name "tutu", X is IN (Basket,Folder)', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1582 |
"""SELECT _X.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1583 |
FROM appears AS appears0, cw_Basket AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1584 |
WHERE appears0.words @@ to_tsquery('default', 'toto&tata') AND appears0.uid=_X.cw_eid AND _X.cw_name=tutu |
0 | 1585 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1586 |
SELECT _X.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1587 |
FROM appears AS appears0, cw_Folder AS _X |
5768
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1588 |
WHERE appears0.words @@ to_tsquery('default', 'toto&tata') AND appears0.uid=_X.cw_eid AND _X.cw_name=tutu"""), |
0 | 1589 |
|
1590 |
('Personne X where X has_text %(text)s, X travaille S, S has_text %(text)s', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1591 |
"""SELECT _X.eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1592 |
FROM appears AS appears0, appears AS appears2, entities AS _X, travaille_relation AS rel_travaille1 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1593 |
WHERE appears0.words @@ to_tsquery('default', 'hip&hop&momo') AND appears0.uid=_X.eid AND _X.type='Personne' AND _X.eid=rel_travaille1.eid_from AND appears2.uid=rel_travaille1.eid_to AND appears2.words @@ to_tsquery('default', 'hip&hop&momo')"""), |
5768
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1594 |
|
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1595 |
('Any X ORDERBY FTIRANK(X) DESC WHERE X has_text "toto tata"', |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1596 |
"""SELECT appears0.uid |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1597 |
FROM appears AS appears0 |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1598 |
WHERE appears0.words @@ to_tsquery('default', 'toto&tata') |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1599 |
ORDER BY ts_rank(appears0.words, to_tsquery('default', 'toto&tata'))*appears0.weight DESC"""), |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1600 |
|
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1601 |
('Personne X ORDERBY FTIRANK(X) WHERE X has_text "toto tata"', |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1602 |
"""SELECT _X.eid |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1603 |
FROM appears AS appears0, entities AS _X |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1604 |
WHERE appears0.words @@ to_tsquery('default', 'toto&tata') AND appears0.uid=_X.eid AND _X.type='Personne' |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1605 |
ORDER BY ts_rank(appears0.words, to_tsquery('default', 'toto&tata'))*appears0.weight"""), |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1606 |
|
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1607 |
('Personne X ORDERBY FTIRANK(X) WHERE X has_text %(text)s', |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1608 |
"""SELECT _X.eid |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1609 |
FROM appears AS appears0, entities AS _X |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1610 |
WHERE appears0.words @@ to_tsquery('default', 'hip&hop&momo') AND appears0.uid=_X.eid AND _X.type='Personne' |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1611 |
ORDER BY ts_rank(appears0.words, to_tsquery('default', 'hip&hop&momo'))*appears0.weight"""), |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1612 |
|
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1613 |
('Any X ORDERBY FTIRANK(X) WHERE X has_text "toto tata", X name "tutu", X is IN (Basket,Folder)', |
7587
c7c0f53062f5
[rql2sql tests] fix erroneous case (tested with psql)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7579
diff
changeset
|
1614 |
"""SELECT T1.C0 FROM (SELECT _X.cw_eid AS C0, ts_rank(appears0.words, to_tsquery('default', 'toto&tata'))*appears0.weight AS C1 |
5768
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1615 |
FROM appears AS appears0, cw_Basket AS _X |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1616 |
WHERE appears0.words @@ to_tsquery('default', 'toto&tata') AND appears0.uid=_X.cw_eid AND _X.cw_name=tutu |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1617 |
UNION ALL |
7587
c7c0f53062f5
[rql2sql tests] fix erroneous case (tested with psql)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7579
diff
changeset
|
1618 |
SELECT _X.cw_eid AS C0, ts_rank(appears0.words, to_tsquery('default', 'toto&tata'))*appears0.weight AS C1 |
5768
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1619 |
FROM appears AS appears0, cw_Folder AS _X |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1620 |
WHERE appears0.words @@ to_tsquery('default', 'toto&tata') AND appears0.uid=_X.cw_eid AND _X.cw_name=tutu |
7587
c7c0f53062f5
[rql2sql tests] fix erroneous case (tested with psql)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7579
diff
changeset
|
1621 |
ORDER BY 2) AS T1"""), |
5768
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1622 |
|
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1623 |
('Personne X ORDERBY FTIRANK(X),FTIRANK(S) WHERE X has_text %(text)s, X travaille S, S has_text %(text)s', |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1624 |
"""SELECT _X.eid |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1625 |
FROM appears AS appears0, appears AS appears2, entities AS _X, travaille_relation AS rel_travaille1 |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1626 |
WHERE appears0.words @@ to_tsquery('default', 'hip&hop&momo') AND appears0.uid=_X.eid AND _X.type='Personne' AND _X.eid=rel_travaille1.eid_from AND appears2.uid=rel_travaille1.eid_to AND appears2.words @@ to_tsquery('default', 'hip&hop&momo') |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1627 |
ORDER BY ts_rank(appears0.words, to_tsquery('default', 'hip&hop&momo'))*appears0.weight,ts_rank(appears2.words, to_tsquery('default', 'hip&hop&momo'))*appears2.weight"""), |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1628 |
|
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1629 |
|
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1630 |
('Any X, FTIRANK(X) WHERE X has_text "toto tata"', |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1631 |
"""SELECT appears0.uid, ts_rank(appears0.words, to_tsquery('default', 'toto&tata'))*appears0.weight |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1632 |
FROM appears AS appears0 |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1633 |
WHERE appears0.words @@ to_tsquery('default', 'toto&tata')"""), |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1634 |
|
6493
019ab5eb37ea
[rql2sql] properly compute has_text relation table scope
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
1635 |
|
019ab5eb37ea
[rql2sql] properly compute has_text relation table scope
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
1636 |
('Any X WHERE NOT A tags X, X has_text "pouet"', |
019ab5eb37ea
[rql2sql] properly compute has_text relation table scope
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
1637 |
'''SELECT appears1.uid |
019ab5eb37ea
[rql2sql] properly compute has_text relation table scope
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
1638 |
FROM appears AS appears1 |
019ab5eb37ea
[rql2sql] properly compute has_text relation table scope
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
1639 |
WHERE NOT (EXISTS(SELECT 1 FROM tags_relation AS rel_tags0 WHERE appears1.uid=rel_tags0.eid_to)) AND appears1.words @@ to_tsquery('default', 'pouet') |
019ab5eb37ea
[rql2sql] properly compute has_text relation table scope
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
1640 |
'''), |
019ab5eb37ea
[rql2sql] properly compute has_text relation table scope
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
1641 |
|
0 | 1642 |
)): |
1643 |
yield t |
|
1644 |
||
1645 |
||
1646 |
def test_from_clause_needed(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1647 |
queries = [("Any 1 WHERE EXISTS(T is CWGroup, T name 'managers')", |
0 | 1648 |
'''SELECT 1 |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1649 |
WHERE EXISTS(SELECT 1 FROM cw_CWGroup AS _T WHERE _T.cw_name=managers)'''), |
0 | 1650 |
('Any X,Y WHERE NOT X created_by Y, X eid 5, Y eid 6', |
1651 |
'''SELECT 5, 6 |
|
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
1652 |
WHERE NOT (EXISTS(SELECT 1 FROM created_by_relation AS rel_created_by0 WHERE rel_created_by0.eid_from=5 AND rel_created_by0.eid_to=6))'''), |
0 | 1653 |
] |
1654 |
for t in self._parse(queries): |
|
1655 |
yield t |
|
1656 |
||
1657 |
def test_ambigous_exists_no_from_clause(self): |
|
1658 |
self._check('Any COUNT(U) WHERE U eid 1, EXISTS (P owned_by U, P is IN (Note, Affaire))', |
|
1659 |
'''SELECT COUNT(1) |
|
7193
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
1660 |
WHERE EXISTS(SELECT 1 FROM cw_Affaire AS _P, owned_by_relation AS rel_owned_by0 WHERE rel_owned_by0.eid_from=_P.cw_eid AND rel_owned_by0.eid_to=1 UNION SELECT 1 FROM cw_Note AS _P, owned_by_relation AS rel_owned_by1 WHERE rel_owned_by1.eid_from=_P.cw_eid AND rel_owned_by1.eid_to=1)''') |
0 | 1661 |
|
5013
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5010
diff
changeset
|
1662 |
def test_attr_map_sqlcb(self): |
2354
9b4bac626977
ability to map attributes to something else than usual cw mapping on sql generation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2199
diff
changeset
|
1663 |
def generate_ref(gen, linkedvar, rel): |
9b4bac626977
ability to map attributes to something else than usual cw mapping on sql generation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2199
diff
changeset
|
1664 |
linkedvar.accept(gen) |
9b4bac626977
ability to map attributes to something else than usual cw mapping on sql generation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2199
diff
changeset
|
1665 |
return 'VERSION_DATA(%s)' % linkedvar._q_sql |
5013
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5010
diff
changeset
|
1666 |
self.o.attr_map['Affaire.ref'] = (generate_ref, False) |
2354
9b4bac626977
ability to map attributes to something else than usual cw mapping on sql generation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2199
diff
changeset
|
1667 |
try: |
9b4bac626977
ability to map attributes to something else than usual cw mapping on sql generation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2199
diff
changeset
|
1668 |
self._check('Any R WHERE X ref R', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1669 |
'''SELECT VERSION_DATA(_X.cw_eid) |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1670 |
FROM cw_Affaire AS _X''') |
2354
9b4bac626977
ability to map attributes to something else than usual cw mapping on sql generation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2199
diff
changeset
|
1671 |
self._check('Any X WHERE X ref 1', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1672 |
'''SELECT _X.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1673 |
FROM cw_Affaire AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1674 |
WHERE VERSION_DATA(_X.cw_eid)=1''') |
2354
9b4bac626977
ability to map attributes to something else than usual cw mapping on sql generation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2199
diff
changeset
|
1675 |
finally: |
9b4bac626977
ability to map attributes to something else than usual cw mapping on sql generation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2199
diff
changeset
|
1676 |
self.o.attr_map.clear() |
9b4bac626977
ability to map attributes to something else than usual cw mapping on sql generation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2199
diff
changeset
|
1677 |
|
5013
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5010
diff
changeset
|
1678 |
def test_attr_map_sourcecb(self): |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5010
diff
changeset
|
1679 |
cb = lambda x,y: None |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5010
diff
changeset
|
1680 |
self.o.attr_map['Affaire.ref'] = (cb, True) |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5010
diff
changeset
|
1681 |
try: |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5010
diff
changeset
|
1682 |
union = self._prepare('Any R WHERE X ref R') |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5010
diff
changeset
|
1683 |
r, nargs, cbs = self.o.generate(union, args={}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6297
diff
changeset
|
1684 |
self.assertMultiLineEqual(r.strip(), 'SELECT _X.cw_ref\nFROM cw_Affaire AS _X') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6297
diff
changeset
|
1685 |
self.assertEqual(cbs, {0: [cb]}) |
5013
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5010
diff
changeset
|
1686 |
finally: |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5010
diff
changeset
|
1687 |
self.o.attr_map.clear() |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5010
diff
changeset
|
1688 |
|
0 | 1689 |
|
5793
1faff41593df
[rql2sql] use new dbhelper.sql_concat_string function to deal with sql string concatenation. This together with lgdb 1.0.4 fixes #1055133: SQL Server support : string concatenation issue
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5582
diff
changeset
|
1690 |
def test_concat_string(self): |
1faff41593df
[rql2sql] use new dbhelper.sql_concat_string function to deal with sql string concatenation. This together with lgdb 1.0.4 fixes #1055133: SQL Server support : string concatenation issue
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5582
diff
changeset
|
1691 |
self._check('Any "A"+R WHERE X ref R', |
1faff41593df
[rql2sql] use new dbhelper.sql_concat_string function to deal with sql string concatenation. This together with lgdb 1.0.4 fixes #1055133: SQL Server support : string concatenation issue
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5582
diff
changeset
|
1692 |
'''SELECT (A || _X.cw_ref) |
1faff41593df
[rql2sql] use new dbhelper.sql_concat_string function to deal with sql string concatenation. This together with lgdb 1.0.4 fixes #1055133: SQL Server support : string concatenation issue
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5582
diff
changeset
|
1693 |
FROM cw_Affaire AS _X''') |
1faff41593df
[rql2sql] use new dbhelper.sql_concat_string function to deal with sql string concatenation. This together with lgdb 1.0.4 fixes #1055133: SQL Server support : string concatenation issue
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5582
diff
changeset
|
1694 |
|
7672
f31f9882c90f
[rql2sql] closes #1832859: fake HAVING terms w/ EXISTS terms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7651
diff
changeset
|
1695 |
def test_or_having_fake_terms_base(self): |
5887
3f55f0f10a22
[rql2sql] test and fix crash when OR in HAVING where both expresion are 'fake' having terms (eg not using aggregat function)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
1696 |
self._check('Any X WHERE X is CWUser, X creation_date D HAVING YEAR(D) = "2010" OR D = NULL', |
3f55f0f10a22
[rql2sql] test and fix crash when OR in HAVING where both expresion are 'fake' having terms (eg not using aggregat function)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
1697 |
'''SELECT _X.cw_eid |
3f55f0f10a22
[rql2sql] test and fix crash when OR in HAVING where both expresion are 'fake' having terms (eg not using aggregat function)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
1698 |
FROM cw_CWUser AS _X |
3f55f0f10a22
[rql2sql] test and fix crash when OR in HAVING where both expresion are 'fake' having terms (eg not using aggregat function)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
1699 |
WHERE ((CAST(EXTRACT(YEAR from _X.cw_creation_date) AS INTEGER)=2010) OR (_X.cw_creation_date IS NULL))''') |
3f55f0f10a22
[rql2sql] test and fix crash when OR in HAVING where both expresion are 'fake' having terms (eg not using aggregat function)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
1700 |
|
7672
f31f9882c90f
[rql2sql] closes #1832859: fake HAVING terms w/ EXISTS terms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7651
diff
changeset
|
1701 |
def test_or_having_fake_terms_exists(self): |
f31f9882c90f
[rql2sql] closes #1832859: fake HAVING terms w/ EXISTS terms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7651
diff
changeset
|
1702 |
# crash with rql <= 0.29.0 |
f31f9882c90f
[rql2sql] closes #1832859: fake HAVING terms w/ EXISTS terms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7651
diff
changeset
|
1703 |
self._check('Any X WHERE X is CWUser, EXISTS(B bookmarked_by X, B creation_date D) HAVING D=2010 OR D=NULL, D=1 OR D=NULL', |
f31f9882c90f
[rql2sql] closes #1832859: fake HAVING terms w/ EXISTS terms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7651
diff
changeset
|
1704 |
'''SELECT _X.cw_eid |
f31f9882c90f
[rql2sql] closes #1832859: fake HAVING terms w/ EXISTS terms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7651
diff
changeset
|
1705 |
FROM cw_CWUser AS _X |
f31f9882c90f
[rql2sql] closes #1832859: fake HAVING terms w/ EXISTS terms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7651
diff
changeset
|
1706 |
WHERE EXISTS(SELECT 1 FROM bookmarked_by_relation AS rel_bookmarked_by0, cw_Bookmark AS _B WHERE rel_bookmarked_by0.eid_from=_B.cw_eid AND rel_bookmarked_by0.eid_to=_X.cw_eid AND ((_B.cw_creation_date=1) OR (_B.cw_creation_date IS NULL)) AND ((_B.cw_creation_date=2010) OR (_B.cw_creation_date IS NULL)))''') |
f31f9882c90f
[rql2sql] closes #1832859: fake HAVING terms w/ EXISTS terms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7651
diff
changeset
|
1707 |
|
f31f9882c90f
[rql2sql] closes #1832859: fake HAVING terms w/ EXISTS terms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7651
diff
changeset
|
1708 |
def test_or_having_fake_terms_nocrash(self): |
f31f9882c90f
[rql2sql] closes #1832859: fake HAVING terms w/ EXISTS terms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7651
diff
changeset
|
1709 |
# crash with rql <= 0.29.0 |
f31f9882c90f
[rql2sql] closes #1832859: fake HAVING terms w/ EXISTS terms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7651
diff
changeset
|
1710 |
self._check('Any X WHERE X is CWUser, X creation_date D HAVING D=2010 OR D=NULL, D=1 OR D=NULL', |
f31f9882c90f
[rql2sql] closes #1832859: fake HAVING terms w/ EXISTS terms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7651
diff
changeset
|
1711 |
'''SELECT _X.cw_eid |
f31f9882c90f
[rql2sql] closes #1832859: fake HAVING terms w/ EXISTS terms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7651
diff
changeset
|
1712 |
FROM cw_CWUser AS _X |
f31f9882c90f
[rql2sql] closes #1832859: fake HAVING terms w/ EXISTS terms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7651
diff
changeset
|
1713 |
WHERE ((_X.cw_creation_date=1) OR (_X.cw_creation_date IS NULL)) AND ((_X.cw_creation_date=2010) OR (_X.cw_creation_date IS NULL))''') |
f31f9882c90f
[rql2sql] closes #1832859: fake HAVING terms w/ EXISTS terms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7651
diff
changeset
|
1714 |
|
6297
23c1e50ff97b
[rql] fix bug with query like 'Any 1 WHERE NOT X in_group G': tables should be kept in EXISTS() even when there are no restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6194
diff
changeset
|
1715 |
def test_not_no_where(self): |
23c1e50ff97b
[rql] fix bug with query like 'Any 1 WHERE NOT X in_group G': tables should be kept in EXISTS() even when there are no restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6194
diff
changeset
|
1716 |
# XXX will check if some in_group relation exists, that's it. |
23c1e50ff97b
[rql] fix bug with query like 'Any 1 WHERE NOT X in_group G': tables should be kept in EXISTS() even when there are no restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6194
diff
changeset
|
1717 |
# We can't actually know if we want to check if there are some |
23c1e50ff97b
[rql] fix bug with query like 'Any 1 WHERE NOT X in_group G': tables should be kept in EXISTS() even when there are no restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6194
diff
changeset
|
1718 |
# X without in_group relation, or some G without it. |
23c1e50ff97b
[rql] fix bug with query like 'Any 1 WHERE NOT X in_group G': tables should be kept in EXISTS() even when there are no restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6194
diff
changeset
|
1719 |
self._check('Any 1 WHERE NOT X in_group G, X is CWUser', |
23c1e50ff97b
[rql] fix bug with query like 'Any 1 WHERE NOT X in_group G': tables should be kept in EXISTS() even when there are no restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6194
diff
changeset
|
1720 |
'''SELECT 1 |
23c1e50ff97b
[rql] fix bug with query like 'Any 1 WHERE NOT X in_group G': tables should be kept in EXISTS() even when there are no restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6194
diff
changeset
|
1721 |
WHERE NOT (EXISTS(SELECT 1 FROM in_group_relation AS rel_in_group0))''') |
23c1e50ff97b
[rql] fix bug with query like 'Any 1 WHERE NOT X in_group G': tables should be kept in EXISTS() even when there are no restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6194
diff
changeset
|
1722 |
|
7357
5ad3154a8810
[rql2sql] fix bug avoiding outer join relation to be used as a variable principal. Closes #1659395
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7252
diff
changeset
|
1723 |
def test_nonregr_outer_join_multiple(self): |
7193
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
1724 |
self._check('Any COUNT(P1148),G GROUPBY G ' |
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
1725 |
'WHERE G owned_by D, D eid 1122, K1148 bookmarked_by P1148, ' |
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
1726 |
'K1148 eid 1148, P1148? in_group G', |
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
1727 |
'''SELECT COUNT(rel_bookmarked_by1.eid_to), _G.cw_eid |
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
1728 |
FROM owned_by_relation AS rel_owned_by0, cw_CWGroup AS _G LEFT OUTER JOIN in_group_relation AS rel_in_group2 ON (rel_in_group2.eid_to=_G.cw_eid) LEFT OUTER JOIN bookmarked_by_relation AS rel_bookmarked_by1 ON (rel_in_group2.eid_from=rel_bookmarked_by1.eid_to) |
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
1729 |
WHERE rel_owned_by0.eid_from=_G.cw_eid AND rel_owned_by0.eid_to=1122 AND rel_bookmarked_by1.eid_from=1148 |
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
1730 |
GROUP BY _G.cw_eid''' |
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
1731 |
) |
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
1732 |
|
7357
5ad3154a8810
[rql2sql] fix bug avoiding outer join relation to be used as a variable principal. Closes #1659395
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7252
diff
changeset
|
1733 |
def test_nonregr_outer_join_multiple2(self): |
7193
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
1734 |
self._check('Any COUNT(P1148),G GROUPBY G ' |
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
1735 |
'WHERE G owned_by D, D eid 1122, K1148 bookmarked_by P1148?, ' |
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
1736 |
'K1148 eid 1148, P1148? in_group G', |
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
1737 |
'''SELECT COUNT(rel_bookmarked_by1.eid_to), _G.cw_eid |
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
1738 |
FROM owned_by_relation AS rel_owned_by0, cw_CWGroup AS _G LEFT OUTER JOIN in_group_relation AS rel_in_group2 ON (rel_in_group2.eid_to=_G.cw_eid) LEFT OUTER JOIN bookmarked_by_relation AS rel_bookmarked_by1 ON (rel_bookmarked_by1.eid_from=1148 AND rel_in_group2.eid_from=rel_bookmarked_by1.eid_to) |
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
1739 |
WHERE rel_owned_by0.eid_from=_G.cw_eid AND rel_owned_by0.eid_to=1122 |
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
1740 |
GROUP BY _G.cw_eid''') |
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
1741 |
|
7579
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
1742 |
def test_groupby_orderby_insertion_dont_modify_intention(self): |
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
1743 |
self._check('Any YEAR(XECT)*100+MONTH(XECT), COUNT(X),SUM(XCE),AVG(XSCT-XECT) ' |
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
1744 |
'GROUPBY YEAR(XECT),MONTH(XECT) ORDERBY 1 ' |
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
1745 |
'WHERE X creation_date XSCT, X modification_date XECT, ' |
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
1746 |
'X ordernum XCE, X is CWAttribute', |
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
1747 |
'''SELECT ((CAST(EXTRACT(YEAR from _X.cw_modification_date) AS INTEGER) * 100) + CAST(EXTRACT(MONTH from _X.cw_modification_date) AS INTEGER)), COUNT(_X.cw_eid), SUM(_X.cw_ordernum), AVG((_X.cw_creation_date - _X.cw_modification_date)) |
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
1748 |
FROM cw_CWAttribute AS _X |
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
1749 |
GROUP BY CAST(EXTRACT(YEAR from _X.cw_modification_date) AS INTEGER),CAST(EXTRACT(MONTH from _X.cw_modification_date) AS INTEGER) |
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
1750 |
ORDER BY 1'''), |
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
1751 |
|
8245
d53762ae5961
[rql2sql] correctly handle modulo operator (closes #2192457)
Julien Cristau <julien.cristau@logilab.fr>
parents:
8217
diff
changeset
|
1752 |
def test_modulo(self): |
d53762ae5961
[rql2sql] correctly handle modulo operator (closes #2192457)
Julien Cristau <julien.cristau@logilab.fr>
parents:
8217
diff
changeset
|
1753 |
self._check('Any 5 % 2', '''SELECT (5 % 2)''') |
d53762ae5961
[rql2sql] correctly handle modulo operator (closes #2192457)
Julien Cristau <julien.cristau@logilab.fr>
parents:
8217
diff
changeset
|
1754 |
|
7193
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
1755 |
|
7108
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1756 |
class SqlServer2005SQLGeneratorTC(PostgresSQLGeneratorTC): |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1757 |
backend = 'sqlserver2005' |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1758 |
def _norm_sql(self, sql): |
8217
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
1759 |
return sql.strip().replace(' SUBSTR', ' SUBSTRING').replace(' || ', ' + ').replace(' ILIKE ', ' LIKE ').replace('TRUE', '1').replace('FALSE', '0') |
7108
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1760 |
|
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1761 |
def test_has_text(self): |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1762 |
for t in self._parse(HAS_TEXT_LG_INDEXER): |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1763 |
yield t |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1764 |
|
7257
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7256
diff
changeset
|
1765 |
def test_regexp(self): |
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7256
diff
changeset
|
1766 |
self.skipTest('regexp-based pattern matching not implemented in sqlserver') |
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7256
diff
changeset
|
1767 |
|
7672
f31f9882c90f
[rql2sql] closes #1832859: fake HAVING terms w/ EXISTS terms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7651
diff
changeset
|
1768 |
def test_or_having_fake_terms_base(self): |
7108
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1769 |
self._check('Any X WHERE X is CWUser, X creation_date D HAVING YEAR(D) = "2010" OR D = NULL', |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1770 |
'''SELECT _X.cw_eid |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1771 |
FROM cw_CWUser AS _X |
7905
32ad1c29e477
[test, sqlserver] update test for fixed impl. of date extraction function for sqlserver (lgdb 1.7)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7904
diff
changeset
|
1772 |
WHERE ((DATEPART(YEAR, _X.cw_creation_date)=2010) OR (_X.cw_creation_date IS NULL))''') |
7108
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1773 |
|
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1774 |
def test_date_extraction(self): |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1775 |
self._check("Any MONTH(D) WHERE P is Personne, P creation_date D", |
7904
f41bb38dda7c
[rql, sql] support for weekday function introduced in lgdp 1.7 (closes #1979717)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7902
diff
changeset
|
1776 |
'''SELECT DATEPART(MONTH, _P.cw_creation_date) |
f41bb38dda7c
[rql, sql] support for weekday function introduced in lgdp 1.7 (closes #1979717)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7902
diff
changeset
|
1777 |
FROM cw_Personne AS _P''') |
f41bb38dda7c
[rql, sql] support for weekday function introduced in lgdp 1.7 (closes #1979717)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7902
diff
changeset
|
1778 |
|
f41bb38dda7c
[rql, sql] support for weekday function introduced in lgdp 1.7 (closes #1979717)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7902
diff
changeset
|
1779 |
def test_weekday_extraction(self): |
f41bb38dda7c
[rql, sql] support for weekday function introduced in lgdp 1.7 (closes #1979717)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7902
diff
changeset
|
1780 |
self._check("Any WEEKDAY(D) WHERE P is Personne, P creation_date D", |
f41bb38dda7c
[rql, sql] support for weekday function introduced in lgdp 1.7 (closes #1979717)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7902
diff
changeset
|
1781 |
'''SELECT DATEPART(WEEKDAY, _P.cw_creation_date) |
7108
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1782 |
FROM cw_Personne AS _P''') |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1783 |
|
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1784 |
def test_symmetric(self): |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1785 |
for t in self._parse(SYMMETRIC): |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1786 |
yield t |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1787 |
|
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1788 |
def test_basic_parse(self): |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1789 |
for t in self._parse(BASIC):# + BASIC_WITH_LIMIT): |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1790 |
yield t |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1791 |
|
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1792 |
def test_advanced_parse(self): |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1793 |
for t in self._parse(ADVANCED):# + ADVANCED_WITH_LIMIT_OR_ORDERBY): |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1794 |
yield t |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1795 |
|
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1796 |
def test_limit_offset(self): |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1797 |
WITH_LIMIT = [ |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1798 |
("Personne P LIMIT 20 OFFSET 10", |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1799 |
'''WITH orderedrows AS ( |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1800 |
SELECT |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1801 |
_L01 |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1802 |
, ROW_NUMBER() OVER (ORDER BY _L01) AS __RowNumber |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1803 |
FROM ( |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1804 |
SELECT _P.cw_eid AS _L01 FROM cw_Personne AS _P |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1805 |
) AS _SQ1 ) |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1806 |
SELECT |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1807 |
_L01 |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1808 |
FROM orderedrows WHERE |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1809 |
__RowNumber <= 30 AND __RowNumber > 10 |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1810 |
'''), |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1811 |
|
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1812 |
('Any COUNT(S),CS GROUPBY CS ORDERBY 1 DESC LIMIT 10 WHERE S is Affaire, C is Societe, S concerne C, C nom CS, (EXISTS(S owned_by 1)) OR (EXISTS(S documented_by N, N title "published"))', |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1813 |
'''WITH orderedrows AS ( |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1814 |
SELECT |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1815 |
_L01, _L02 |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1816 |
, ROW_NUMBER() OVER (ORDER BY _L01 DESC) AS __RowNumber |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1817 |
FROM ( |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1818 |
SELECT COUNT(rel_concerne0.eid_from) AS _L01, _C.cw_nom AS _L02 FROM concerne_relation AS rel_concerne0, cw_Societe AS _C |
7193
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
1819 |
WHERE rel_concerne0.eid_to=_C.cw_eid AND ((EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by1 WHERE rel_concerne0.eid_from=rel_owned_by1.eid_from AND rel_owned_by1.eid_to=1)) OR (EXISTS(SELECT 1 FROM cw_Card AS _N, documented_by_relation AS rel_documented_by2 WHERE rel_concerne0.eid_from=rel_documented_by2.eid_from AND rel_documented_by2.eid_to=_N.cw_eid AND _N.cw_title=published))) |
7108
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1820 |
GROUP BY _C.cw_nom |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1821 |
) AS _SQ1 ) |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1822 |
SELECT |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1823 |
_L01, _L02 |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1824 |
FROM orderedrows WHERE |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1825 |
__RowNumber <= 10 |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1826 |
'''), |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1827 |
|
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1828 |
('DISTINCT Any MAX(X)+MIN(LENGTH(D)), N GROUPBY N ORDERBY 2, DF WHERE X data_name N, X data D, X data_format DF;', |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1829 |
'''SELECT T1.C0,T1.C1 FROM (SELECT DISTINCT (MAX(_X.cw_eid) + MIN(LENGTH(_X.cw_data))) AS C0, _X.cw_data_name AS C1, _X.cw_data_format AS C2 |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1830 |
FROM cw_File AS _X |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1831 |
GROUP BY _X.cw_data_name,_X.cw_data_format) AS T1 |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1832 |
ORDER BY T1.C1,T1.C2 |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1833 |
'''), |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1834 |
|
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1835 |
|
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1836 |
('DISTINCT Any X ORDERBY Y WHERE B bookmarked_by X, X login Y', |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1837 |
'''SELECT T1.C0 FROM (SELECT DISTINCT _X.cw_eid AS C0, _X.cw_login AS C1 |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1838 |
FROM bookmarked_by_relation AS rel_bookmarked_by0, cw_CWUser AS _X |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1839 |
WHERE rel_bookmarked_by0.eid_to=_X.cw_eid) AS T1 |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1840 |
ORDER BY T1.C1 |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1841 |
'''), |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1842 |
|
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1843 |
('DISTINCT Any X ORDERBY SN WHERE X in_state S, S name SN', |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1844 |
'''SELECT T1.C0 FROM (SELECT DISTINCT _X.cw_eid AS C0, _S.cw_name AS C1 |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1845 |
FROM cw_Affaire AS _X, cw_State AS _S |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1846 |
WHERE _X.cw_in_state=_S.cw_eid |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1847 |
UNION |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1848 |
SELECT DISTINCT _X.cw_eid AS C0, _S.cw_name AS C1 |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1849 |
FROM cw_CWUser AS _X, cw_State AS _S |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1850 |
WHERE _X.cw_in_state=_S.cw_eid |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1851 |
UNION |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1852 |
SELECT DISTINCT _X.cw_eid AS C0, _S.cw_name AS C1 |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1853 |
FROM cw_Note AS _X, cw_State AS _S |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1854 |
WHERE _X.cw_in_state=_S.cw_eid) AS T1 |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1855 |
ORDER BY T1.C1'''), |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1856 |
|
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1857 |
('Any O,AA,AB,AC ORDERBY AC DESC ' |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1858 |
'WHERE NOT S use_email O, S eid 1, O is EmailAddress, O address AA, O alias AB, O modification_date AC, ' |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1859 |
'EXISTS(A use_email O, EXISTS(A identity B, NOT B in_group D, D name "guests", D is CWGroup), A is CWUser), B eid 2', |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1860 |
''' |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1861 |
SELECT _O.cw_eid, _O.cw_address, _O.cw_alias, _O.cw_modification_date |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1862 |
FROM cw_EmailAddress AS _O |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1863 |
WHERE NOT (EXISTS(SELECT 1 FROM use_email_relation AS rel_use_email0 WHERE rel_use_email0.eid_from=1 AND rel_use_email0.eid_to=_O.cw_eid)) AND EXISTS(SELECT 1 FROM use_email_relation AS rel_use_email1 WHERE rel_use_email1.eid_to=_O.cw_eid AND EXISTS(SELECT 1 FROM cw_CWGroup AS _D WHERE rel_use_email1.eid_from=2 AND NOT (EXISTS(SELECT 1 FROM in_group_relation AS rel_in_group2 WHERE rel_in_group2.eid_from=2 AND rel_in_group2.eid_to=_D.cw_eid)) AND _D.cw_name=guests)) |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1864 |
ORDER BY 4 DESC'''), |
7596
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1865 |
|
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1866 |
("Any P ORDERBY N LIMIT 1 WHERE P is Personne, P travaille S, S eid %(eid)s, P nom N, P nom %(text)s", |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1867 |
'''WITH orderedrows AS ( |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1868 |
SELECT |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1869 |
_L01 |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1870 |
, ROW_NUMBER() OVER (ORDER BY _L01) AS __RowNumber |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1871 |
FROM ( |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1872 |
SELECT _P.cw_eid AS _L01 FROM cw_Personne AS _P, travaille_relation AS rel_travaille0 |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1873 |
WHERE rel_travaille0.eid_from=_P.cw_eid AND rel_travaille0.eid_to=12345 AND _P.cw_nom=hip hop momo |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1874 |
) AS _SQ1 ) |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1875 |
SELECT |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1876 |
_L01 |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1877 |
FROM orderedrows WHERE |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1878 |
__RowNumber <= 1'''), |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1879 |
|
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1880 |
("Any P ORDERBY N LIMIT 1 WHERE P is Personne, P nom N", |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1881 |
'''WITH orderedrows AS ( |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1882 |
SELECT |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1883 |
_L01 |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1884 |
, ROW_NUMBER() OVER (ORDER BY _L01) AS __RowNumber |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1885 |
FROM ( |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1886 |
SELECT _P.cw_eid AS _L01 FROM cw_Personne AS _P |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1887 |
) AS _SQ1 ) |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1888 |
SELECT |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1889 |
_L01 |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1890 |
FROM orderedrows WHERE |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1891 |
__RowNumber <= 1 |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1892 |
'''), |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1893 |
|
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1894 |
("Any PN, N, P ORDERBY N LIMIT 1 WHERE P is Personne, P nom N, P prenom PN", |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1895 |
'''WITH orderedrows AS ( |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1896 |
SELECT |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1897 |
_L01, _L02, _L03 |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1898 |
, ROW_NUMBER() OVER (ORDER BY _L02) AS __RowNumber |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1899 |
FROM ( |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1900 |
SELECT _P.cw_prenom AS _L01, _P.cw_nom AS _L02, _P.cw_eid AS _L03 FROM cw_Personne AS _P |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1901 |
) AS _SQ1 ) |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1902 |
SELECT |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1903 |
_L01, _L02, _L03 |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1904 |
FROM orderedrows WHERE |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1905 |
__RowNumber <= 1 |
f3cdf1694c92
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7587
diff
changeset
|
1906 |
'''), |
7108
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1907 |
] |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1908 |
for t in self._parse(WITH_LIMIT):# + ADVANCED_WITH_LIMIT_OR_ORDERBY): |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1909 |
yield t |
bcdf22734059
Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7043
diff
changeset
|
1910 |
|
7256
ccd44caeb936
[rql] support CAST() Function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7252
diff
changeset
|
1911 |
def test_cast(self): |
ccd44caeb936
[rql] support CAST() Function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7252
diff
changeset
|
1912 |
self._check("Any CAST(String, P) WHERE P is Personne", |
ccd44caeb936
[rql] support CAST() Function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7252
diff
changeset
|
1913 |
'''SELECT CAST(_P.cw_eid AS nvarchar(max)) |
ccd44caeb936
[rql] support CAST() Function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7252
diff
changeset
|
1914 |
FROM cw_Personne AS _P''') |
6297
23c1e50ff97b
[rql] fix bug with query like 'Any 1 WHERE NOT X in_group G': tables should be kept in EXISTS() even when there are no restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6194
diff
changeset
|
1915 |
|
7579
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
1916 |
def test_groupby_orderby_insertion_dont_modify_intention(self): |
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
1917 |
self._check('Any YEAR(XECT)*100+MONTH(XECT), COUNT(X),SUM(XCE),AVG(XSCT-XECT) ' |
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
1918 |
'GROUPBY YEAR(XECT),MONTH(XECT) ORDERBY 1 ' |
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
1919 |
'WHERE X creation_date XSCT, X modification_date XECT, ' |
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
1920 |
'X ordernum XCE, X is CWAttribute', |
7905
32ad1c29e477
[test, sqlserver] update test for fixed impl. of date extraction function for sqlserver (lgdb 1.7)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7904
diff
changeset
|
1921 |
'''SELECT ((DATEPART(YEAR, _X.cw_modification_date) * 100) + DATEPART(MONTH, _X.cw_modification_date)), COUNT(_X.cw_eid), SUM(_X.cw_ordernum), AVG((_X.cw_creation_date - _X.cw_modification_date)) |
7579
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
1922 |
FROM cw_CWAttribute AS _X |
7905
32ad1c29e477
[test, sqlserver] update test for fixed impl. of date extraction function for sqlserver (lgdb 1.7)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7904
diff
changeset
|
1923 |
GROUP BY DATEPART(YEAR, _X.cw_modification_date),DATEPART(MONTH, _X.cw_modification_date) |
8217
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
1924 |
ORDER BY 1''') |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
1925 |
|
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
1926 |
def test_today(self): |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
1927 |
for t in self._parse([("Any X WHERE X creation_date TODAY, X is Affaire", |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
1928 |
'''SELECT _X.cw_eid |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
1929 |
FROM cw_Affaire AS _X |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
1930 |
WHERE DATE(_X.cw_creation_date)=CURRENT_DATE'''), |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
1931 |
|
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
1932 |
("Personne P where not P datenaiss TODAY", |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
1933 |
'''SELECT _P.cw_eid |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
1934 |
FROM cw_Personne AS _P |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
1935 |
WHERE NOT (DATE(_P.cw_datenaiss)=CURRENT_DATE)'''), |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
1936 |
]): |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
1937 |
yield t |
6297
23c1e50ff97b
[rql] fix bug with query like 'Any 1 WHERE NOT X in_group G': tables should be kept in EXISTS() even when there are no restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6194
diff
changeset
|
1938 |
|
5793
1faff41593df
[rql2sql] use new dbhelper.sql_concat_string function to deal with sql string concatenation. This together with lgdb 1.0.4 fixes #1055133: SQL Server support : string concatenation issue
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5582
diff
changeset
|
1939 |
|
0 | 1940 |
class SqliteSQLGeneratorTC(PostgresSQLGeneratorTC): |
5768
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
1941 |
backend = 'sqlite' |
0 | 1942 |
|
1943 |
def _norm_sql(self, sql): |
|
7705
2a1f078ebdcd
[sql test] lgdb > 1.6 use int for bool with sqlite backend
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7672
diff
changeset
|
1944 |
return sql.strip().replace(' ILIKE ', ' LIKE ').replace('TRUE', '1').replace('FALSE', '0') |
0 | 1945 |
|
4831
c5aec27c1bf7
[repo] use logilab.db instead of lgc.adbh/lgc.db/lgc.sqlgen/indexer, test new date extranction functions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
1946 |
def test_date_extraction(self): |
c5aec27c1bf7
[repo] use logilab.db instead of lgc.adbh/lgc.db/lgc.sqlgen/indexer, test new date extranction functions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
1947 |
self._check("Any MONTH(D) WHERE P is Personne, P creation_date D", |
c5aec27c1bf7
[repo] use logilab.db instead of lgc.adbh/lgc.db/lgc.sqlgen/indexer, test new date extranction functions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
1948 |
'''SELECT MONTH(_P.cw_creation_date) |
c5aec27c1bf7
[repo] use logilab.db instead of lgc.adbh/lgc.db/lgc.sqlgen/indexer, test new date extranction functions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
1949 |
FROM cw_Personne AS _P''') |
c5aec27c1bf7
[repo] use logilab.db instead of lgc.adbh/lgc.db/lgc.sqlgen/indexer, test new date extranction functions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
1950 |
|
7904
f41bb38dda7c
[rql, sql] support for weekday function introduced in lgdp 1.7 (closes #1979717)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7902
diff
changeset
|
1951 |
def test_weekday_extraction(self): |
f41bb38dda7c
[rql, sql] support for weekday function introduced in lgdp 1.7 (closes #1979717)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7902
diff
changeset
|
1952 |
# custom impl. in cw.server.sqlutils |
f41bb38dda7c
[rql, sql] support for weekday function introduced in lgdp 1.7 (closes #1979717)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7902
diff
changeset
|
1953 |
self._check("Any WEEKDAY(D) WHERE P is Personne, P creation_date D", |
f41bb38dda7c
[rql, sql] support for weekday function introduced in lgdp 1.7 (closes #1979717)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7902
diff
changeset
|
1954 |
'''SELECT WEEKDAY(_P.cw_creation_date) |
f41bb38dda7c
[rql, sql] support for weekday function introduced in lgdp 1.7 (closes #1979717)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7902
diff
changeset
|
1955 |
FROM cw_Personne AS _P''') |
f41bb38dda7c
[rql, sql] support for weekday function introduced in lgdp 1.7 (closes #1979717)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7902
diff
changeset
|
1956 |
|
7257
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7256
diff
changeset
|
1957 |
def test_regexp(self): |
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7256
diff
changeset
|
1958 |
self._check("Any X WHERE X login REGEXP '[0-9].*'", |
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7256
diff
changeset
|
1959 |
'''SELECT _X.cw_eid |
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7256
diff
changeset
|
1960 |
FROM cw_CWUser AS _X |
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7256
diff
changeset
|
1961 |
WHERE _X.cw_login REGEXP [0-9].* |
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7256
diff
changeset
|
1962 |
''') |
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7256
diff
changeset
|
1963 |
|
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7256
diff
changeset
|
1964 |
|
0 | 1965 |
def test_union(self): |
1966 |
for t in self._parse(( |
|
1967 |
('(Any N ORDERBY 1 WHERE X name N, X is State)' |
|
1968 |
' UNION ' |
|
1969 |
'(Any NN ORDERBY 1 WHERE XX name NN, XX is Transition)', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1970 |
'''SELECT _X.cw_name |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1971 |
FROM cw_State AS _X |
0 | 1972 |
ORDER BY 1 |
1973 |
UNION ALL |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1974 |
SELECT _XX.cw_name |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1975 |
FROM cw_Transition AS _XX |
0 | 1976 |
ORDER BY 1'''), |
1977 |
)): |
|
1978 |
yield t |
|
1787 | 1979 |
|
0 | 1980 |
|
1981 |
def test_subquery(self): |
|
1982 |
# NOTE: no paren around UNION with sqlitebackend |
|
1983 |
for t in self._parse(( |
|
1984 |
||
1985 |
('Any N ORDERBY 1 WITH N BEING ' |
|
1986 |
'((Any N WHERE X name N, X is State)' |
|
1987 |
' UNION ' |
|
1988 |
'(Any NN WHERE XX name NN, XX is Transition))', |
|
1989 |
'''SELECT _T0.C0 |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1990 |
FROM (SELECT _X.cw_name AS C0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1991 |
FROM cw_State AS _X |
0 | 1992 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1993 |
SELECT _XX.cw_name AS C0 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
1994 |
FROM cw_Transition AS _XX) AS _T0 |
0 | 1995 |
ORDER BY 1'''), |
1787 | 1996 |
|
0 | 1997 |
('Any N,NX ORDERBY NX WITH N,NX BEING ' |
1998 |
'((Any N,COUNT(X) GROUPBY N WHERE X name N, X is State HAVING COUNT(X)>1)' |
|
1999 |
' UNION ' |
|
2000 |
'(Any N,COUNT(X) GROUPBY N WHERE X name N, X is Transition HAVING COUNT(X)>1))', |
|
2001 |
'''SELECT _T0.C0, _T0.C1 |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
2002 |
FROM (SELECT _X.cw_name AS C0, COUNT(_X.cw_eid) AS C1 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
2003 |
FROM cw_State AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
2004 |
GROUP BY _X.cw_name |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
2005 |
HAVING COUNT(_X.cw_eid)>1 |
0 | 2006 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
2007 |
SELECT _X.cw_name AS C0, COUNT(_X.cw_eid) AS C1 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
2008 |
FROM cw_Transition AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
2009 |
GROUP BY _X.cw_name |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
2010 |
HAVING COUNT(_X.cw_eid)>1) AS _T0 |
1787 | 2011 |
ORDER BY 2'''), |
0 | 2012 |
|
2013 |
('Any N,COUNT(X) GROUPBY N HAVING COUNT(X)>1 ' |
|
2014 |
'WITH X, N BEING ((Any X, N WHERE X name N, X is State) UNION ' |
|
2015 |
' (Any X, N WHERE X name N, X is Transition))', |
|
2016 |
'''SELECT _T0.C1, COUNT(_T0.C0) |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
2017 |
FROM (SELECT _X.cw_eid AS C0, _X.cw_name AS C1 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
2018 |
FROM cw_State AS _X |
0 | 2019 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
2020 |
SELECT _X.cw_eid AS C0, _X.cw_name AS C1 |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
2021 |
FROM cw_Transition AS _X) AS _T0 |
0 | 2022 |
GROUP BY _T0.C1 |
2023 |
HAVING COUNT(_T0.C0)>1'''), |
|
2024 |
)): |
|
2025 |
yield t |
|
1787 | 2026 |
|
0 | 2027 |
def test_has_text(self): |
2028 |
for t in self._parse(( |
|
2029 |
('Any X WHERE X has_text "toto tata"', |
|
4836
3e3c4917e94e
[sql generation] fti_need_distinct quere was not anymore used, potentially causing duplicates on has_text queries with sqlite backend
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
2030 |
"""SELECT DISTINCT appears0.uid |
0 | 2031 |
FROM appears AS appears0 |
2032 |
WHERE appears0.word_id IN (SELECT word_id FROM word WHERE word in ('toto', 'tata'))"""), |
|
1787 | 2033 |
|
0 | 2034 |
('Any X WHERE X has_text %(text)s', |
4836
3e3c4917e94e
[sql generation] fti_need_distinct quere was not anymore used, potentially causing duplicates on has_text queries with sqlite backend
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
2035 |
"""SELECT DISTINCT appears0.uid |
0 | 2036 |
FROM appears AS appears0 |
2037 |
WHERE appears0.word_id IN (SELECT word_id FROM word WHERE word in ('hip', 'hop', 'momo'))"""), |
|
1787 | 2038 |
|
0 | 2039 |
('Personne X WHERE X has_text "toto tata"', |
4836
3e3c4917e94e
[sql generation] fti_need_distinct quere was not anymore used, potentially causing duplicates on has_text queries with sqlite backend
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
2040 |
"""SELECT DISTINCT _X.eid |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
2041 |
FROM appears AS appears0, entities AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
2042 |
WHERE appears0.word_id IN (SELECT word_id FROM word WHERE word in ('toto', 'tata')) AND appears0.uid=_X.eid AND _X.type='Personne'"""), |
1787 | 2043 |
|
3587 | 2044 |
('Any X WHERE X has_text "toto tata", X name "tutu", X is IN (Basket,Folder)', |
4836
3e3c4917e94e
[sql generation] fti_need_distinct quere was not anymore used, potentially causing duplicates on has_text queries with sqlite backend
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
2045 |
"""SELECT DISTINCT _X.cw_eid |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
2046 |
FROM appears AS appears0, cw_Basket AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
2047 |
WHERE appears0.word_id IN (SELECT word_id FROM word WHERE word in ('toto', 'tata')) AND appears0.uid=_X.cw_eid AND _X.cw_name=tutu |
4836
3e3c4917e94e
[sql generation] fti_need_distinct quere was not anymore used, potentially causing duplicates on has_text queries with sqlite backend
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
2048 |
UNION |
3e3c4917e94e
[sql generation] fti_need_distinct quere was not anymore used, potentially causing duplicates on has_text queries with sqlite backend
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
2049 |
SELECT DISTINCT _X.cw_eid |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
2050 |
FROM appears AS appears0, cw_Folder AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
2051 |
WHERE appears0.word_id IN (SELECT word_id FROM word WHERE word in ('toto', 'tata')) AND appears0.uid=_X.cw_eid AND _X.cw_name=tutu |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2916
diff
changeset
|
2052 |
"""), |
5768
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
2053 |
|
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
2054 |
('Any X ORDERBY FTIRANK(X) WHERE X has_text "toto tata"', |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
2055 |
"""SELECT DISTINCT appears0.uid |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
2056 |
FROM appears AS appears0 |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
2057 |
WHERE appears0.word_id IN (SELECT word_id FROM word WHERE word in ('toto', 'tata'))"""), |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
2058 |
|
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
2059 |
('Any X ORDERBY FTIRANK(X) WHERE X has_text "toto tata", X name "tutu", X is IN (Basket,Folder)', |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
2060 |
"""SELECT DISTINCT _X.cw_eid |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
2061 |
FROM appears AS appears0, cw_Basket AS _X |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
2062 |
WHERE appears0.word_id IN (SELECT word_id FROM word WHERE word in ('toto', 'tata')) AND appears0.uid=_X.cw_eid AND _X.cw_name=tutu |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
2063 |
UNION |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
2064 |
SELECT DISTINCT _X.cw_eid |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
2065 |
FROM appears AS appears0, cw_Folder AS _X |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
2066 |
WHERE appears0.word_id IN (SELECT word_id FROM word WHERE word in ('toto', 'tata')) AND appears0.uid=_X.cw_eid AND _X.cw_name=tutu |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
2067 |
"""), |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
2068 |
|
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
2069 |
('Any X, FTIRANK(X) WHERE X has_text "toto tata"', |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
2070 |
"""SELECT DISTINCT appears0.uid, 1.0 |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
2071 |
FROM appears AS appears0 |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
2072 |
WHERE appears0.word_id IN (SELECT word_id FROM word WHERE word in ('toto', 'tata'))"""), |
0 | 2073 |
)): |
2074 |
yield t |
|
2075 |
||
2076 |
||
7672
f31f9882c90f
[rql2sql] closes #1832859: fake HAVING terms w/ EXISTS terms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7651
diff
changeset
|
2077 |
def test_or_having_fake_terms_base(self): |
5887
3f55f0f10a22
[rql2sql] test and fix crash when OR in HAVING where both expresion are 'fake' having terms (eg not using aggregat function)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
2078 |
self._check('Any X WHERE X is CWUser, X creation_date D HAVING YEAR(D) = "2010" OR D = NULL', |
3f55f0f10a22
[rql2sql] test and fix crash when OR in HAVING where both expresion are 'fake' having terms (eg not using aggregat function)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
2079 |
'''SELECT _X.cw_eid |
3f55f0f10a22
[rql2sql] test and fix crash when OR in HAVING where both expresion are 'fake' having terms (eg not using aggregat function)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
2080 |
FROM cw_CWUser AS _X |
3f55f0f10a22
[rql2sql] test and fix crash when OR in HAVING where both expresion are 'fake' having terms (eg not using aggregat function)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
2081 |
WHERE ((YEAR(_X.cw_creation_date)=2010) OR (_X.cw_creation_date IS NULL))''') |
3f55f0f10a22
[rql2sql] test and fix crash when OR in HAVING where both expresion are 'fake' having terms (eg not using aggregat function)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
2082 |
|
7579
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
2083 |
def test_groupby_orderby_insertion_dont_modify_intention(self): |
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
2084 |
self._check('Any YEAR(XECT)*100+MONTH(XECT), COUNT(X),SUM(XCE),AVG(XSCT-XECT) ' |
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
2085 |
'GROUPBY YEAR(XECT),MONTH(XECT) ORDERBY 1 ' |
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
2086 |
'WHERE X creation_date XSCT, X modification_date XECT, ' |
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
2087 |
'X ordernum XCE, X is CWAttribute', |
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
2088 |
'''SELECT ((YEAR(_X.cw_modification_date) * 100) + MONTH(_X.cw_modification_date)), COUNT(_X.cw_eid), SUM(_X.cw_ordernum), AVG((_X.cw_creation_date - _X.cw_modification_date)) |
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
2089 |
FROM cw_CWAttribute AS _X |
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
2090 |
GROUP BY YEAR(_X.cw_modification_date),MONTH(_X.cw_modification_date) |
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
2091 |
ORDER BY 1'''), |
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
2092 |
|
8217
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
2093 |
def test_today(self): |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
2094 |
for t in self._parse([("Any X WHERE X creation_date TODAY, X is Affaire", |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
2095 |
'''SELECT _X.cw_eid |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
2096 |
FROM cw_Affaire AS _X |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
2097 |
WHERE DATE(_X.cw_creation_date)=CURRENT_DATE'''), |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
2098 |
|
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
2099 |
("Personne P where not P datenaiss TODAY", |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
2100 |
'''SELECT _P.cw_eid |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
2101 |
FROM cw_Personne AS _P |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
2102 |
WHERE NOT (DATE(_P.cw_datenaiss)=CURRENT_DATE)'''), |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
2103 |
]): |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
2104 |
yield t |
5887
3f55f0f10a22
[rql2sql] test and fix crash when OR in HAVING where both expresion are 'fake' having terms (eg not using aggregat function)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
2105 |
|
0 | 2106 |
|
2107 |
class MySQLGenerator(PostgresSQLGeneratorTC): |
|
5768
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
2108 |
backend = 'mysql' |
0 | 2109 |
|
2110 |
def _norm_sql(self, sql): |
|
3987
f85ef29f6214
fix sql generation bug with neged inlined relation where the object is invariant and subject is only referenced by the relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3852
diff
changeset
|
2111 |
sql = sql.strip().replace(' ILIKE ', ' LIKE ').replace('TRUE', '1').replace('FALSE', '0') |
f85ef29f6214
fix sql generation bug with neged inlined relation where the object is invariant and subject is only referenced by the relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3852
diff
changeset
|
2112 |
newsql = [] |
f85ef29f6214
fix sql generation bug with neged inlined relation where the object is invariant and subject is only referenced by the relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3852
diff
changeset
|
2113 |
latest = None |
f85ef29f6214
fix sql generation bug with neged inlined relation where the object is invariant and subject is only referenced by the relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3852
diff
changeset
|
2114 |
for line in sql.splitlines(False): |
f85ef29f6214
fix sql generation bug with neged inlined relation where the object is invariant and subject is only referenced by the relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3852
diff
changeset
|
2115 |
firstword = line.split(None, 1)[0] |
f85ef29f6214
fix sql generation bug with neged inlined relation where the object is invariant and subject is only referenced by the relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3852
diff
changeset
|
2116 |
if firstword == 'WHERE' and latest == 'SELECT': |
f85ef29f6214
fix sql generation bug with neged inlined relation where the object is invariant and subject is only referenced by the relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3852
diff
changeset
|
2117 |
newsql.append('FROM (SELECT 1) AS _T') |
f85ef29f6214
fix sql generation bug with neged inlined relation where the object is invariant and subject is only referenced by the relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3852
diff
changeset
|
2118 |
newsql.append(line) |
f85ef29f6214
fix sql generation bug with neged inlined relation where the object is invariant and subject is only referenced by the relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3852
diff
changeset
|
2119 |
latest = firstword |
f85ef29f6214
fix sql generation bug with neged inlined relation where the object is invariant and subject is only referenced by the relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3852
diff
changeset
|
2120 |
return '\n'.join(newsql) |
0 | 2121 |
|
4831
c5aec27c1bf7
[repo] use logilab.db instead of lgc.adbh/lgc.db/lgc.sqlgen/indexer, test new date extranction functions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
2122 |
def test_date_extraction(self): |
c5aec27c1bf7
[repo] use logilab.db instead of lgc.adbh/lgc.db/lgc.sqlgen/indexer, test new date extranction functions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
2123 |
self._check("Any MONTH(D) WHERE P is Personne, P creation_date D", |
c5aec27c1bf7
[repo] use logilab.db instead of lgc.adbh/lgc.db/lgc.sqlgen/indexer, test new date extranction functions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
2124 |
'''SELECT EXTRACT(MONTH from _P.cw_creation_date) |
c5aec27c1bf7
[repo] use logilab.db instead of lgc.adbh/lgc.db/lgc.sqlgen/indexer, test new date extranction functions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
2125 |
FROM cw_Personne AS _P''') |
c5aec27c1bf7
[repo] use logilab.db instead of lgc.adbh/lgc.db/lgc.sqlgen/indexer, test new date extranction functions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
2126 |
|
7904
f41bb38dda7c
[rql, sql] support for weekday function introduced in lgdp 1.7 (closes #1979717)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7902
diff
changeset
|
2127 |
def test_weekday_extraction(self): |
f41bb38dda7c
[rql, sql] support for weekday function introduced in lgdp 1.7 (closes #1979717)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7902
diff
changeset
|
2128 |
self._check("Any WEEKDAY(D) WHERE P is Personne, P creation_date D", |
f41bb38dda7c
[rql, sql] support for weekday function introduced in lgdp 1.7 (closes #1979717)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7902
diff
changeset
|
2129 |
'''SELECT DAYOFWEEK(_P.cw_creation_date) |
f41bb38dda7c
[rql, sql] support for weekday function introduced in lgdp 1.7 (closes #1979717)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7902
diff
changeset
|
2130 |
FROM cw_Personne AS _P''') |
f41bb38dda7c
[rql, sql] support for weekday function introduced in lgdp 1.7 (closes #1979717)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7902
diff
changeset
|
2131 |
|
7256
ccd44caeb936
[rql] support CAST() Function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7252
diff
changeset
|
2132 |
def test_cast(self): |
ccd44caeb936
[rql] support CAST() Function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7252
diff
changeset
|
2133 |
self._check("Any CAST(String, P) WHERE P is Personne", |
ccd44caeb936
[rql] support CAST() Function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7252
diff
changeset
|
2134 |
'''SELECT CAST(_P.cw_eid AS mediumtext) |
ccd44caeb936
[rql] support CAST() Function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7252
diff
changeset
|
2135 |
FROM cw_Personne AS _P''') |
ccd44caeb936
[rql] support CAST() Function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7252
diff
changeset
|
2136 |
|
7257
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7256
diff
changeset
|
2137 |
def test_regexp(self): |
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7256
diff
changeset
|
2138 |
self._check("Any X WHERE X login REGEXP '[0-9].*'", |
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7256
diff
changeset
|
2139 |
'''SELECT _X.cw_eid |
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7256
diff
changeset
|
2140 |
FROM cw_CWUser AS _X |
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7256
diff
changeset
|
2141 |
WHERE _X.cw_login REGEXP [0-9].* |
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7256
diff
changeset
|
2142 |
''') |
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7256
diff
changeset
|
2143 |
|
0 | 2144 |
def test_from_clause_needed(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
2145 |
queries = [("Any 1 WHERE EXISTS(T is CWGroup, T name 'managers')", |
0 | 2146 |
'''SELECT 1 |
2147 |
FROM (SELECT 1) AS _T |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
2148 |
WHERE EXISTS(SELECT 1 FROM cw_CWGroup AS _T WHERE _T.cw_name=managers)'''), |
0 | 2149 |
('Any X,Y WHERE NOT X created_by Y, X eid 5, Y eid 6', |
2150 |
'''SELECT 5, 6 |
|
2151 |
FROM (SELECT 1) AS _T |
|
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
2152 |
WHERE NOT (EXISTS(SELECT 1 FROM created_by_relation AS rel_created_by0 WHERE rel_created_by0.eid_from=5 AND rel_created_by0.eid_to=6))'''), |
0 | 2153 |
] |
2154 |
for t in self._parse(queries): |
|
2155 |
yield t |
|
2156 |
||
2157 |
||
2158 |
def test_has_text(self): |
|
2159 |
queries = [ |
|
2160 |
('Any X WHERE X has_text "toto tata"', |
|
2161 |
"""SELECT appears0.uid |
|
2162 |
FROM appears AS appears0 |
|
2163 |
WHERE MATCH (appears0.words) AGAINST ('toto tata' IN BOOLEAN MODE)"""), |
|
2164 |
('Personne X WHERE X has_text "toto tata"', |
|
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
2165 |
"""SELECT _X.eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
2166 |
FROM appears AS appears0, entities AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
2167 |
WHERE MATCH (appears0.words) AGAINST ('toto tata' IN BOOLEAN MODE) AND appears0.uid=_X.eid AND _X.type='Personne'"""), |
0 | 2168 |
('Personne X WHERE X has_text %(text)s', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
2169 |
"""SELECT _X.eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
2170 |
FROM appears AS appears0, entities AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
2171 |
WHERE MATCH (appears0.words) AGAINST ('hip hop momo' IN BOOLEAN MODE) AND appears0.uid=_X.eid AND _X.type='Personne'"""), |
3587 | 2172 |
('Any X WHERE X has_text "toto tata", X name "tutu", X is IN (Basket,Folder)', |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
2173 |
"""SELECT _X.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
2174 |
FROM appears AS appears0, cw_Basket AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
2175 |
WHERE MATCH (appears0.words) AGAINST ('toto tata' IN BOOLEAN MODE) AND appears0.uid=_X.cw_eid AND _X.cw_name=tutu |
0 | 2176 |
UNION ALL |
3762
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
2177 |
SELECT _X.cw_eid |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
2178 |
FROM appears AS appears0, cw_Folder AS _X |
e416186fb91c
prefix sql aliases for entity table by '_' to avoid pb with variable such as 'AS' (eg a keyword in SQL)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3752
diff
changeset
|
2179 |
WHERE MATCH (appears0.words) AGAINST ('toto tata' IN BOOLEAN MODE) AND appears0.uid=_X.cw_eid AND _X.cw_name=tutu |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2916
diff
changeset
|
2180 |
""") |
0 | 2181 |
] |
2182 |
for t in self._parse(queries): |
|
2183 |
yield t |
|
1787 | 2184 |
|
0 | 2185 |
|
2186 |
def test_ambigous_exists_no_from_clause(self): |
|
2187 |
self._check('Any COUNT(U) WHERE U eid 1, EXISTS (P owned_by U, P is IN (Note, Affaire))', |
|
2188 |
'''SELECT COUNT(1) |
|
2189 |
FROM (SELECT 1) AS _T |
|
7193
7eaef037ea9d
[sql generation] fix missing join with outer joins w/ rhs invariant variable...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7142
diff
changeset
|
2190 |
WHERE EXISTS(SELECT 1 FROM cw_Affaire AS _P, owned_by_relation AS rel_owned_by0 WHERE rel_owned_by0.eid_from=_P.cw_eid AND rel_owned_by0.eid_to=1 UNION SELECT 1 FROM cw_Note AS _P, owned_by_relation AS rel_owned_by1 WHERE rel_owned_by1.eid_from=_P.cw_eid AND rel_owned_by1.eid_to=1)''') |
0 | 2191 |
|
4289
890dc89516f1
fix bad indent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4286
diff
changeset
|
2192 |
def test_groupby_multiple_outerjoins(self): |
890dc89516f1
fix bad indent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4286
diff
changeset
|
2193 |
self._check('Any A,U,P,group_concat(TN) GROUPBY A,U,P WHERE A is Affaire, A concerne N, N todo_by U?, T? tags A, T name TN, A todo_by P?', |
4286
6801093af29c
fix bug: the 'table' argument is overwritten by the loop variable, causing latter crash due to this missing information
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
2194 |
'''SELECT _A.cw_eid, rel_todo_by1.eid_to, rel_todo_by3.eid_to, GROUP_CONCAT(_T.cw_name) |
6801093af29c
fix bug: the 'table' argument is overwritten by the loop variable, causing latter crash due to this missing information
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
2195 |
FROM concerne_relation AS rel_concerne0, cw_Affaire AS _A LEFT OUTER JOIN tags_relation AS rel_tags2 ON (rel_tags2.eid_to=_A.cw_eid) LEFT OUTER JOIN cw_Tag AS _T ON (rel_tags2.eid_from=_T.cw_eid) LEFT OUTER JOIN todo_by_relation AS rel_todo_by3 ON (rel_todo_by3.eid_from=_A.cw_eid), cw_Note AS _N LEFT OUTER JOIN todo_by_relation AS rel_todo_by1 ON (rel_todo_by1.eid_from=_N.cw_eid) |
6801093af29c
fix bug: the 'table' argument is overwritten by the loop variable, causing latter crash due to this missing information
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
2196 |
WHERE rel_concerne0.eid_from=_A.cw_eid AND rel_concerne0.eid_to=_N.cw_eid |
6801093af29c
fix bug: the 'table' argument is overwritten by the loop variable, causing latter crash due to this missing information
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
2197 |
GROUP BY _A.cw_eid,rel_todo_by1.eid_to,rel_todo_by3.eid_to''') |
6801093af29c
fix bug: the 'table' argument is overwritten by the loop variable, causing latter crash due to this missing information
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
2198 |
|
5233
673b63953e7a
ticket #787103, entity schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
5016
diff
changeset
|
2199 |
def test_substring(self): |
673b63953e7a
ticket #787103, entity schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
5016
diff
changeset
|
2200 |
self._check("Any SUBSTRING(N, 1, 1) WHERE P nom N, P is Personne", |
673b63953e7a
ticket #787103, entity schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
5016
diff
changeset
|
2201 |
'''SELECT SUBSTRING(_P.cw_nom, 1, 1) |
673b63953e7a
ticket #787103, entity schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
5016
diff
changeset
|
2202 |
FROM cw_Personne AS _P''') |
1787 | 2203 |
|
5887
3f55f0f10a22
[rql2sql] test and fix crash when OR in HAVING where both expresion are 'fake' having terms (eg not using aggregat function)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
2204 |
|
7672
f31f9882c90f
[rql2sql] closes #1832859: fake HAVING terms w/ EXISTS terms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7651
diff
changeset
|
2205 |
def test_or_having_fake_terms_base(self): |
5887
3f55f0f10a22
[rql2sql] test and fix crash when OR in HAVING where both expresion are 'fake' having terms (eg not using aggregat function)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
2206 |
self._check('Any X WHERE X is CWUser, X creation_date D HAVING YEAR(D) = "2010" OR D = NULL', |
3f55f0f10a22
[rql2sql] test and fix crash when OR in HAVING where both expresion are 'fake' having terms (eg not using aggregat function)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
2207 |
'''SELECT _X.cw_eid |
3f55f0f10a22
[rql2sql] test and fix crash when OR in HAVING where both expresion are 'fake' having terms (eg not using aggregat function)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
2208 |
FROM cw_CWUser AS _X |
3f55f0f10a22
[rql2sql] test and fix crash when OR in HAVING where both expresion are 'fake' having terms (eg not using aggregat function)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
2209 |
WHERE ((EXTRACT(YEAR from _X.cw_creation_date)=2010) OR (_X.cw_creation_date IS NULL))''') |
3f55f0f10a22
[rql2sql] test and fix crash when OR in HAVING where both expresion are 'fake' having terms (eg not using aggregat function)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
2210 |
|
3f55f0f10a22
[rql2sql] test and fix crash when OR in HAVING where both expresion are 'fake' having terms (eg not using aggregat function)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
2211 |
|
6297
23c1e50ff97b
[rql] fix bug with query like 'Any 1 WHERE NOT X in_group G': tables should be kept in EXISTS() even when there are no restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6194
diff
changeset
|
2212 |
def test_not_no_where(self): |
23c1e50ff97b
[rql] fix bug with query like 'Any 1 WHERE NOT X in_group G': tables should be kept in EXISTS() even when there are no restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6194
diff
changeset
|
2213 |
self._check('Any 1 WHERE NOT X in_group G, X is CWUser', |
23c1e50ff97b
[rql] fix bug with query like 'Any 1 WHERE NOT X in_group G': tables should be kept in EXISTS() even when there are no restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6194
diff
changeset
|
2214 |
'''SELECT 1 |
23c1e50ff97b
[rql] fix bug with query like 'Any 1 WHERE NOT X in_group G': tables should be kept in EXISTS() even when there are no restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6194
diff
changeset
|
2215 |
FROM (SELECT 1) AS _T |
23c1e50ff97b
[rql] fix bug with query like 'Any 1 WHERE NOT X in_group G': tables should be kept in EXISTS() even when there are no restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6194
diff
changeset
|
2216 |
WHERE NOT (EXISTS(SELECT 1 FROM in_group_relation AS rel_in_group0))''') |
23c1e50ff97b
[rql] fix bug with query like 'Any 1 WHERE NOT X in_group G': tables should be kept in EXISTS() even when there are no restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6194
diff
changeset
|
2217 |
|
7579
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
2218 |
def test_groupby_orderby_insertion_dont_modify_intention(self): |
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
2219 |
self._check('Any YEAR(XECT)*100+MONTH(XECT), COUNT(X),SUM(XCE),AVG(XSCT-XECT) ' |
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
2220 |
'GROUPBY YEAR(XECT),MONTH(XECT) ORDERBY 1 ' |
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
2221 |
'WHERE X creation_date XSCT, X modification_date XECT, ' |
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
2222 |
'X ordernum XCE, X is CWAttribute', |
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
2223 |
'''SELECT ((EXTRACT(YEAR from _X.cw_modification_date) * 100) + EXTRACT(MONTH from _X.cw_modification_date)), COUNT(_X.cw_eid), SUM(_X.cw_ordernum), AVG((_X.cw_creation_date - _X.cw_modification_date)) |
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
2224 |
FROM cw_CWAttribute AS _X |
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
2225 |
GROUP BY EXTRACT(YEAR from _X.cw_modification_date),EXTRACT(MONTH from _X.cw_modification_date) |
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
2226 |
ORDER BY 1'''), |
5a610b34d2d2
[rql2sql] more cases fixed where something is wrongly added to GROUPBY, causing unexpected results for the query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7472
diff
changeset
|
2227 |
|
8217
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
2228 |
def test_today(self): |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
2229 |
for t in self._parse([("Any X WHERE X creation_date TODAY, X is Affaire", |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
2230 |
'''SELECT _X.cw_eid |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
2231 |
FROM cw_Affaire AS _X |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
2232 |
WHERE DATE(_X.cw_creation_date)=CURRENT_DATE'''), |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
2233 |
|
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
2234 |
("Personne P where not P datenaiss TODAY", |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
2235 |
'''SELECT _P.cw_eid |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
2236 |
FROM cw_Personne AS _P |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
2237 |
WHERE NOT (DATE(_P.cw_datenaiss)=CURRENT_DATE)'''), |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
2238 |
]): |
0a467663c3fe
[server test] fix test broken by recent changes in lgdb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8109
diff
changeset
|
2239 |
yield t |
6297
23c1e50ff97b
[rql] fix bug with query like 'Any 1 WHERE NOT X in_group G': tables should be kept in EXISTS() even when there are no restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6194
diff
changeset
|
2240 |
|
3852
03121ca1f85e
test and fix case where remove_unsused_solutions remove some solutions that should be kept
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3815
diff
changeset
|
2241 |
class removeUnsusedSolutionsTC(TestCase): |
03121ca1f85e
test and fix case where remove_unsused_solutions remove some solutions that should be kept
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3815
diff
changeset
|
2242 |
def test_invariant_not_varying(self): |
03121ca1f85e
test and fix case where remove_unsused_solutions remove some solutions that should be kept
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3815
diff
changeset
|
2243 |
rqlst = mock_object(defined_vars={}) |
5004
4cc020ee70e2
le patch rql26 a été importé
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4998
diff
changeset
|
2244 |
rqlst.defined_vars['A'] = mock_object(scope=rqlst, stinfo={}, _q_invariant=True) |
4cc020ee70e2
le patch rql26 a été importé
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4998
diff
changeset
|
2245 |
rqlst.defined_vars['B'] = mock_object(scope=rqlst, stinfo={}, _q_invariant=False) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6297
diff
changeset
|
2246 |
self.assertEqual(remove_unused_solutions(rqlst, [{'A': 'RugbyGroup', 'B': 'RugbyTeam'}, |
3852
03121ca1f85e
test and fix case where remove_unsused_solutions remove some solutions that should be kept
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3815
diff
changeset
|
2247 |
{'A': 'FootGroup', 'B': 'FootTeam'}], {}, None), |
03121ca1f85e
test and fix case where remove_unsused_solutions remove some solutions that should be kept
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3815
diff
changeset
|
2248 |
([{'A': 'RugbyGroup', 'B': 'RugbyTeam'}, |
03121ca1f85e
test and fix case where remove_unsused_solutions remove some solutions that should be kept
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3815
diff
changeset
|
2249 |
{'A': 'FootGroup', 'B': 'FootTeam'}], |
03121ca1f85e
test and fix case where remove_unsused_solutions remove some solutions that should be kept
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3815
diff
changeset
|
2250 |
{}, set('B')) |
03121ca1f85e
test and fix case where remove_unsused_solutions remove some solutions that should be kept
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3815
diff
changeset
|
2251 |
) |
1787 | 2252 |
|
3852
03121ca1f85e
test and fix case where remove_unsused_solutions remove some solutions that should be kept
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3815
diff
changeset
|
2253 |
def test_invariant_varying(self): |
03121ca1f85e
test and fix case where remove_unsused_solutions remove some solutions that should be kept
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3815
diff
changeset
|
2254 |
rqlst = mock_object(defined_vars={}) |
5004
4cc020ee70e2
le patch rql26 a été importé
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4998
diff
changeset
|
2255 |
rqlst.defined_vars['A'] = mock_object(scope=rqlst, stinfo={}, _q_invariant=True) |
4cc020ee70e2
le patch rql26 a été importé
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4998
diff
changeset
|
2256 |
rqlst.defined_vars['B'] = mock_object(scope=rqlst, stinfo={}, _q_invariant=False) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6297
diff
changeset
|
2257 |
self.assertEqual(remove_unused_solutions(rqlst, [{'A': 'RugbyGroup', 'B': 'RugbyTeam'}, |
3852
03121ca1f85e
test and fix case where remove_unsused_solutions remove some solutions that should be kept
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3815
diff
changeset
|
2258 |
{'A': 'FootGroup', 'B': 'RugbyTeam'}], {}, None), |
03121ca1f85e
test and fix case where remove_unsused_solutions remove some solutions that should be kept
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3815
diff
changeset
|
2259 |
([{'A': 'RugbyGroup', 'B': 'RugbyTeam'}], {}, set()) |
03121ca1f85e
test and fix case where remove_unsused_solutions remove some solutions that should be kept
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3815
diff
changeset
|
2260 |
) |
0 | 2261 |
|
5575
8a531340c3ef
no more Image type w/ cw 3.9
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
2262 |
|
0 | 2263 |
if __name__ == '__main__': |
2264 |
unittest_main() |