mirror of
https://github.com/django/django.git
synced 2025-07-05 18:29:11 +00:00
[soc2009/multidb] Removed the as_sql_takes_connection option from various classes, it was originally just to allow the tests to pass while the code base was being migrated, it was not meant to remain
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/multidb@11075 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
99fdf66600
commit
64eec4a120
@ -132,7 +132,7 @@ class QueryWrapper(object):
|
|||||||
def __init__(self, sql, params):
|
def __init__(self, sql, params):
|
||||||
self.data = sql, params
|
self.data = sql, params
|
||||||
|
|
||||||
def as_sql(self, qn=None):
|
def as_sql(self, qn=None, connection=None):
|
||||||
return self.data
|
return self.data
|
||||||
|
|
||||||
class Q(tree.Node):
|
class Q(tree.Node):
|
||||||
|
@ -21,7 +21,6 @@ class Aggregate(object):
|
|||||||
is_ordinal = False
|
is_ordinal = False
|
||||||
is_computed = False
|
is_computed = False
|
||||||
sql_template = '%(function)s(%(field)s)'
|
sql_template = '%(function)s(%(field)s)'
|
||||||
as_sql_takes_connection = True
|
|
||||||
|
|
||||||
def __init__(self, col, source=None, is_summary=False, **extra):
|
def __init__(self, col, source=None, is_summary=False, **extra):
|
||||||
"""Instantiate an SQL aggregate
|
"""Instantiate an SQL aggregate
|
||||||
@ -77,10 +76,7 @@ class Aggregate(object):
|
|||||||
"Return the aggregate, rendered as SQL."
|
"Return the aggregate, rendered as SQL."
|
||||||
|
|
||||||
if hasattr(self.col, 'as_sql'):
|
if hasattr(self.col, 'as_sql'):
|
||||||
if getattr(self.col, 'as_sql_takes_connection', False):
|
|
||||||
field_name = self.col.as_sql(qn, connection)
|
field_name = self.col.as_sql(qn, connection)
|
||||||
else:
|
|
||||||
field_name = self.col.as_sql(qn)
|
|
||||||
elif isinstance(self.col, (list, tuple)):
|
elif isinstance(self.col, (list, tuple)):
|
||||||
field_name = '.'.join([qn(c) for c in self.col])
|
field_name = '.'.join([qn(c) for c in self.col])
|
||||||
else:
|
else:
|
||||||
|
@ -29,8 +29,6 @@ class Date(object):
|
|||||||
"""
|
"""
|
||||||
Add a date selection column.
|
Add a date selection column.
|
||||||
"""
|
"""
|
||||||
as_sql_takes_connection = True
|
|
||||||
|
|
||||||
def __init__(self, col, lookup_type):
|
def __init__(self, col, lookup_type):
|
||||||
self.col = col
|
self.col = col
|
||||||
self.lookup_type = lookup_type
|
self.lookup_type = lookup_type
|
||||||
|
@ -3,8 +3,6 @@ from django.db.models.fields import FieldDoesNotExist
|
|||||||
from django.db.models.sql.constants import LOOKUP_SEP
|
from django.db.models.sql.constants import LOOKUP_SEP
|
||||||
|
|
||||||
class SQLEvaluator(object):
|
class SQLEvaluator(object):
|
||||||
as_sql_takes_connection = True
|
|
||||||
|
|
||||||
def __init__(self, expression, query, allow_joins=True):
|
def __init__(self, expression, query, allow_joins=True):
|
||||||
self.expression = expression
|
self.expression = expression
|
||||||
self.opts = query.get_meta()
|
self.opts = query.get_meta()
|
||||||
@ -78,9 +76,6 @@ class SQLEvaluator(object):
|
|||||||
def evaluate_leaf(self, node, qn, connection):
|
def evaluate_leaf(self, node, qn, connection):
|
||||||
col = self.cols[node]
|
col = self.cols[node]
|
||||||
if hasattr(col, 'as_sql'):
|
if hasattr(col, 'as_sql'):
|
||||||
if getattr(col, 'as_sql_takes_connection', False):
|
|
||||||
return col.as_sql(qn, connection), ()
|
return col.as_sql(qn, connection), ()
|
||||||
else:
|
|
||||||
return col.as_sql(qn)
|
|
||||||
else:
|
else:
|
||||||
return '%s.%s' % (qn(col[0]), qn(col[1])), ()
|
return '%s.%s' % (qn(col[0]), qn(col[1])), ()
|
||||||
|
@ -729,10 +729,7 @@ class BaseQuery(object):
|
|||||||
aliases.add(r)
|
aliases.add(r)
|
||||||
col_aliases.add(col[1])
|
col_aliases.add(col[1])
|
||||||
else:
|
else:
|
||||||
if getattr(col, 'as_sql_takes_connection', False):
|
|
||||||
result.append(col.as_sql(qn, self.connection))
|
result.append(col.as_sql(qn, self.connection))
|
||||||
else:
|
|
||||||
result.append(col.as_sql(qn))
|
|
||||||
|
|
||||||
if hasattr(col, 'alias'):
|
if hasattr(col, 'alias'):
|
||||||
aliases.add(col.alias)
|
aliases.add(col.alias)
|
||||||
|
@ -144,10 +144,7 @@ class UpdateQuery(Query):
|
|||||||
values, update_params = [], []
|
values, update_params = [], []
|
||||||
for name, val, placeholder in self.values:
|
for name, val, placeholder in self.values:
|
||||||
if hasattr(val, 'as_sql'):
|
if hasattr(val, 'as_sql'):
|
||||||
if getattr(val, 'as_sql_takes_connection', False):
|
|
||||||
sql, params = val.as_sql(qn, self.connection)
|
sql, params = val.as_sql(qn, self.connection)
|
||||||
else:
|
|
||||||
sql, params = val.as_sql(qn)
|
|
||||||
values.append('%s = %s' % (qn(name), sql))
|
values.append('%s = %s' % (qn(name), sql))
|
||||||
update_params.extend(params)
|
update_params.extend(params)
|
||||||
elif val is not None:
|
elif val is not None:
|
||||||
@ -421,7 +418,6 @@ class AggregateQuery(Query):
|
|||||||
An AggregateQuery takes another query as a parameter to the FROM
|
An AggregateQuery takes another query as a parameter to the FROM
|
||||||
clause and only selects the elements in the provided list.
|
clause and only selects the elements in the provided list.
|
||||||
"""
|
"""
|
||||||
as_sql_takes_connection = True
|
|
||||||
|
|
||||||
def add_subquery(self, query):
|
def add_subquery(self, query):
|
||||||
self.subquery, self.sub_params = query.as_sql(with_col_aliases=True)
|
self.subquery, self.sub_params = query.as_sql(with_col_aliases=True)
|
||||||
|
@ -32,7 +32,6 @@ class WhereNode(tree.Node):
|
|||||||
relabel_aliases() methods.
|
relabel_aliases() methods.
|
||||||
"""
|
"""
|
||||||
default = AND
|
default = AND
|
||||||
as_sql_takes_connection = True
|
|
||||||
|
|
||||||
def add(self, data, connector):
|
def add(self, data, connector):
|
||||||
"""
|
"""
|
||||||
@ -89,10 +88,7 @@ class WhereNode(tree.Node):
|
|||||||
for child in self.children:
|
for child in self.children:
|
||||||
try:
|
try:
|
||||||
if hasattr(child, 'as_sql'):
|
if hasattr(child, 'as_sql'):
|
||||||
if getattr(child, 'as_sql_takes_connection', False):
|
|
||||||
sql, params = child.as_sql(qn=qn, connection=connection)
|
sql, params = child.as_sql(qn=qn, connection=connection)
|
||||||
else:
|
|
||||||
sql, params = child.as_sql(qn=qn)
|
|
||||||
else:
|
else:
|
||||||
# A leaf node in the tree.
|
# A leaf node in the tree.
|
||||||
sql, params = self.make_atom(child, qn, connection)
|
sql, params = self.make_atom(child, qn, connection)
|
||||||
@ -152,11 +148,7 @@ class WhereNode(tree.Node):
|
|||||||
field_sql = self.sql_for_columns(lvalue, qn, connection)
|
field_sql = self.sql_for_columns(lvalue, qn, connection)
|
||||||
else:
|
else:
|
||||||
# A smart object with an as_sql() method.
|
# A smart object with an as_sql() method.
|
||||||
if getattr(lvalue, 'as_sql_takes_connection', False):
|
|
||||||
field_sql = lvalue.as_sql(qn, connection)
|
field_sql = lvalue.as_sql(qn, connection)
|
||||||
else:
|
|
||||||
field_sql = lvalue.as_sql(qn)
|
|
||||||
|
|
||||||
|
|
||||||
if value_annot is datetime.datetime:
|
if value_annot is datetime.datetime:
|
||||||
cast_sql = connection.ops.datetime_cast_sql()
|
cast_sql = connection.ops.datetime_cast_sql()
|
||||||
@ -164,10 +156,7 @@ class WhereNode(tree.Node):
|
|||||||
cast_sql = '%s'
|
cast_sql = '%s'
|
||||||
|
|
||||||
if hasattr(params, 'as_sql'):
|
if hasattr(params, 'as_sql'):
|
||||||
if getattr(params, 'as_sql_takes_connection', False):
|
|
||||||
extra, params = params.as_sql(qn, connection)
|
extra, params = params.as_sql(qn, connection)
|
||||||
else:
|
|
||||||
extra, params = params.as_sql(qn)
|
|
||||||
cast_sql = ''
|
cast_sql = ''
|
||||||
else:
|
else:
|
||||||
extra = ''
|
extra = ''
|
||||||
@ -242,7 +231,8 @@ class EverythingNode(object):
|
|||||||
"""
|
"""
|
||||||
A node that matches everything.
|
A node that matches everything.
|
||||||
"""
|
"""
|
||||||
def as_sql(self, qn=None):
|
|
||||||
|
def as_sql(self, qn=None, connection=None):
|
||||||
raise FullResultSet
|
raise FullResultSet
|
||||||
|
|
||||||
def relabel_aliases(self, change_map, node=None):
|
def relabel_aliases(self, change_map, node=None):
|
||||||
@ -252,7 +242,7 @@ class NothingNode(object):
|
|||||||
"""
|
"""
|
||||||
A node that matches nothing.
|
A node that matches nothing.
|
||||||
"""
|
"""
|
||||||
def as_sql(self, qn=None):
|
def as_sql(self, qn=None, connection=None):
|
||||||
raise EmptyResultSet
|
raise EmptyResultSet
|
||||||
|
|
||||||
def relabel_aliases(self, change_map, node=None):
|
def relabel_aliases(self, change_map, node=None):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user