Django

Code

Changeset 806

Show
Ignore:
Timestamp:
10/08/05 16:00:25 (3 years ago)
Author:
adrian
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/db/backends/mysql.py

    r713 r806  
    2222}) 
    2323 
     24# This is an extra debug layer over MySQL queries, to display warnings. 
     25# It's only used when DEBUG=True. 
     26class MysqlDebugWrapper: 
     27    def __init__(self, cursor): 
     28        self.cursor = cursor 
     29 
     30    def execute(self, sql, params=()): 
     31        try: 
     32            return self.cursor.execute(sql, params) 
     33        except Database.Warning, w: 
     34            self.cursor.execute("SHOW WARNINGS") 
     35            raise Database.Warning, "%s: %s" % (w, self.cursor.fetchall()) 
     36 
     37    def executemany(self, sql, param_list): 
     38        try: 
     39            return self.cursor.executemany(sql, param_list) 
     40        except Database.Warning: 
     41            self.cursor.execute("SHOW WARNINGS") 
     42            raise Database.Warning, "%s: %s" % (w, self.cursor.fetchall()) 
     43 
     44    def __getattr__(self, attr): 
     45        if self.__dict__.has_key(attr): 
     46            return self.__dict__[attr] 
     47        else: 
     48            return getattr(self.cursor, attr) 
     49 
    2450class DatabaseWrapper: 
    2551    def __init__(self): 
     
    3359                passwd=DATABASE_PASSWORD, host=DATABASE_HOST, conv=django_conversions) 
    3460        if DEBUG: 
    35             return base.CursorDebugWrapper(self.connection.cursor(), self) 
     61            return base.CursorDebugWrapper(MysqlDebugWrapper(self.connection.cursor()), self) 
    3662        return self.connection.cursor() 
    3763