Ticket #18116: 18116-require-mysql-5.0.3-2.diff

File 18116-require-mysql-5.0.3-2.diff, 8.3 KB (added by Ramiro Morales, 12 years ago)
  • django/db/backends/mysql/base.py

    diff -r 99b02d130047 django/db/backends/mysql/base.py
    a b  
    1515    from django.core.exceptions import ImproperlyConfigured
    1616    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
    1717
     18from django.utils.functional import cached_property
     19
    1820# We want version (1, 2, 1, 'final', 2) or later. We can't just use
    1921# lexicographic ordering in this check because then (1, 2, 1, 'gamma')
    2022# inadvertently passes the version test.
    2123version = Database.version_info
    22 if (version < (1,2,1) or (version[:3] == (1, 2, 1) and
     24if (version < (1, 2, 1) or (version[:3] == (1, 2, 1) and
    2325        (len(version) < 5 or version[3] != 'final' or version[4] < 2))):
    2426    from django.core.exceptions import ImproperlyConfigured
    2527    raise ImproperlyConfigured("MySQLdb-1.2.1p2 or newer is required; you have %s" % Database.__version__)
     
    163165    supports_timezones = False
    164166    requires_explicit_null_ordering_when_grouping = True
    165167    allows_primary_key_0 = False
     168    uses_savepoints = True
    166169
    167170    def __init__(self, connection):
    168171        super(DatabaseFeatures, self).__init__(connection)
     
    387390            self.connection = Database.connect(**kwargs)
    388391            self.connection.encoders[SafeUnicode] = self.connection.encoders[unicode]
    389392            self.connection.encoders[SafeString] = self.connection.encoders[str]
    390             self.features.uses_savepoints = \
    391                 self.get_server_version() >= (5, 0, 3)
    392393            connection_created.send(sender=self.__class__, connection=self)
    393394        cursor = self.connection.cursor()
    394395        if new_connection:
     
    405406        except Database.NotSupportedError:
    406407            pass
    407408
    408     def get_server_version(self):
     409    @cached_property
     410    def mysql_version(self):
    409411        if not self.server_version:
    410412            if not self._valid_connection():
    411                 self.cursor()
     413                self.cursor().close()
    412414            m = server_version_re.match(self.connection.get_server_info())
    413415            if not m:
    414416                raise Exception('Unable to determine MySQL version from version string %r' % self.connection.get_server_info())
  • django/db/backends/mysql/introspection.py

    diff -r 99b02d130047 django/db/backends/mysql/introspection.py
    a b  
    6565        key columns in given table.
    6666        """
    6767        key_columns = []
    68         try:
    69             cursor.execute("""
    70                 SELECT column_name, referenced_table_name, referenced_column_name
    71                 FROM information_schema.key_column_usage
    72                 WHERE table_name = %s
    73                     AND table_schema = DATABASE()
    74                     AND referenced_table_name IS NOT NULL
    75                     AND referenced_column_name IS NOT NULL""", [table_name])
    76             key_columns.extend(cursor.fetchall())
    77         except (ProgrammingError, OperationalError):
    78             # Fall back to "SHOW CREATE TABLE", for previous MySQL versions.
    79             # Go through all constraints and save the equal matches.
    80             cursor.execute("SHOW CREATE TABLE %s" % self.connection.ops.quote_name(table_name))
    81             for row in cursor.fetchall():
    82                 pos = 0
    83                 while True:
    84                     match = foreign_key_re.search(row[1], pos)
    85                     if match == None:
    86                         break
    87                     pos = match.end()
    88                     key_columns.append(match.groups())
     68        cursor.execute("""
     69            SELECT column_name, referenced_table_name, referenced_column_name
     70            FROM information_schema.key_column_usage
     71            WHERE table_name = %s
     72                AND table_schema = DATABASE()
     73                AND referenced_table_name IS NOT NULL
     74                AND referenced_column_name IS NOT NULL""", [table_name])
     75        key_columns.extend(cursor.fetchall())
    8976        return key_columns
    9077
    9178    def get_primary_key_column(self, cursor, table_name):
  • django/db/backends/mysql/validation.py

    diff -r 99b02d130047 django/db/backends/mysql/validation.py
    a b  
    33class DatabaseValidation(BaseDatabaseValidation):
    44    def validate_field(self, errors, opts, f):
    55        """
    6         There are some field length restrictions for MySQL:
    7 
    8         - Prior to version 5.0.3, character fields could not exceed 255
    9           characters in length.
    10         - No character (varchar) fields can have a length exceeding 255
    11           characters if they have a unique index on them.
     6        MySQL has the following field length restriction:
     7        No character (varchar) fields can have a length exceeding 255
     8        characters if they have a unique index on them.
    129        """
    1310        from django.db import models
    14         from MySQLdb import OperationalError
    15         try:
    16             db_version = self.connection.get_server_version()
    17             text_version = '.'.join([str(n) for n in db_version[:3]])
    18         except OperationalError:
    19             db_version = None
    20             text_version = ''
    2111        varchar_fields = (models.CharField, models.CommaSeparatedIntegerField,
    2212                models.SlugField)
    23         if isinstance(f, varchar_fields) and f.max_length > 255:
    24             if db_version and db_version < (5, 0, 3):
    25                 msg = '"%(name)s": %(cls)s cannot have a "max_length" greater than 255 when you are using a version of MySQL prior to 5.0.3 (you are using %(version)s).'
    26             elif f.unique == True:
    27                 msg = '"%(name)s": %(cls)s cannot have a "max_length" greater than 255 when using "unique=True".'
    28             else:
    29                 msg = None
    30 
    31             if msg:
    32                 errors.add(opts, msg % {'name': f.name, 'cls': f.__class__.__name__, 'version': text_version})
     13        if isinstance(f, varchar_fields) and f.max_length > 255 and f.unique:
     14            msg = '"%(name)s": %(cls)s cannot have a "max_length" greater than 255 when using "unique=True".'
     15            errors.add(opts, msg % {'name': f.name, 'cls': f.__class__.__name__})
  • docs/ref/databases.txt

    diff -r 99b02d130047 docs/ref/databases.txt
    a b  
    122122MySQL notes
    123123===========
    124124
    125 Django expects the database to support transactions, referential integrity, and
    126 Unicode (UTF-8 encoding). Fortunately, MySQL_ has all these features as
    127 available as far back as 3.23. While it may be possible to use 3.23 or 4.0,
    128 you'll probably have less trouble if you use 4.1 or 5.0.
     125Version support
     126---------------
    129127
    130 MySQL 4.1
    131 ---------
    132 
    133 `MySQL 4.1`_ has greatly improved support for character sets. It is possible to
    134 set different default character sets on the database, table, and column.
    135 Previous versions have only a server-wide character set setting. It's also the
    136 first version where the character set can be changed on the fly. 4.1 also has
    137 support for views, but Django currently doesn't use views.
    138 
    139 MySQL 5.0
    140 ---------
     128Django supports MySQL 5.0.3 and higher.
    141129
    142130`MySQL 5.0`_ adds the ``information_schema`` database, which contains detailed
    143131data on all database schema. Django's ``inspectdb`` feature uses this
    144 ``information_schema`` if it's available. 5.0 also has support for stored
    145 procedures, but Django currently doesn't use stored procedures.
     132``information_schema`` if it's available.
     133
     134.. versionchanged:: 1.5
     135    The minimum version requirement of MySQL 5.0.3 was set in Django 1.5.
     136
     137Django expects the database to support transactions, referential integrity, and
     138Unicode (UTF-8 encoding).
    146139
    147140.. _MySQL: http://www.mysql.com/
    148 .. _MySQL 4.1: http://dev.mysql.com/doc/refman/4.1/en/index.html
    149141.. _MySQL 5.0: http://dev.mysql.com/doc/refman/5.0/en/index.html
    150142
    151143Storage engines
     
    381373:class:`~django.db.models.SlugField` and
    382374:class:`~django.db.models.CommaSeparatedIntegerField`.
    383375
    384 Furthermore, if you are using a version of MySQL prior to 5.0.3, all of those
    385 column types have a maximum length restriction of 255 characters, regardless
    386 of whether ``unique=True`` is specified or not.
    387 
    388376DateTime fields
    389377~~~~~~~~~~~~~~~
    390378
Back to Top