server/sources/rql2sql.py
branchstable
changeset 5706 c2e8290bc7b7
parent 5702 9fb240cf0f61
child 5768 1e73a466aa69
child 5782 8ff48d1a319f
equal deleted inserted replaced
5704:924ea48326c4 5706:c2e8290bc7b7
   740                     # if variable(s) in the RHS
   740                     # if variable(s) in the RHS
   741                     sql = self._visit_var_attr_relation(relation, rhs_vars)
   741                     sql = self._visit_var_attr_relation(relation, rhs_vars)
   742                 else:
   742                 else:
   743                     # no variables in the RHS
   743                     # no variables in the RHS
   744                     sql = self._visit_attribute_relation(relation)
   744                     sql = self._visit_attribute_relation(relation)
   745         else:
   745         elif (rtype == 'is' and isinstance(rhs.children[0], Constant)
   746             if rtype == 'is' and rhs.operator == 'IS':
   746               and rhs.children[0].eval(self._args) is None):
   747                 # special case "C is NULL"
   747             # special case "C is NULL"
   748                 if lhs.name in self._varmap:
   748             if lhs.name in self._varmap:
   749                     lhssql = self._varmap[lhs.name]
   749                 lhssql = self._varmap[lhs.name]
   750                 else:
       
   751                     lhssql = lhs.accept(self)
       
   752                 return '%s%s' % (lhssql, rhs.accept(self))
       
   753             if '%s.%s' % (lhs, relation.r_type) in self._varmap:
       
   754                 # relation has already been processed by a previous step
       
   755                 return
       
   756             if relation.optional:
       
   757                 # check it has not already been treaten (to get necessary
       
   758                 # information to add an outer join condition)
       
   759                 if relation in self._state.done:
       
   760                     return
       
   761                 # OPTIONAL relation, generate a left|right outer join
       
   762                 sql = self._visit_outer_join_relation(relation, rschema)
       
   763             elif rschema.inlined:
       
   764                 sql = self._visit_inlined_relation(relation)
       
   765             else:
   750             else:
   766                 # regular (non final) relation
   751                 lhssql = lhs.accept(self)
   767                 sql = self._visit_relation(relation, rschema)
   752             return '%s%s' % (lhssql, rhs.accept(self))
       
   753         elif '%s.%s' % (lhs, relation.r_type) in self._varmap:
       
   754             # relation has already been processed by a previous step
       
   755             return ''
       
   756         elif relation.optional:
       
   757             # check it has not already been treaten (to get necessary
       
   758             # information to add an outer join condition)
       
   759             if relation in self._state.done:
       
   760                 return ''
       
   761             # OPTIONAL relation, generate a left|right outer join
       
   762             sql = self._visit_outer_join_relation(relation, rschema)
       
   763         elif rschema.inlined:
       
   764             sql = self._visit_inlined_relation(relation)
       
   765         else:
       
   766             # regular (non final) relation
       
   767             sql = self._visit_relation(relation, rschema)
   768         return sql
   768         return sql
   769 
   769 
   770     def _visit_inlined_relation(self, relation):
   770     def _visit_inlined_relation(self, relation):
   771         lhsvar, _, rhsvar, rhsconst = relation_info(relation)
   771         lhsvar, _, rhsvar, rhsconst = relation_info(relation)
   772         # we are sure here to have a lhsvar
   772         # we are sure here to have a lhsvar