Django

Code

Ticket #473 (closed: fixed)

Opened 3 years ago

Last modified 2 years ago

Make MySQL warnings more informative

Reported by: mlambert@gmail.com Assigned to: adrian
Milestone: Component: Database layer (models, ORM)
Version: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

mysql.diff (1.6 kB) - added by mlambert@gmail.com on 09/07/05 17:39:43.
unified diff file

Change History

09/07/05 17:23:30 changed by mlambert@gmail.com

Oh wow the formatting on the above sucks.

Will upload a diff...

09/07/05 17:39:43 changed by mlambert@gmail.com

  • attachment mysql.diff added.

unified diff file

09/26/05 23:39:22 changed by adrian

  • status changed from new to assigned.

10/08/05 16:00:25 changed by adrian

  • status changed from assigned to closed.
  • resolution set to fixed.

(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@gmail.com


Add/Change #473 (Make MySQL warnings more informative)




Change Properties
Action