new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer stable
authorAlexandre Fayolle <alexandre.fayolle@logilab.fr>
Thu, 30 Jun 2011 09:46:33 +0200
branchstable
changeset 7596 f3cdf1694c92
parent 7594 d177c0755b10
child 7597 c6cf2a9b2331
new rql2sql unit tests for ORDERBY and LIMIT checks in SQLServer
server/test/unittest_rql2sql.py
--- a/server/test/unittest_rql2sql.py	Fri Jul 01 11:27:20 2011 +0200
+++ b/server/test/unittest_rql2sql.py	Thu Jun 30 09:46:33 2011 +0200
@@ -210,6 +210,12 @@
 FROM cw_Personne AS _P
 LIMIT 20
 OFFSET 10'''),
+    ("Any P ORDERBY N LIMIT 1 WHERE P is Personne, P travaille S, S eid %(eid)s, P nom N, P nom %(text)s",
+     '''SELECT _P.cw_eid
+FROM cw_Personne AS _P, travaille_relation AS rel_travaille0
+WHERE rel_travaille0.eid_from=_P.cw_eid AND rel_travaille0.eid_to=12345 AND _P.cw_nom=hip hop momo
+ORDER BY _P.cw_nom
+LIMIT 1'''),
     ]
 
 
@@ -1239,7 +1245,7 @@
 
     def _check(self, rql, sql, varmap=None, args=None):
         if args is None:
-            args = {'text': 'hip hop momo'}
+            args = {'text': 'hip hop momo', 'eid': 12345}
         try:
             union = self._prepare(rql)
             r, nargs, cbs = self.o.generate(union, args,
@@ -1755,6 +1761,48 @@
 FROM cw_EmailAddress AS _O
 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))
 ORDER BY 4 DESC'''),
+
+    ("Any P ORDERBY N LIMIT 1 WHERE P is Personne, P travaille S, S eid %(eid)s, P nom N, P nom %(text)s",
+     '''WITH orderedrows AS (
+SELECT
+_L01
+, ROW_NUMBER() OVER (ORDER BY _L01) AS __RowNumber
+FROM (
+SELECT _P.cw_eid AS _L01 FROM  cw_Personne AS _P, travaille_relation AS rel_travaille0
+WHERE rel_travaille0.eid_from=_P.cw_eid AND rel_travaille0.eid_to=12345 AND _P.cw_nom=hip hop momo
+) AS _SQ1 )
+SELECT
+_L01
+FROM orderedrows WHERE
+__RowNumber <= 1'''),
+
+    ("Any P ORDERBY N LIMIT 1 WHERE P is Personne, P nom N",
+     '''WITH orderedrows AS (
+SELECT
+_L01
+, ROW_NUMBER() OVER (ORDER BY _L01) AS __RowNumber
+FROM (
+SELECT _P.cw_eid AS _L01 FROM  cw_Personne AS _P
+) AS _SQ1 )
+SELECT
+_L01
+FROM orderedrows WHERE
+__RowNumber <= 1
+'''),
+
+    ("Any PN, N, P ORDERBY N LIMIT 1 WHERE P is Personne, P nom N, P prenom PN",
+     '''WITH orderedrows AS (
+SELECT
+_L01, _L02, _L03
+, ROW_NUMBER() OVER (ORDER BY _L02) AS __RowNumber
+FROM (
+SELECT _P.cw_prenom AS _L01, _P.cw_nom AS _L02, _P.cw_eid AS _L03 FROM  cw_Personne AS _P
+) AS _SQ1 )
+SELECT
+_L01, _L02, _L03
+FROM orderedrows WHERE
+__RowNumber <= 1
+'''),
             ]
         for t in self._parse(WITH_LIMIT):# + ADVANCED_WITH_LIMIT_OR_ORDERBY):
             yield t