server/sources/rql2sql.py
changeset 9361 0542a85fe667
parent 9324 a5ce068143ad
child 9468 39b7a91a3f4c
child 9492 c7fc56eecd1a
equal deleted inserted replaced
9360:eda5071e30a1 9361:0542a85fe667
   240         rhs = None
   240         rhs = None
   241     except KeyError:
   241     except KeyError:
   242         rhsconst = None # ColumnAlias
   242         rhsconst = None # ColumnAlias
   243     return lhs, lhsconst, rhs, rhsconst
   243     return lhs, lhsconst, rhs, rhsconst
   244 
   244 
   245 def switch_relation_field(sql, table=''):
       
   246     switchedsql = sql.replace(table + '.eid_from', '__eid_from__')
       
   247     switchedsql = switchedsql.replace(table + '.eid_to',
       
   248                                       table + '.eid_from')
       
   249     return switchedsql.replace('__eid_from__', table + '.eid_to')
       
   250 
       
   251 def sort_term_selection(sorts, rqlst, groups):
   245 def sort_term_selection(sorts, rqlst, groups):
   252     # XXX beurk
   246     # XXX beurk
   253     if isinstance(rqlst, list):
   247     if isinstance(rqlst, list):
   254         def append(term):
   248         def append(term):
   255             rqlst.append(term)
   249             rqlst.append(term)
  1130         rid = self._state.relation_table(relation)
  1124         rid = self._state.relation_table(relation)
  1131         sqls = []
  1125         sqls = []
  1132         sqls += self._process_relation_term(relation, rid, lhsvar, lhsconst, 'eid_from')
  1126         sqls += self._process_relation_term(relation, rid, lhsvar, lhsconst, 'eid_from')
  1133         sqls += self._process_relation_term(relation, rid, rhsvar, rhsconst, 'eid_to')
  1127         sqls += self._process_relation_term(relation, rid, rhsvar, rhsconst, 'eid_to')
  1134         sql = ' AND '.join(sqls)
  1128         sql = ' AND '.join(sqls)
  1135         if rschema.symmetric:
       
  1136             sql = '(%s OR %s)' % (sql, switch_relation_field(sql))
       
  1137         return sql
  1129         return sql
  1138 
  1130 
  1139     def _visit_outer_join_relation(self, relation, rschema):
  1131     def _visit_outer_join_relation(self, relation, rschema):
  1140         """
  1132         """
  1141         left outer join syntax (optional=='right'):
  1133         left outer join syntax (optional=='right'):