58 towrap.add( (var, rel) ) |
58 towrap.add( (var, rel) ) |
59 for vref in rel.children[1].iget_nodes(VariableRef): |
59 for vref in rel.children[1].iget_nodes(VariableRef): |
60 newivar = _new_var(newselect, vref.name) |
60 newivar = _new_var(newselect, vref.name) |
61 newselect.selection.append(VariableRef(newivar)) |
61 newselect.selection.append(VariableRef(newivar)) |
62 _fill_to_wrap_rel(vref.variable, newselect, towrap, schema) |
62 _fill_to_wrap_rel(vref.variable, newselect, towrap, schema) |
63 elif rschema.is_final(): |
63 elif rschema.final: |
64 towrap.add( (var, rel) ) |
64 towrap.add( (var, rel) ) |
65 |
65 |
66 def rewrite_unstable_outer_join(select, solutions, unstable, schema): |
66 def rewrite_unstable_outer_join(select, solutions, unstable, schema): |
67 """if some optional variables are unstable, they should be selected in a |
67 """if some optional variables are unstable, they should be selected in a |
68 subquery. This function check this and rewrite the rql syntax tree if |
68 subquery. This function check this and rewrite the rql syntax tree if |
614 # don't care of type constraint statement (i.e. relation_type = 'is') |
614 # don't care of type constraint statement (i.e. relation_type = 'is') |
615 if relation.is_types_restriction(): |
615 if relation.is_types_restriction(): |
616 return '' |
616 return '' |
617 lhs, rhs = relation.get_parts() |
617 lhs, rhs = relation.get_parts() |
618 rschema = self.schema.rschema(rtype) |
618 rschema = self.schema.rschema(rtype) |
619 if rschema.is_final(): |
619 if rschema.final: |
620 if rtype == 'eid' and lhs.variable._q_invariant and \ |
620 if rtype == 'eid' and lhs.variable._q_invariant and \ |
621 lhs.variable.stinfo['constnode']: |
621 lhs.variable.stinfo['constnode']: |
622 # special case where this restriction is already generated by |
622 # special case where this restriction is already generated by |
623 # some other relation |
623 # some other relation |
624 return '' |
624 return '' |
1094 scope = self._varmap_table_scope(var.stmt, table) |
1094 scope = self._varmap_table_scope(var.stmt, table) |
1095 self.add_table(table, scope=scope) |
1095 self.add_table(table, scope=scope) |
1096 except KeyError: |
1096 except KeyError: |
1097 etype = self._state.solution[var.name] |
1097 etype = self._state.solution[var.name] |
1098 # XXX this check should be moved in rql.stcheck |
1098 # XXX this check should be moved in rql.stcheck |
1099 if self.schema.eschema(etype).is_final(): |
1099 if self.schema.eschema(etype).final: |
1100 raise BadRQLQuery(var.stmt.root) |
1100 raise BadRQLQuery(var.stmt.root) |
1101 table = var.name |
1101 table = var.name |
1102 sql = '%s.%seid' % (table, SQL_PREFIX) |
1102 sql = '%s.%seid' % (table, SQL_PREFIX) |
1103 self.add_table('%s%s AS %s' % (SQL_PREFIX, etype, table), table, |
1103 self.add_table('%s%s AS %s' % (SQL_PREFIX, etype, table), table, |
1104 scope=scope) |
1104 scope=scope) |
1209 |
1209 |
1210 def _relation_table(self, relation): |
1210 def _relation_table(self, relation): |
1211 """return the table alias used by the given relation""" |
1211 """return the table alias used by the given relation""" |
1212 if relation in self._state.done: |
1212 if relation in self._state.done: |
1213 return relation._q_sqltable |
1213 return relation._q_sqltable |
1214 assert not self.schema.rschema(relation.r_type).is_final(), relation.r_type |
1214 assert not self.schema.rschema(relation.r_type).final, relation.r_type |
1215 rid = 'rel_%s%s' % (relation.r_type, self._state.count) |
1215 rid = 'rel_%s%s' % (relation.r_type, self._state.count) |
1216 # relation's table is belonging to the root scope if it is the principal |
1216 # relation's table is belonging to the root scope if it is the principal |
1217 # table of one of it's variable and if that variable belong's to parent |
1217 # table of one of it's variable and if that variable belong's to parent |
1218 # scope |
1218 # scope |
1219 for varref in relation.iget_nodes(VariableRef): |
1219 for varref in relation.iget_nodes(VariableRef): |