server/sources/rql2sql.py
branchstable
changeset 6940 1172c25655b7
parent 6929 e9464d975908
child 7042 8bcf33c493f8
equal deleted inserted replaced
6939:8fa55cf2a8cb 6940:1172c25655b7
   989 
   989 
   990         attribute variables are used either in the selection or for
   990         attribute variables are used either in the selection or for
   991         unification (eg X attr1 A, Y attr2 A). In case of selection,
   991         unification (eg X attr1 A, Y attr2 A). In case of selection,
   992         nothing to do here.
   992         nothing to do here.
   993         """
   993         """
   994         contextrels = {}
       
   995         for var in rhs_vars:
   994         for var in rhs_vars:
   996             if var.name in self._varmap:
   995             if var.name in self._varmap:
   997                 # ensure table is added
   996                 # ensure table is added
   998                 self._var_info(var.variable)
   997                 self._var_info(var.variable)
   999             principal = var.variable.stinfo.get('principal')
   998             principal = var.variable.stinfo.get('principal')
  1000             if principal is not None and principal is not relation:
   999             if principal is not None and principal is not relation:
  1001                 contextrels[var.name] = relation
  1000                 # we have to generate unification expression
  1002         if not contextrels:
  1001                 lhssql = self._inlined_var_sql(relation.children[0].variable,
  1003             return ''
  1002                                                relation.r_type)
  1004         # we have to generate unification expression
  1003                 try:
  1005         lhssql = self._inlined_var_sql(relation.children[0].variable,
  1004                     self._state.ignore_varmap = True
  1006                                        relation.r_type)
  1005                     return '%s%s' % (lhssql, relation.children[1].accept(self))
  1007         try:
  1006                 finally:
  1008             self._state.ignore_varmap = True
  1007                     self._state.ignore_varmap = False
  1009             return '%s%s' % (lhssql, relation.children[1].accept(self))
  1008         return ''
  1010         finally:
       
  1011             self._state.ignore_varmap = False
       
  1012 
  1009 
  1013     def _visit_attribute_relation(self, rel):
  1010     def _visit_attribute_relation(self, rel):
  1014         """generate SQL for an attribute relation"""
  1011         """generate SQL for an attribute relation"""
  1015         lhs, rhs = rel.get_parts()
  1012         lhs, rhs = rel.get_parts()
  1016         rhssql = rhs.accept(self)
  1013         rhssql = rhs.accept(self)