Ticket #17644: ticket17644.diff

File ticket17644.diff, 2.6 KB (added by Łukasz Rekucki, 13 years ago)
  • django/db/models/sql/query.py

    diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
    index ed2bc06..dbac57b 100644
    a b from django.core.exceptions import FieldError  
    2727
    2828__all__ = ['Query', 'RawQuery']
    2929
     30try:
     31    from collections import namedtuple
     32except ImportError:
     33    # Python < 2.6
     34    JoinExpr = tuple
     35else:
     36    _JoinExpr = namedtuple("_JoinExpr",
     37        # This basicaly describes the following SQL expression:
     38        #
     39        #  {join_type} JOIN {table_name} [AS {rhs_alias}]
     40        #    ON ({lhs_alias}.{lhs_join_col} = {rhs_alias}.{rhs_join_col})
     41        #
     42        "table_name,"  # Original table_name as in Query.tables
     43        "rhs_alias,"
     44        "join_type,"  # INNER, OUTER or None (= base table, not really being joined)
     45        "lhs_alias,"
     46        "lhs_join_col,"
     47        "rhs_join_col,"
     48        # Can the right hand values be NULL ? This is used in promote_alias()
     49        # to check if INNER JOIN should be promoted to OUTER JOIN
     50        "nullable,"
     51    )
     52    JoinExpr = _JoinExpr._make
     53
     54
    3055class RawQuery(object):
    3156    """
    3257    A single raw SQL query
    class Query(object):  
    696721                self.alias_map[alias][JOIN_TYPE] != self.LOUTER):
    697722            data = list(self.alias_map[alias])
    698723            data[JOIN_TYPE] = self.LOUTER
    699             self.alias_map[alias] = tuple(data)
     724            self.alias_map[alias] = JoinExpr(data)
    700725            return True
    701726        return False
    702727
    class Query(object):  
    781806            del self.rev_join_map[old_alias]
    782807            self.alias_refcount[new_alias] = self.alias_refcount[old_alias]
    783808            del self.alias_refcount[old_alias]
    784             self.alias_map[new_alias] = tuple(alias_data)
     809            self.alias_map[new_alias] = JoinExpr(alias_data)
    785810            del self.alias_map[old_alias]
    786811
    787812            table_aliases = self.table_map[alias_data[TABLE_NAME]]
    class Query(object):  
    803828            if lhs in change_map:
    804829                data = list(data)
    805830                data[LHS_ALIAS] = change_map[lhs]
    806                 self.alias_map[alias] = tuple(data)
     831                self.alias_map[alias] = JoinExpr(data)
    807832
    808833    def bump_prefix(self, exceptions=()):
    809834        """
    class Query(object):  
    920945            join_type = self.LOUTER
    921946        else:
    922947            join_type = self.INNER
    923         join = (table, alias, join_type, lhs, lhs_col, col, nullable)
     948        join = JoinExpr((table, alias, join_type, lhs, lhs_col, col, nullable))
    924949        self.alias_map[alias] = join
    925950        if t_ident in self.join_map:
    926951            self.join_map[t_ident] += (alias,)
Back to Top