﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
473	Make MySQL warnings more informative	mlambert@…	Adrian Holovaty	"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)
"	enhancement	closed	Database layer (models, ORM)		normal	fixed			Unreviewed	0	0	0	0	0	0
