Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #473 -- Added a MysqlDebugWrapper to use for MySQL with DEBUG=T…

…rue. It displays more informative error messages for MySQL warnings. Thanks for the patch, mlambert@gmail.com

git-svn-id: http://code.djangoproject.com/svn/django/trunk@806 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit a933432a708e77437706051f9e80b05fdf602aee 1 parent b63abf0
@adrianholovaty adrianholovaty authored
Showing with 27 additions and 1 deletion.
  1. +27 −1 django/core/db/backends/mysql.py
View
28 django/core/db/backends/mysql.py
@@ -21,6 +21,32 @@
FIELD_TYPE.TIME: typecasts.typecast_time,
})
+# This is an extra debug layer over MySQL queries, to display warnings.
+# It's only used when DEBUG=True.
+class MysqlDebugWrapper:
+ def __init__(self, cursor):
+ self.cursor = cursor
+
+ def execute(self, sql, params=()):
+ try:
+ return self.cursor.execute(sql, params)
+ except Database.Warning, w:
+ self.cursor.execute("SHOW WARNINGS")
+ raise Database.Warning, "%s: %s" % (w, self.cursor.fetchall())
+
+ def executemany(self, sql, param_list):
+ try:
+ return self.cursor.executemany(sql, param_list)
+ except Database.Warning:
+ self.cursor.execute("SHOW WARNINGS")
+ raise Database.Warning, "%s: %s" % (w, self.cursor.fetchall())
+
+ def __getattr__(self, attr):
+ if self.__dict__.has_key(attr):
+ return self.__dict__[attr]
+ else:
+ return getattr(self.cursor, attr)
+
class DatabaseWrapper:
def __init__(self):
self.connection = None
@@ -32,7 +58,7 @@ def cursor(self):
self.connection = Database.connect(user=DATABASE_USER, db=DATABASE_NAME,
passwd=DATABASE_PASSWORD, host=DATABASE_HOST, conv=django_conversions)
if DEBUG:
- return base.CursorDebugWrapper(self.connection.cursor(), self)
+ return base.CursorDebugWrapper(MysqlDebugWrapper(self.connection.cursor()), self)
return self.connection.cursor()
def commit(self):
Please sign in to comment.
Something went wrong with that request. Please try again.