Opened 19 years ago

Closed 19 years ago

Last modified 18 years ago

#473 closed enhancement (fixed)

Make MySQL warnings more informative

Reported by: mlambert@… Owned by: Adrian Holovaty
Component: Database layer (models, ORM) Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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)

Attachments (1)

mysql.diff (1.6 KB ) - added by mlambert@… 19 years ago.
unified diff file

Download all attachments as: .zip

Change History (4)

comment:1 by mlambert@…, 19 years ago

Oh wow the formatting on the above sucks.

Will upload a diff...

by mlambert@…, 19 years ago

Attachment: mysql.diff added

unified diff file

comment:2 by Adrian Holovaty, 19 years ago

Status: newassigned

comment:3 by Adrian Holovaty, 19 years ago

Resolution: fixed
Status: assignedclosed

(In [806]) 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@…

Note: See TracTickets for help on using tickets.
Back to Top