server/rqlannotation.py
branchstable
changeset 8342 7a5271182ef0
parent 7734 59fea81647e5
child 9361 0542a85fe667
equal deleted inserted replaced
8341:af813e7d5daa 8342:7a5271182ef0
     1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     1 # copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     3 #
     3 #
     4 # This file is part of CubicWeb.
     4 # This file is part of CubicWeb.
     5 #
     5 #
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
    26 from rql import BadRQLQuery
    26 from rql import BadRQLQuery
    27 from rql.nodes import Relation, VariableRef, Constant, Variable, Or, Exists
    27 from rql.nodes import Relation, VariableRef, Constant, Variable, Or, Exists
    28 from rql.utils import common_parent
    28 from rql.utils import common_parent
    29 
    29 
    30 def _annotate_select(annotator, rqlst):
    30 def _annotate_select(annotator, rqlst):
       
    31     has_text_query = False
    31     for subquery in rqlst.with_:
    32     for subquery in rqlst.with_:
    32         annotator._annotate_union(subquery.query)
    33         if annotator._annotate_union(subquery.query):
       
    34             has_text_query = True
    33     #if server.DEBUG:
    35     #if server.DEBUG:
    34     #    print '-------- sql annotate', repr(rqlst)
    36     #    print '-------- sql annotate', repr(rqlst)
    35     getrschema = annotator.schema.rschema
    37     getrschema = annotator.schema.rschema
    36     has_text_query = False
       
    37     need_distinct = rqlst.distinct
    38     need_distinct = rqlst.distinct
    38     for rel in rqlst.iget_nodes(Relation):
    39     for rel in rqlst.iget_nodes(Relation):
    39         if getrschema(rel.r_type).symmetric and not isinstance(rel.parent, Exists):
    40         if getrschema(rel.r_type).symmetric and not isinstance(rel.parent, Exists):
    40             for vref in rel.iget_nodes(VariableRef):
    41             for vref in rel.iget_nodes(VariableRef):
    41                 stinfo = vref.variable.stinfo
    42                 stinfo = vref.variable.stinfo
   152                     # rhs variable's scope (since it's retrieved from lhs's table)
   153                     # rhs variable's scope (since it's retrieved from lhs's table)
   153                     sstinfo = principal.children[0].variable.stinfo
   154                     sstinfo = principal.children[0].variable.stinfo
   154                     sstinfo['scope'] = common_parent(sstinfo['scope'], stinfo['scope']).scope
   155                     sstinfo['scope'] = common_parent(sstinfo['scope'], stinfo['scope']).scope
   155             except CantSelectPrincipal:
   156             except CantSelectPrincipal:
   156                 stinfo['invariant'] = False
   157                 stinfo['invariant'] = False
       
   158     # see unittest_rqlannotation. test_has_text_security_cache_bug
       
   159     # XXX probably more to do, but yet that work without more...
       
   160     for col_alias in rqlst.aliases.itervalues():
       
   161         if col_alias.stinfo.get('ftirels'):
       
   162             has_text_query = True
   157     rqlst.need_distinct = need_distinct
   163     rqlst.need_distinct = need_distinct
   158     return has_text_query
   164     return has_text_query
   159 
   165 
   160 
   166 
   161 
   167 
   270         rqlst.has_text_query = self._annotate_union(rqlst)
   276         rqlst.has_text_query = self._annotate_union(rqlst)
   271 
   277 
   272     def _annotate_union(self, union):
   278     def _annotate_union(self, union):
   273         has_text_query = False
   279         has_text_query = False
   274         for select in union.children:
   280         for select in union.children:
   275             htq = _annotate_select(self, select)
   281             if _annotate_select(self, select):
   276             if htq:
       
   277                 has_text_query = True
   282                 has_text_query = True
   278         return has_text_query
   283         return has_text_query
   279 
   284 
   280     def is_ambiguous(self, var):
   285     def is_ambiguous(self, var):
   281         # ignore has_text relation when we know it will be used as principal.
   286         # ignore has_text relation when we know it will be used as principal.