578 if rel in done: |
578 if rel in done: |
579 continue |
579 continue |
580 done.add(rel) |
580 done.add(rel) |
581 rschema = get_rschema(rel.r_type) |
581 rschema = get_rschema(rel.r_type) |
582 if rschema.final or rschema.inlined: |
582 if rschema.final or rschema.inlined: |
|
583 subselect_vrefs = [] |
583 rel.children[0].name = varname # XXX explain why |
584 rel.children[0].name = varname # XXX explain why |
584 subselect.add_restriction(rel.copy(subselect)) |
585 subselect.add_restriction(rel.copy(subselect)) |
585 for vref in rel.children[1].iget_nodes(n.VariableRef): |
586 for vref in rel.children[1].iget_nodes(n.VariableRef): |
586 if isinstance(vref.variable, n.ColumnAlias): |
587 if isinstance(vref.variable, n.ColumnAlias): |
587 # XXX could probably be handled by generating the |
588 # XXX could probably be handled by generating the |
590 "cant insert security because of usage two inlined " |
591 "cant insert security because of usage two inlined " |
591 "relations in this query. You should probably at " |
592 "relations in this query. You should probably at " |
592 "least uninline %s" % rel.r_type) |
593 "least uninline %s" % rel.r_type) |
593 subselect.append_selected(vref.copy(subselect)) |
594 subselect.append_selected(vref.copy(subselect)) |
594 aliases.append(vref.name) |
595 aliases.append(vref.name) |
|
596 subselect_vrefs.append(vref) |
595 self.select.remove_node(rel) |
597 self.select.remove_node(rel) |
596 # when some inlined relation has to be copied in the |
598 # when some inlined relation has to be copied in the |
597 # subquery and that relation is optional, we need to |
599 # subquery and that relation is optional, we need to |
598 # test that either value is NULL or that the snippet |
600 # test that either value is NULL or that the snippet |
599 # condition is satisfied |
601 # condition is satisfied |
600 if varname == selectvar and rel.optional and rschema.inlined: |
602 if varname == selectvar and rel.optional and rschema.inlined: |
601 need_null_test = True |
603 need_null_test = True |
602 # also, if some attributes or inlined relation of the |
604 # also, if some attributes or inlined relation of the |
603 # object variable are accessed, we need to get all those |
605 # object variable are accessed, we need to get all those |
604 # from the subquery as well |
606 # from the subquery as well |
605 if vref.name not in done and rschema.inlined: |
607 for vref in subselect_vrefs: |
606 # we can use vref here define in above for loop |
608 if vref.name not in done and rschema.inlined: |
607 ostinfo = vref.variable.stinfo |
609 # we can use vref here define in above for loop |
608 for orel in iter_relations(ostinfo): |
610 ostinfo = vref.variable.stinfo |
609 orschema = get_rschema(orel.r_type) |
611 for orel in iter_relations(ostinfo): |
610 if orschema.final or orschema.inlined: |
612 orschema = get_rschema(orel.r_type) |
611 todo.append( (vref.name, ostinfo) ) |
613 if orschema.final or orschema.inlined: |
612 break |
614 todo.append( (vref.name, ostinfo) ) |
|
615 break |
613 if need_null_test: |
616 if need_null_test: |
614 snippetrqlst = n.Or( |
617 snippetrqlst = n.Or( |
615 n.make_relation(subselect.get_variable(selectvar), 'is', |
618 n.make_relation(subselect.get_variable(selectvar), 'is', |
616 (None, None), n.Constant, |
619 (None, None), n.Constant, |
617 operator='='), |
620 operator='='), |