diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2005-10-08 21:00:25 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2005-10-08 21:00:25 +0000 |
| commit | a933432a708e77437706051f9e80b05fdf602aee (patch) | |
| tree | 844c2a1119589c0b9472003837dabecc1fe54ca7 | |
| parent | b63abf037943741db7c1958537ebe3233ed6d6ee (diff) | |
Fixed #473 -- Added a MysqlDebugWrapper to use for MySQL with DEBUG=True. 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
| -rw-r--r-- | django/core/db/backends/mysql.py | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/django/core/db/backends/mysql.py b/django/core/db/backends/mysql.py index e678740b33..2e77adbc43 100644 --- a/django/core/db/backends/mysql.py +++ b/django/core/db/backends/mysql.py @@ -21,6 +21,32 @@ django_conversions.update({ 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 @@ class DatabaseWrapper: 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): |
