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