Sometimes when saving a record the data is slightly malformed and MySQL will raise an error. This code adds an extra debug wrapper layer for MySQL to make these warnings more informative.
In core/db/backends/mysql.py, add the following class:
class MysqlDebugWrapper?:
def init(self, cursor):
self.cursor = cursor
def execute(self, sql, params=[]):
try:
result = self.cursor.execute(sql, params)
except Database.Warning, w:
self.cursor.execute("show warnings")
raise Database.Warning, "%s: %s" % (w,self.cursor.fetchall())
return result
def executemany(self, sql, param_list):
try:
result = self.cursor.executemany(sql, param_list)
except Database.Warning:
self.cursor.execute("show warnings")
raise Database.Warning, "%s: %s" % (w,self.cursor.fetchall())
return result
def getattr(self, attr):
if self.dict.has_key(attr):
return self.dict[attr]
else:
return getattr(self.cursor, attr)
Then, in the same file, change:
return base.CursorDebugWrapper?(self.connection.cursor(), self)
to:
return base.CursorDebugWrapper?(MysqlDebugWrapper?(self.connection.cursor()), self)