Compare Pastes
Welcome On LodgeIt
Welcome to the LodgeIt pastebin. In order to use the notification feature a 31 day cookie with an unique ID was created for you. The lodgeit database does not store any information about you, it's just used for an advanced pastebin experience :-). Read more on the about lodgeit page. Have fun :-)
Differences between the pastes #4100 (2007-09-21 @ 12:03) and #4579 (2007-09-26 @ 13:04). Download as unified diff.
| 1 | 1 | Index: ./django/db/backends/mysql_old/base.py |
|---|---|---|
| 2 | 2 | =================================================================== |
| 3 | --- ./django/db/backends/mysql_old/base.py (revision 6 |
|
| 3 | --- ./django/db/backends/mysql_old/base.py (revision 6426) | |
| 4 | 4 | +++ ./django/db/backends/mysql_old/base.py (working copy) |
| 5 | 5 | @@ -37,12 +37,19 @@ |
| 6 | 6 | # http://dev.mysql.com/doc/refman/5.0/en/news.html . |
| 7 | 7 | server_version_re = re.compile(r'(\d{1,2})\.(\d{1,2})\.(\d{1,2})') |
| ... | ||
| 24 | 24 | +class MysqlDebugWrapper(MysqlWrapper): |
| 25 | 25 | def execute(self, sql, params=()): |
| 26 | 26 | try: |
| 27 | 27 | return self.cursor.execute(sql, params) |
| 28 | @@ -57,11 +64, |
|
| 28 | @@ -57,11 +64,46 @@ | |
| 29 | 29 | self.cursor.execute("SHOW WARNINGS") |
| 30 | 30 | raise Database.Warning("%s: %s" % (w, self.cursor.fetchall())) |
| 31 | 31 | |
| 32 | 32 | - def __getattr__(self, attr): |
| ... | ||
| 34 | 34 | - return self.__dict__[attr] |
| 35 | 35 | - else: |
| 36 | 36 | - return getattr(self.cursor, attr) |
| 37 | 37 | +class MysqlUnicodeWrapper(MysqlWrapper): |
| 38 | + def __init__(self, cursor): | |
| 39 | + self.cursor = cursor | |
| 38 | 40 | + |
| 39 | 41 | + def _decode_results(self, result_raw): |
| 40 | 42 | + """ |
| 41 | 43 | + decode all byte string to unicode with the server encoding. |
| 42 | 44 | + """ |
| 45 | + if not result_raw: | |
| 46 | + return result_raw | |
| 43 | 47 | + result = [] |
| 44 | 48 | + for item in result_raw: |
| 45 | 49 | + if isinstance(item, str): |
| 46 | 50 | + item = item.decode(self.cursor.server_encoding) |
| 47 | 51 | + result.append(item) |
| 52 | + | |
| 53 | + return tuple(result) | |
| 54 | + | |
| 55 | + def _decode_lines(self, result_raw): | |
| 56 | + """ | |
| 57 | + decode every line in a resultset. | |
| 58 | + """ | |
| 59 | + result = [] | |
| 60 | + for line in result_raw: | |
| 61 | + result.append(self._decode_results(line)) | |
| 48 | 62 | + return tuple(result) |
| 49 | 63 | + |
| 50 | 64 | + def fetchone(self): |
| 51 | 65 | + result_raw = self.cursor.fetchone() |
| 52 | 66 | + return self._decode_results(result_raw) |
| 53 | 67 | + |
| 54 | 68 | + def fetchall(self): |
| 55 | 69 | + result_raw = self.cursor.fetchall() |
| 56 | + result = [] | |
| 57 | + for line in result_raw: | |
| 58 | + result.append(self._decode_results(line)) | |
| 59 | + return tuple(result) | |
| 70 | + return self._decode_lines(result_raw) | |
| 71 | + | |
| 72 | + def fetchmany(self, *args): | |
| 73 | + result_raw = self.cursor.fetchmany(*args) | |
| 74 | + return self._decode_lines(result_raw) | |
| 75 | + return result_raw | |
| 60 | 76 | + |
| 61 | 77 | |
| 62 | 78 | class DatabaseFeatures(BaseDatabaseFeatures): |
| 63 | 79 | autoindexes_primary_keys = False |
| 64 | @@ -193, |
|
| 80 | @@ -193,10 +235,16 @@ | |
| 65 | 81 | self.connection.set_character_set('utf8') |
| 66 | 82 | else: |
| 67 | 83 | cursor = self.connection.cursor() |
| 68 | 84 | - return cursor |
| ... | ||
| 72 | 88 | + |
| 73 | 89 | + return MysqlUnicodeWrapper(cursor) |
| 74 | 90 | |
| 75 | 91 | def make_debug_cursor(self, cursor): |
| 76 | ||
| 92 | - return BaseDatabaseWrapper.make_debug_cursor(self, MysqlDebugWrapper(cursor)) | |
| 93 | + cursor = MysqlDebugWrapper(cursor) | |
| 94 | + cursor = MysqlUnicodeWrapper(cursor) | |
| 95 | + return BaseDatabaseWrapper.make_debug_cursor(self, cursor) | |
| 96 | ||
| 97 | def _rollback(self): | |
| 98 | try: | |