Changeset 1692

Show
Ignore:
Timestamp:
07/18/08 13:25:14 (4 months ago)
Author:
JensDiemer
Message:

Patched svn revision 7852:
http://code.djangoproject.com/changeset/7852
http://code.djangoproject.com/browser/django/trunk/django/db/backends/mysql_old/base.py?rev=7852

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • CodeSnippets/django_backends_mysql_old/base.py

    • Property svn:eol-style set to LF
    r1337 r1692  
    33 
    44Requires MySQLdb: http://sourceforge.net/projects/mysql-python 
     5 
     6Patched svn revision 7852: 
     7http://code.djangoproject.com/changeset/7852 
     8http://code.djangoproject.com/browser/django/trunk/django/db/backends/mysql_old/base.py?rev=7852 
    59""" 
    610 
     
    3842server_version_re = re.compile(r'(\d{1,2})\.(\d{1,2})\.(\d{1,2})') 
    3943 
    40 class MysqlWrapper: 
     44# This is an extra debug layer over MySQL queries, to display warnings. 
     45# It's only used when DEBUG=True. 
     46class MysqlDebugWrapper: 
    4147    def __init__(self, cursor): 
    4248        self.cursor = cursor 
    4349 
    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): 
    5350    def execute(self, sql, params=()): 
    5451        try: 
     
    6562            raise Database.Warning("%s: %s" % (w, self.cursor.fetchall())) 
    6663 
    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 
     70class MysqlUnicodeWrapper: 
     71    """ 
     72    A Wrapper who decode all byte strings to unicode. 
     73    """ 
    6874    def __init__(self, cursor): 
    6975        self.cursor = cursor 
     
    105111        return result_raw 
    106112 
     113    def __getattr__(self, attr): 
     114        if attr in self.__dict__: 
     115            return self.__dict__[attr] 
     116        else: 
     117            return getattr(self.cursor, attr) 
    107118 
    108119class DatabaseFeatures(BaseDatabaseFeatures): 
    109     autoindexes_primary_keys = False 
    110120    inline_fk_references = False 
     121    empty_fetchmany_value = () 
     122    update_can_self_select = False 
     123    supports_usecs = False 
    111124 
    112125class DatabaseOperations(BaseDatabaseOperations): 
     
    134147        return 'MATCH (%s) AGAINST (%%s IN BOOLEAN MODE)' % field_name 
    135148 
    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 
    142152 
    143153    def quote_name(self, name): 
     
    176186    ops = DatabaseOperations() 
    177187    operators = { 
    178         'exact': '= %s', 
     188        'exact': '= BINARY %s', 
    179189        'iexact': 'LIKE %s', 
    180190        'contains': 'LIKE BINARY %s', 
     
    238248            cursor = self.connection.cursor() 
    239249 
    240         return MysqlUnicodeWrapper(cursor) 
     250        cursor = MysqlUnicodeWrapper(cursor) 
     251 
     252        return cursor 
    241253 
    242254    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)) 
    246256 
    247257    def _rollback(self):