Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
"""
|
|
|
|
Useful auxilliary data structures for query construction. Not useful outside
|
|
|
|
the SQL domain.
|
|
|
|
"""
|
|
|
|
|
2013-07-08 08:39:54 +08:00
|
|
|
|
2013-11-03 04:35:45 +08:00
|
|
|
class Col(object):
|
2014-01-18 17:09:43 +08:00
|
|
|
def __init__(self, alias, target, source):
|
|
|
|
self.alias, self.target, self.source = alias, target, source
|
2013-11-03 04:35:45 +08:00
|
|
|
|
|
|
|
def as_sql(self, qn, connection):
|
2014-01-18 17:09:43 +08:00
|
|
|
return "%s.%s" % (qn(self.alias), qn(self.target.column)), []
|
2013-11-03 04:35:45 +08:00
|
|
|
|
2014-01-18 17:09:43 +08:00
|
|
|
@property
|
|
|
|
def output_type(self):
|
|
|
|
return self.source
|
2013-11-03 04:35:45 +08:00
|
|
|
|
|
|
|
def relabeled_clone(self, relabels):
|
2014-01-18 17:09:43 +08:00
|
|
|
return self.__class__(relabels.get(self.alias, self.alias), self.target, self.source)
|
|
|
|
|
|
|
|
def get_group_by_cols(self):
|
|
|
|
return [(self.alias, self.target.column)]
|
|
|
|
|
|
|
|
def get_lookup(self, name):
|
|
|
|
return self.output_type.get_lookup(name)
|
|
|
|
|
2014-03-02 03:21:57 +08:00
|
|
|
def get_transform(self, name):
|
|
|
|
return self.output_type.get_transform(name)
|
|
|
|
|
2014-01-18 17:09:43 +08:00
|
|
|
def prepare(self):
|
|
|
|
return self
|
2013-11-03 04:35:45 +08:00
|
|
|
|
|
|
|
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
class EmptyResultSet(Exception):
|
|
|
|
pass
|
|
|
|
|
2013-07-08 08:39:54 +08:00
|
|
|
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
class MultiJoin(Exception):
|
|
|
|
"""
|
|
|
|
Used by join construction code to indicate the point at which a
|
|
|
|
multi-valued join was attempted (if the caller wants to treat that
|
|
|
|
exceptionally).
|
|
|
|
"""
|
2013-02-18 07:56:24 +08:00
|
|
|
def __init__(self, names_pos, path_with_names):
|
|
|
|
self.level = names_pos
|
|
|
|
# The path travelled, this includes the path to the multijoin.
|
|
|
|
self.names_with_path = path_with_names
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
|
2013-07-08 08:39:54 +08:00
|
|
|
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
class Empty(object):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class Date(object):
|
|
|
|
"""
|
|
|
|
Add a date selection column.
|
|
|
|
"""
|
2009-12-22 23:18:51 +08:00
|
|
|
def __init__(self, col, lookup_type):
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
self.col = col
|
|
|
|
self.lookup_type = lookup_type
|
|
|
|
|
2013-03-02 07:06:56 +08:00
|
|
|
def relabeled_clone(self, change_map):
|
|
|
|
return self.__class__((change_map.get(self.col[0], self.col[0]), self.col[1]))
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
|
2009-12-22 23:18:51 +08:00
|
|
|
def as_sql(self, qn, connection):
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
if isinstance(self.col, (list, tuple)):
|
2013-08-30 00:09:35 +08:00
|
|
|
col = '%s.%s' % tuple(qn(c) for c in self.col)
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
else:
|
|
|
|
col = self.col
|
2013-02-10 23:15:49 +08:00
|
|
|
return connection.ops.date_trunc_sql(self.lookup_type, col), []
|
|
|
|
|
2013-07-08 08:39:54 +08:00
|
|
|
|
2013-02-10 23:15:49 +08:00
|
|
|
class DateTime(object):
|
|
|
|
"""
|
|
|
|
Add a datetime selection column.
|
|
|
|
"""
|
|
|
|
def __init__(self, col, lookup_type, tzname):
|
|
|
|
self.col = col
|
|
|
|
self.lookup_type = lookup_type
|
|
|
|
self.tzname = tzname
|
|
|
|
|
2013-03-02 07:06:56 +08:00
|
|
|
def relabeled_clone(self, change_map):
|
|
|
|
return self.__class__((change_map.get(self.col[0], self.col[0]), self.col[1]))
|
2013-02-10 23:15:49 +08:00
|
|
|
|
|
|
|
def as_sql(self, qn, connection):
|
|
|
|
if isinstance(self.col, (list, tuple)):
|
2013-08-30 00:09:35 +08:00
|
|
|
col = '%s.%s' % tuple(qn(c) for c in self.col)
|
2013-02-10 23:15:49 +08:00
|
|
|
else:
|
|
|
|
col = self.col
|
|
|
|
return connection.ops.datetime_trunc_sql(self.lookup_type, col, self.tzname)
|