merge stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 20 Oct 2009 16:22:52 +0200
branchstable
changeset 3753 310621cfed9b
parent 3752 4c77a1653374 (diff)
parent 3749 a84e798b99f6 (current diff)
child 3754 a9c641f6193b
merge
--- a/server/sources/rql2sql.py	Tue Oct 20 14:34:42 2009 +0200
+++ b/server/sources/rql2sql.py	Tue Oct 20 16:22:52 2009 +0200
@@ -207,9 +207,17 @@
                     if not vref in groups:
                         groups.append(vref)
 
-def fix_selection(rqlst, selectedidx, needwrap, sorts, groups, having):
-    if sorts:
+def fix_selection_and_group(rqlst, selectedidx, needwrap, selectsortterms,
+                            sorts, groups, having):
+    if selectsortterms and sorts:
         sort_term_selection(sorts, selectedidx, rqlst, not needwrap and groups)
+    if sorts and groups:
+        for sortterm in sorts:
+            term = sortterm.term
+            if not isinstance(term, Constant):
+                for vref in term.iget_nodes(VariableRef):
+                    if not vref in groups:
+                        groups.append(vref)
     if needwrap:
         if groups:
             for vref in groups:
@@ -410,8 +418,8 @@
                                         outerselection, groups)
             else:
                 outerselectidx = selectidx[:]
-        fix_selection(select, selectidx, needwrap,
-                      selectsortterms and sorts, groups, having)
+        fix_selection_and_group(select, selectidx, needwrap,
+                                selectsortterms, sorts, groups, having)
         if needwrap:
             fselectidx = outerselectidx
             fneedwrap = len(outerselection) != len(origselection)
--- a/server/test/unittest_rql2sql.py	Tue Oct 20 14:34:42 2009 +0200
+++ b/server/test/unittest_rql2sql.py	Tue Oct 20 16:22:52 2009 +0200
@@ -446,7 +446,7 @@
 UNION ALL
 SELECT X.cw_data AS C0, X.cw_eid AS C1, X.cw_data_name AS C2, X.cw_data_format AS C3
 FROM cw_Image AS X) AS T1
-GROUP BY T1.C2
+GROUP BY T1.C2,T1.C3
 ORDER BY 1,2,T1.C3'''),
 
     ('DISTINCT Any S ORDERBY R WHERE A is Affaire, A sujet S, A ref R',
@@ -524,7 +524,7 @@
      '''SELECT X.cw_eid
 FROM cw_CWUser AS X
 WHERE X.cw_eid=12
-GROUP BY X.cw_eid
+GROUP BY X.cw_eid,X.cw_login
 ORDER BY X.cw_login'''),
 
     ('Any U,COUNT(X) GROUPBY U WHERE U eid 12, X owned_by U HAVING COUNT(X) > 10',
@@ -574,7 +574,30 @@
     ("Any X WHERE X eid 0, X eid 0, X test TRUE",
      '''SELECT X.cw_eid
 FROM cw_Personne AS X
-WHERE X.cw_eid=0 AND X.cw_eid=0 AND X.cw_test='''),
+WHERE X.cw_eid=0 AND X.cw_eid=0 AND X.cw_test=TRUE'''),
+
+    ("Any X,GROUP_CONCAT(TN) GROUPBY X ORDERBY XN WHERE T tags X, X name XN, T name TN, X is CWGroup",
+     '''SELECT X.cw_eid, GROUP_CONCAT(T.cw_name)
+FROM cw_CWGroup AS X, cw_Tag AS T, tags_relation AS rel_tags0
+WHERE rel_tags0.eid_from=T.cw_eid AND rel_tags0.eid_to=X.cw_eid
+GROUP BY X.cw_eid,X.cw_name
+ORDER BY X.cw_name'''),
+
+    ("Any X,GROUP_CONCAT(TN) GROUPBY X ORDERBY XN WHERE T tags X, X name XN, T name TN",
+     '''SELECT T1.C0, GROUP_CONCAT(T1.C1) FROM (SELECT X.cw_eid AS C0, T.cw_name AS C1, X.cw_name AS C2
+FROM cw_CWGroup AS X, cw_Tag AS T, tags_relation AS rel_tags0
+WHERE rel_tags0.eid_from=T.cw_eid AND rel_tags0.eid_to=X.cw_eid
+UNION ALL
+SELECT X.cw_eid AS C0, T.cw_name AS C1, X.cw_name AS C2
+FROM cw_State AS X, cw_Tag AS T, tags_relation AS rel_tags0
+WHERE rel_tags0.eid_from=T.cw_eid AND rel_tags0.eid_to=X.cw_eid
+UNION ALL
+SELECT X.cw_eid AS C0, T.cw_name AS C1, X.cw_name AS C2
+FROM cw_Tag AS T, cw_Tag AS X, tags_relation AS rel_tags0
+WHERE rel_tags0.eid_from=T.cw_eid AND rel_tags0.eid_to=X.cw_eid) AS T1
+GROUP BY T1.C0,T1.C2
+ORDER BY T1.C2'''),
+
     ]
 
 MULTIPLE_SEL = [
--- a/web/component.py	Tue Oct 20 14:34:42 2009 +0200
+++ b/web/component.py	Tue Oct 20 16:22:52 2009 +0200
@@ -175,7 +175,8 @@
         if not rset.rowcount:
             return
         self.w(u'<div class="%s">' % self.div_class())
-        self.wview(self.vid, rset, title=self.req._(self.title).capitalize())
+        self.w(u'<h4>%s</h4>\n' % self.req._(self.title).capitalize())
+        self.wview(self.vid, rset)
         self.w(u'</div>')
 
 
--- a/web/views/navigation.py	Tue Oct 20 14:34:42 2009 +0200
+++ b/web/views/navigation.py	Tue Oct 20 16:22:52 2009 +0200
@@ -62,6 +62,8 @@
         req = self.req
         if attrname is not None:
             def index_display(row):
+                if not rset[row][col]: # outer join
+                    return u''
                 entity = rset.get_entity(row, col)
                 return entity.printable_value(attrname, format='text/plain')
         elif self.schema.eschema(rset.description[0][col]).final: