web/lib/django/db/models/sql/datastructures.py
changeset 0 0d40e90630ef
child 29 cc9b7e14412b
equal deleted inserted replaced
-1:000000000000 0:0d40e90630ef
       
     1 """
       
     2 Useful auxilliary data structures for query construction. Not useful outside
       
     3 the SQL domain.
       
     4 """
       
     5 
       
     6 class EmptyResultSet(Exception):
       
     7     pass
       
     8 
       
     9 class FullResultSet(Exception):
       
    10     pass
       
    11 
       
    12 class MultiJoin(Exception):
       
    13     """
       
    14     Used by join construction code to indicate the point at which a
       
    15     multi-valued join was attempted (if the caller wants to treat that
       
    16     exceptionally).
       
    17     """
       
    18     def __init__(self, level):
       
    19         self.level = level
       
    20 
       
    21 class Empty(object):
       
    22     pass
       
    23 
       
    24 class RawValue(object):
       
    25     def __init__(self, value):
       
    26         self.value = value
       
    27 
       
    28 class Date(object):
       
    29     """
       
    30     Add a date selection column.
       
    31     """
       
    32     def __init__(self, col, lookup_type, date_sql_func):
       
    33         self.col = col
       
    34         self.lookup_type = lookup_type
       
    35         self.date_sql_func = date_sql_func
       
    36 
       
    37     def relabel_aliases(self, change_map):
       
    38         c = self.col
       
    39         if isinstance(c, (list, tuple)):
       
    40             self.col = (change_map.get(c[0], c[0]), c[1])
       
    41 
       
    42     def as_sql(self, quote_func=None):
       
    43         if not quote_func:
       
    44             quote_func = lambda x: x
       
    45         if isinstance(self.col, (list, tuple)):
       
    46             col = '%s.%s' % tuple([quote_func(c) for c in self.col])
       
    47         else:
       
    48             col = self.col
       
    49         return self.date_sql_func(self.lookup_type, col)
       
    50