Created
June 4, 2013 12:46
-
-
Save babo/5705621 to your computer and use it in GitHub Desktop.
print raw sql queries from django
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db.backends import util, BaseDatabaseWrapper | |
class LoggingCursorWrapper(util.CursorDebugWrapper): | |
def execute(self, sql, *args): | |
print sql | |
return super(LoggingCursorWrapper, self).execute(sql, *args) if self.cursor.__class__ == util.CursorDebugWrapper else self.cursor.execute(sql, *args) | |
def create_wrapper_factory(old_cursor): | |
def cursor(self, *args, **kwargs): | |
return LoggingCursorWrapper(old_cursor(self, *args, **kwargs), self) | |
return cursor | |
def show_sql(): | |
BaseDatabaseWrapper.cursor = create_wrapper_factory(BaseDatabaseWrapper.cursor) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment