server/test/unittest_rql2sql.py
changeset 3589 a5432f99f2d9
parent 3524 a3431f4e2f40
parent 3587 5b3725f315fc
child 3674 387d51af966d
equal deleted inserted replaced
3536:f6c9a5df80fb 3589:a5432f99f2d9
   335     ('Any L WHERE X login "admin", X identity Y?, Y login L',
   335     ('Any L WHERE X login "admin", X identity Y?, Y login L',
   336      '''SELECT Y.cw_login
   336      '''SELECT Y.cw_login
   337 FROM cw_CWUser AS X LEFT OUTER JOIN cw_CWUser AS Y ON (X.cw_eid=Y.cw_eid)
   337 FROM cw_CWUser AS X LEFT OUTER JOIN cw_CWUser AS Y ON (X.cw_eid=Y.cw_eid)
   338 WHERE X.cw_login=admin'''),
   338 WHERE X.cw_login=admin'''),
   339 
   339 
   340     ('Any XN ORDERBY XN WHERE X name XN',
   340     ('Any XN ORDERBY XN WHERE X name XN, X is IN (Basket,Folder,Tag)',
   341      '''SELECT X.cw_name
   341      '''SELECT X.cw_name
   342 FROM cw_BaseTransition AS X
       
   343 UNION ALL
       
   344 SELECT X.cw_name
       
   345 FROM cw_Basket AS X
   342 FROM cw_Basket AS X
   346 UNION ALL
       
   347 SELECT X.cw_name
       
   348 FROM cw_CWCache AS X
       
   349 UNION ALL
       
   350 SELECT X.cw_name
       
   351 FROM cw_CWConstraintType AS X
       
   352 UNION ALL
       
   353 SELECT X.cw_name
       
   354 FROM cw_CWEType AS X
       
   355 UNION ALL
       
   356 SELECT X.cw_name
       
   357 FROM cw_CWGroup AS X
       
   358 UNION ALL
       
   359 SELECT X.cw_name
       
   360 FROM cw_CWPermission AS X
       
   361 UNION ALL
       
   362 SELECT X.cw_name
       
   363 FROM cw_CWRType AS X
       
   364 UNION ALL
       
   365 SELECT X.cw_name
       
   366 FROM cw_File AS X
       
   367 UNION ALL
   343 UNION ALL
   368 SELECT X.cw_name
   344 SELECT X.cw_name
   369 FROM cw_Folder AS X
   345 FROM cw_Folder AS X
   370 UNION ALL
   346 UNION ALL
   371 SELECT X.cw_name
   347 SELECT X.cw_name
   372 FROM cw_Image AS X
       
   373 UNION ALL
       
   374 SELECT X.cw_name
       
   375 FROM cw_State AS X
       
   376 UNION ALL
       
   377 SELECT X.cw_name
       
   378 FROM cw_Tag AS X
   348 FROM cw_Tag AS X
   379 UNION ALL
       
   380 SELECT X.cw_name
       
   381 FROM cw_Transition AS X
       
   382 UNION ALL
       
   383 SELECT X.cw_name
       
   384 FROM cw_Workflow AS X
       
   385 UNION ALL
       
   386 SELECT X.cw_name
       
   387 FROM cw_WorkflowTransition AS X
       
   388 ORDER BY 1'''),
   349 ORDER BY 1'''),
   389 
   350 
   390     # DISTINCT, can use relation under exists scope as principal
   351     # DISTINCT, can use relation under exists scope as principal
   391     ('DISTINCT Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), EXISTS(X read_permission Y)',
   352     ('DISTINCT Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), EXISTS(X read_permission Y)',
   392      '''SELECT DISTINCT X.cw_eid, rel_read_permission0.eid_to
   353      '''SELECT DISTINCT X.cw_eid, rel_read_permission0.eid_to
   467 UNION ALL
   428 UNION ALL
   468 SELECT X.cw_eid, Y.cw_eid
   429 SELECT X.cw_eid, Y.cw_eid
   469 FROM cw_CWRType AS X, cw_RQLExpression AS Y
   430 FROM cw_CWRType AS X, cw_RQLExpression AS Y
   470 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)'''),
   431 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)'''),
   471 
   432 
   472     ('Any MAX(X)+MIN(X), N GROUPBY N WHERE X name N;',
   433     ('Any MAX(X)+MIN(X), N GROUPBY N WHERE X name N, X is IN (Basket, Folder, Tag);',
   473      '''SELECT (MAX(T1.C0) + MIN(T1.C0)), T1.C1 FROM (SELECT X.cw_eid AS C0, X.cw_name AS C1
   434      '''SELECT (MAX(T1.C0) + MIN(T1.C0)), T1.C1 FROM (SELECT X.cw_eid AS C0, X.cw_name AS C1
   474 FROM cw_BaseTransition AS X
       
   475 UNION ALL
       
   476 SELECT X.cw_eid AS C0, X.cw_name AS C1
       
   477 FROM cw_Basket AS X
   435 FROM cw_Basket AS X
   478 UNION ALL
       
   479 SELECT X.cw_eid AS C0, X.cw_name AS C1
       
   480 FROM cw_CWCache AS X
       
   481 UNION ALL
       
   482 SELECT X.cw_eid AS C0, X.cw_name AS C1
       
   483 FROM cw_CWConstraintType AS X
       
   484 UNION ALL
       
   485 SELECT X.cw_eid AS C0, X.cw_name AS C1
       
   486 FROM cw_CWEType AS X
       
   487 UNION ALL
       
   488 SELECT X.cw_eid AS C0, X.cw_name AS C1
       
   489 FROM cw_CWGroup AS X
       
   490 UNION ALL
       
   491 SELECT X.cw_eid AS C0, X.cw_name AS C1
       
   492 FROM cw_CWPermission AS X
       
   493 UNION ALL
       
   494 SELECT X.cw_eid AS C0, X.cw_name AS C1
       
   495 FROM cw_CWRType AS X
       
   496 UNION ALL
       
   497 SELECT X.cw_eid AS C0, X.cw_name AS C1
       
   498 FROM cw_File AS X
       
   499 UNION ALL
   436 UNION ALL
   500 SELECT X.cw_eid AS C0, X.cw_name AS C1
   437 SELECT X.cw_eid AS C0, X.cw_name AS C1
   501 FROM cw_Folder AS X
   438 FROM cw_Folder AS X
   502 UNION ALL
   439 UNION ALL
   503 SELECT X.cw_eid AS C0, X.cw_name AS C1
   440 SELECT X.cw_eid AS C0, X.cw_name AS C1
   504 FROM cw_Image AS X
   441 FROM cw_Tag AS X) AS T1
   505 UNION ALL
       
   506 SELECT X.cw_eid AS C0, X.cw_name AS C1
       
   507 FROM cw_State AS X
       
   508 UNION ALL
       
   509 SELECT X.cw_eid AS C0, X.cw_name AS C1
       
   510 FROM cw_Tag AS X
       
   511 UNION ALL
       
   512 SELECT X.cw_eid AS C0, X.cw_name AS C1
       
   513 FROM cw_Transition AS X
       
   514 UNION ALL
       
   515 SELECT X.cw_eid AS C0, X.cw_name AS C1
       
   516 FROM cw_Workflow AS X
       
   517 UNION ALL
       
   518 SELECT X.cw_eid AS C0, X.cw_name AS C1
       
   519 FROM cw_WorkflowTransition AS X) AS T1
       
   520 GROUP BY T1.C1'''),
   442 GROUP BY T1.C1'''),
   521 
   443 
   522     ('Any MAX(X)+MIN(LENGTH(D)), N GROUPBY N ORDERBY 1, N, DF WHERE X name N, X data D, X data_format DF;',
   444     ('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;',
   523      '''SELECT (MAX(T1.C1) + MIN(LENGTH(T1.C0))), T1.C2 FROM (SELECT X.cw_data AS C0, X.cw_eid AS C1, X.cw_name AS C2, X.cw_data_format AS C3
   445      '''SELECT (MAX(T1.C1) + MIN(LENGTH(T1.C0))), T1.C2 FROM (SELECT X.cw_data AS C0, X.cw_eid AS C1, X.cw_data_name AS C2, X.cw_data_format AS C3
   524 FROM cw_File AS X
   446 FROM cw_File AS X
   525 UNION ALL
   447 UNION ALL
   526 SELECT X.cw_data AS C0, X.cw_eid AS C1, X.cw_name AS C2, X.cw_data_format AS C3
   448 SELECT X.cw_data AS C0, X.cw_eid AS C1, X.cw_data_name AS C2, X.cw_data_format AS C3
   527 FROM cw_Image AS X) AS T1
   449 FROM cw_Image AS X) AS T1
   528 GROUP BY T1.C2
   450 GROUP BY T1.C2
   529 ORDER BY 1,2,T1.C3'''),
   451 ORDER BY 1,2,T1.C3'''),
   530 
   452 
   531     ('DISTINCT Any S ORDERBY R WHERE A is Affaire, A sujet S, A ref R',
   453     ('DISTINCT Any S ORDERBY R WHERE A is Affaire, A sujet S, A ref R',
   532      '''SELECT T1.C0 FROM (SELECT DISTINCT A.cw_sujet AS C0, A.cw_ref AS C1
   454      '''SELECT T1.C0 FROM (SELECT DISTINCT A.cw_sujet AS C0, A.cw_ref AS C1
   533 FROM cw_Affaire AS A
   455 FROM cw_Affaire AS A
   534 ORDER BY 2) AS T1'''),
   456 ORDER BY 2) AS T1'''),
   535 
   457 
   536     ('DISTINCT Any MAX(X)+MIN(LENGTH(D)), N GROUPBY N ORDERBY 2, DF WHERE X name N, X data D, X data_format DF;',
   458     ('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;',
   537      '''SELECT T1.C0,T1.C1 FROM (SELECT DISTINCT (MAX(T1.C1) + MIN(LENGTH(T1.C0))) AS C0, T1.C2 AS C1, T1.C3 AS C2 FROM (SELECT DISTINCT X.cw_data AS C0, X.cw_eid AS C1, X.cw_name AS C2, X.cw_data_format AS C3
   459      '''SELECT T1.C0,T1.C1 FROM (SELECT DISTINCT (MAX(T1.C1) + MIN(LENGTH(T1.C0))) AS C0, T1.C2 AS C1, T1.C3 AS C2 FROM (SELECT DISTINCT X.cw_data AS C0, X.cw_eid AS C1, X.cw_data_name AS C2, X.cw_data_format AS C3
   538 FROM cw_File AS X
   460 FROM cw_File AS X
   539 UNION
   461 UNION
   540 SELECT DISTINCT X.cw_data AS C0, X.cw_eid AS C1, X.cw_name AS C2, X.cw_data_format AS C3
   462 SELECT DISTINCT X.cw_data AS C0, X.cw_eid AS C1, X.cw_data_name AS C2, X.cw_data_format AS C3
   541 FROM cw_Image AS X) AS T1
   463 FROM cw_Image AS X) AS T1
   542 GROUP BY T1.C2,T1.C3
   464 GROUP BY T1.C2,T1.C3
   543 ORDER BY 2,3) AS T1
   465 ORDER BY 2,3) AS T1
   544 '''),
   466 '''),
   545 
   467 
  1407             ('Personne X WHERE X has_text %(text)s',
  1329             ('Personne X WHERE X has_text %(text)s',
  1408              """SELECT X.eid
  1330              """SELECT X.eid
  1409 FROM appears AS appears0, entities AS X
  1331 FROM appears AS appears0, entities AS X
  1410 WHERE appears0.words @@ to_tsquery('default', 'hip&hop&momo') AND appears0.uid=X.eid AND X.type='Personne'"""),
  1332 WHERE appears0.words @@ to_tsquery('default', 'hip&hop&momo') AND appears0.uid=X.eid AND X.type='Personne'"""),
  1411 
  1333 
  1412             ('Any X WHERE X has_text "toto tata", X name "tutu", X is IN (Basket,File,Folder)',
  1334             ('Any X WHERE X has_text "toto tata", X name "tutu", X is IN (Basket,Folder)',
  1413              """SELECT X.cw_eid
  1335              """SELECT X.cw_eid
  1414 FROM appears AS appears0, cw_Basket AS X
  1336 FROM appears AS appears0, cw_Basket AS X
  1415 WHERE appears0.words @@ to_tsquery('default', 'toto&tata') AND appears0.uid=X.cw_eid AND X.cw_name=tutu
       
  1416 UNION ALL
       
  1417 SELECT X.cw_eid
       
  1418 FROM appears AS appears0, cw_File AS X
       
  1419 WHERE appears0.words @@ to_tsquery('default', 'toto&tata') AND appears0.uid=X.cw_eid AND X.cw_name=tutu
  1337 WHERE appears0.words @@ to_tsquery('default', 'toto&tata') AND appears0.uid=X.cw_eid AND X.cw_name=tutu
  1420 UNION ALL
  1338 UNION ALL
  1421 SELECT X.cw_eid
  1339 SELECT X.cw_eid
  1422 FROM appears AS appears0, cw_Folder AS X
  1340 FROM appears AS appears0, cw_Folder AS X
  1423 WHERE appears0.words @@ to_tsquery('default', 'toto&tata') AND appears0.uid=X.cw_eid AND X.cw_name=tutu
  1341 WHERE appears0.words @@ to_tsquery('default', 'toto&tata') AND appears0.uid=X.cw_eid AND X.cw_name=tutu
  1556             ('Personne X WHERE X has_text "toto tata"',
  1474             ('Personne X WHERE X has_text "toto tata"',
  1557              """SELECT X.eid
  1475              """SELECT X.eid
  1558 FROM appears AS appears0, entities AS X
  1476 FROM appears AS appears0, entities AS X
  1559 WHERE appears0.word_id IN (SELECT word_id FROM word WHERE word in ('toto', 'tata')) AND appears0.uid=X.eid AND X.type='Personne'"""),
  1477 WHERE appears0.word_id IN (SELECT word_id FROM word WHERE word in ('toto', 'tata')) AND appears0.uid=X.eid AND X.type='Personne'"""),
  1560 
  1478 
  1561             ('Any X WHERE X has_text "toto tata", X name "tutu", X is IN (Basket,File,Folder)',
  1479             ('Any X WHERE X has_text "toto tata", X name "tutu", X is IN (Basket,Folder)',
  1562              """SELECT X.cw_eid
  1480              """SELECT X.cw_eid
  1563 FROM appears AS appears0, cw_Basket AS X
  1481 FROM appears AS appears0, cw_Basket AS X
  1564 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
       
  1565 UNION ALL
       
  1566 SELECT X.cw_eid
       
  1567 FROM appears AS appears0, cw_File AS X
       
  1568 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
  1482 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
  1569 UNION ALL
  1483 UNION ALL
  1570 SELECT X.cw_eid
  1484 SELECT X.cw_eid
  1571 FROM appears AS appears0, cw_Folder AS X
  1485 FROM appears AS appears0, cw_Folder AS X
  1572 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
  1486 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
  1617 WHERE MATCH (appears0.words) AGAINST ('toto tata' IN BOOLEAN MODE) AND appears0.uid=X.eid AND X.type='Personne'"""),
  1531 WHERE MATCH (appears0.words) AGAINST ('toto tata' IN BOOLEAN MODE) AND appears0.uid=X.eid AND X.type='Personne'"""),
  1618             ('Personne X WHERE X has_text %(text)s',
  1532             ('Personne X WHERE X has_text %(text)s',
  1619              """SELECT X.eid
  1533              """SELECT X.eid
  1620 FROM appears AS appears0, entities AS X
  1534 FROM appears AS appears0, entities AS X
  1621 WHERE MATCH (appears0.words) AGAINST ('hip hop momo' IN BOOLEAN MODE) AND appears0.uid=X.eid AND X.type='Personne'"""),
  1535 WHERE MATCH (appears0.words) AGAINST ('hip hop momo' IN BOOLEAN MODE) AND appears0.uid=X.eid AND X.type='Personne'"""),
  1622             ('Any X WHERE X has_text "toto tata", X name "tutu", X is IN (Basket,File,Folder)',
  1536             ('Any X WHERE X has_text "toto tata", X name "tutu", X is IN (Basket,Folder)',
  1623              """SELECT X.cw_eid
  1537              """SELECT X.cw_eid
  1624 FROM appears AS appears0, cw_Basket AS X
  1538 FROM appears AS appears0, cw_Basket AS X
  1625 WHERE MATCH (appears0.words) AGAINST ('toto tata' IN BOOLEAN MODE) AND appears0.uid=X.cw_eid AND X.cw_name=tutu
       
  1626 UNION ALL
       
  1627 SELECT X.cw_eid
       
  1628 FROM appears AS appears0, cw_File AS X
       
  1629 WHERE MATCH (appears0.words) AGAINST ('toto tata' IN BOOLEAN MODE) AND appears0.uid=X.cw_eid AND X.cw_name=tutu
  1539 WHERE MATCH (appears0.words) AGAINST ('toto tata' IN BOOLEAN MODE) AND appears0.uid=X.cw_eid AND X.cw_name=tutu
  1630 UNION ALL
  1540 UNION ALL
  1631 SELECT X.cw_eid
  1541 SELECT X.cw_eid
  1632 FROM appears AS appears0, cw_Folder AS X
  1542 FROM appears AS appears0, cw_Folder AS X
  1633 WHERE MATCH (appears0.words) AGAINST ('toto tata' IN BOOLEAN MODE) AND appears0.uid=X.cw_eid AND X.cw_name=tutu
  1543 WHERE MATCH (appears0.words) AGAINST ('toto tata' IN BOOLEAN MODE) AND appears0.uid=X.cw_eid AND X.cw_name=tutu