Django

Code

Changeset 3872

Show
Ignore:
Timestamp:
09/26/06 21:42:31 (2 years ago)
Author:
mtredinnick
Message:

Reintroduced the changes from [3855] with more flexible handling of version
strings. Refs #2188, #2827.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/AUTHORS

    r3867 r3872  
    120120    Robin Munn <http://www.geekforgod.com/> 
    121121    Nebojša Dorđević 
     122    Fraser Nevett <mail@nevett.org> 
    122123    Sam Newman <http://www.magpiebrain.com/> 
    123124    Neal Norwitz <nnorwitz@google.com> 
  • django/trunk/django/core/management.py

    r3867 r3872  
    821821    Returns number of errors. 
    822822    """ 
    823     from django.db import models 
     823    from django.conf import settings 
     824    from django.db import models, connection 
    824825    from django.db.models.loading import get_app_errors 
    825826    from django.db.models.fields.related import RelatedObject 
     
    862863            if f.db_index not in (None, True, False): 
    863864                e.add(opts, '"%s": "db_index" should be either None, True or False.' % f.name) 
     865 
     866            # Check that maxlength <= 255 if using older MySQL versions. 
     867            if settings.DATABASE_ENGINE == 'mysql': 
     868                db_version = connection.get_server_version() 
     869                if db_version < (5, 0, 3) and isinstance(f, (models.CharField, models.CommaSeparatedIntegerField, models.SlugField)) and f.maxlength > 255: 
     870                    e.add(opts, '"%s": %s cannot have a "maxlength" greater than 255 when you are using a version of MySQL prior to 5.0.3 (you are using %s).' % (f.name, f.__class__.__name__, '.'.join(str(n) for n in db_version[:3]))) 
    864871 
    865872            # Check to see if the related field will clash with any 
  • django/trunk/django/db/backends/mysql/base.py

    r3868 r3872  
    1414from MySQLdb.constants import FIELD_TYPE 
    1515import types 
     16import re 
    1617 
    1718DatabaseError = Database.DatabaseError 
     
    2425    FIELD_TYPE.TIME: util.typecast_time, 
    2526}) 
     27 
     28# This should match the numerical portion of the version numbers (we can treat 
     29# versions like 5.0.24 and 5.0.24a as the same). Based on the list of version 
     30# at http://dev.mysql.com/doc/refman/4.1/en/news.html and 
     31# http://dev.mysql.com/doc/refman/5.0/en/news.html . 
     32server_version_re = re.compile(r'(\d{1,2})\.(\d{1,2})\.(\d{1,2})') 
    2633 
    2734# This is an extra debug layer over MySQL queries, to display warnings. 
     
    6269        self.connection = None 
    6370        self.queries = [] 
     71        self.server_version = None 
    6472 
    6573    def _valid_connection(self): 
     
    110118            self.connection.close() 
    111119            self.connection = None 
     120 
     121    def get_server_version(self): 
     122        if not self.server_version: 
     123            if not self._valid_connection(): 
     124                self.cursor() 
     125            m = server_version_re.match(self.connection.get_server_info()) 
     126            if not m: 
     127                raise Exception('Unable to determine MySQL version from version string %r' % self.connection.get_server_info()) 
     128            self.server_version = m.groups() 
     129        return self.server_version 
    112130 
    113131supports_constraints = True