summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2011-08-23 03:38:28 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2011-08-23 03:38:28 +0000
commitc3a0dcf6e9e7859a4a990954cbab0a44e7cb1307 (patch)
tree73f8e5992c6b3766a365b51af632e337b855e678
parent0686c6b0ee7e6099cdcc48317d2649dc19dc89c9 (diff)
Added convenience method for viewing Query SQL without params.
This is the old Query.as_sql() method revived: it's like Query.__str__, but the parameters aren't substituted into the placeholders. Thus, it's a more accurate representation of the SQL the (default) backend will see. Entirely internal. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16655 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/db/models/sql/query.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index d906cb1132..fd2e7a6d9a 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -156,14 +156,21 @@ class Query(object):
def __str__(self):
"""
Returns the query as a string of SQL with the parameter values
- substituted in.
+ substituted in (use sql_with_params() to see the unsubstituted string).
Parameter values won't necessarily be quoted correctly, since that is
done by the database interface at execution time.
"""
- sql, params = self.get_compiler(DEFAULT_DB_ALIAS).as_sql()
+ sql, params = self.sql_with_params()
return sql % params
+ def sql_with_params(self):
+ """
+ Returns the query as an SQL string and the parameters that will be
+ subsituted into the query.
+ """
+ return self.get_compiler(DEFAULT_DB_ALIAS).as_sql()
+
def __deepcopy__(self, memo):
result = self.clone(memo=memo)
memo[id(self)] = result