Changeset 1692 for CodeSnippets/django_backends_mysql_old/base.py
- Timestamp:
- 07/18/08 13:25:14 (20 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
CodeSnippets/django_backends_mysql_old/base.py
- Property svn:eol-style set to LF
r1337 r1692 3 3 4 4 Requires MySQLdb: http://sourceforge.net/projects/mysql-python 5 6 Patched svn revision 7852: 7 http://code.djangoproject.com/changeset/7852 8 http://code.djangoproject.com/browser/django/trunk/django/db/backends/mysql_old/base.py?rev=7852 5 9 """ 6 10 … … 38 42 server_version_re = re.compile(r'(\d{1,2})\.(\d{1,2})\.(\d{1,2})') 39 43 40 class MysqlWrapper: 44 # This is an extra debug layer over MySQL queries, to display warnings. 45 # It's only used when DEBUG=True. 46 class MysqlDebugWrapper: 41 47 def __init__(self, cursor): 42 48 self.cursor = cursor 43 49 44 def __getattr__(self, attr):45 if attr in self.__dict__:46 return self.__dict__[attr]47 else:48 return getattr(self.cursor, attr)49 50 # This is an extra debug layer over MySQL queries, to display warnings.51 # It's only used when DEBUG=True.52 class MysqlDebugWrapper(MysqlWrapper):53 50 def execute(self, sql, params=()): 54 51 try: … … 65 62 raise Database.Warning("%s: %s" % (w, self.cursor.fetchall())) 66 63 67 class MysqlUnicodeWrapper(MysqlWrapper): 64 def __getattr__(self, attr): 65 if attr in self.__dict__: 66 return self.__dict__[attr] 67 else: 68 return getattr(self.cursor, attr) 69 70 class MysqlUnicodeWrapper: 71 """ 72 A Wrapper who decode all byte strings to unicode. 73 """ 68 74 def __init__(self, cursor): 69 75 self.cursor = cursor … … 105 111 return result_raw 106 112 113 def __getattr__(self, attr): 114 if attr in self.__dict__: 115 return self.__dict__[attr] 116 else: 117 return getattr(self.cursor, attr) 107 118 108 119 class DatabaseFeatures(BaseDatabaseFeatures): 109 autoindexes_primary_keys = False110 120 inline_fk_references = False 121 empty_fetchmany_value = () 122 update_can_self_select = False 123 supports_usecs = False 111 124 112 125 class DatabaseOperations(BaseDatabaseOperations): … … 134 147 return 'MATCH (%s) AGAINST (%%s IN BOOLEAN MODE)' % field_name 135 148 136 def limit_offset_sql(self, limit, offset=None): 137 # 'LIMIT 20,40' 138 sql = "LIMIT " 139 if offset and offset != 0: 140 sql += "%s," % offset 141 return sql + str(limit) 149 def no_limit_value(self): 150 # 2**64 - 1, as recommended by the MySQL documentation 151 return 18446744073709551615L 142 152 143 153 def quote_name(self, name): … … 176 186 ops = DatabaseOperations() 177 187 operators = { 178 'exact': '= %s',188 'exact': '= BINARY %s', 179 189 'iexact': 'LIKE %s', 180 190 'contains': 'LIKE BINARY %s', … … 238 248 cursor = self.connection.cursor() 239 249 240 return MysqlUnicodeWrapper(cursor) 250 cursor = MysqlUnicodeWrapper(cursor) 251 252 return cursor 241 253 242 254 def make_debug_cursor(self, cursor): 243 cursor = MysqlDebugWrapper(cursor) 244 cursor = MysqlUnicodeWrapper(cursor) 245 return BaseDatabaseWrapper.make_debug_cursor(self, cursor) 255 return BaseDatabaseWrapper.make_debug_cursor(self, MysqlDebugWrapper(cursor)) 246 256 247 257 def _rollback(self):