| | 24 | # This is an extra debug layer over MySQL queries, to display warnings. |
|---|
| | 25 | # It's only used when DEBUG=True. |
|---|
| | 26 | class 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 | |
|---|