def as_sql(self):
distinct = '<STR_LIT>' if self._distinct else '<STR_LIT>'<EOL>final = '<STR_LIT>' if self._final else '<STR_LIT>'<EOL>params = (distinct, self.select_fields_as_sql(), self._model_cls.table_name(), final)<EOL>sql = u'<STR_LIT>' % params<EOL>if self._prewhere_q and not self._prewhere_q.is_empty:<EOL><INDENT>sql += '<STR_LIT>' + self.conditions_as_sql(prewhere=True)<EOL><DEDENT>if self._where_q and not self._where_q.is_empty:<EOL><INDENT>sql += '<STR_LIT>' + self.conditions_as_sql(prewhere=False)<EOL><DEDENT>if self._grouping_fields:<EOL><INDENT>sql += '<STR_LIT>' % comma_join('<STR_LIT>' % field for field in self._grouping_fields)<EOL>if self._grouping_with_totals:<EOL><INDENT>sql += '<STR_LIT>'<EOL><DEDENT><DEDENT>if self._order_by:<EOL><INDENT>sql += '<STR_LIT>' + self.order_by_as_sql()<EOL><DEDENT>if self._limits:<EOL><INDENT>sql += '<STR_LIT>' % self._limits<EOL><DEDENT>return sql<EOL>
Returns the whole query as a SQL string.