Ticket #7789: 7789_fields_3.diff
File 7789_fields_3.diff, 3.6 KB (added by , 16 years ago) |
---|
-
db/models/fields/__init__.py
150 150 # mapped to one of the built-in Django field types. In this case, you 151 151 # can implement db_type() instead of get_internal_type() to specify 152 152 # exactly which wacky database column type you want to use. 153 data = DictWrapper(self.__dict__, connection.ops.quote_name, "qn_")154 153 try: 154 data = get_creation_module().backend_parameters(self, self.__dict__) 155 except AttributeError: 156 # No backend_parameters provided in backend 157 data = self.__dict__ 158 data = DictWrapper(data, connection.ops.quote_name, "qn_") 159 try: 155 160 return get_creation_module().DATA_TYPES[self.get_internal_type()] % data 156 161 except KeyError: 157 162 return None -
db/backends/mysql/base.py
21 21 raise ImproperlyConfigured("MySQLdb-1.2.1p2 or newer is required; you have %s" % Database.__version__) 22 22 23 23 from MySQLdb.converters import conversions 24 from MySQLdb.constants import FIELD_TYPE 24 from MySQLdb.constants import FIELD_TYPE, FLAG 25 25 import re 26 26 27 27 # Raise exceptions for database warnings if DEBUG is on … … 39 39 # TIME columns as timedelta -- they are more like timedelta in terms of actual 40 40 # behavior as they are signed and include days -- and Django expects time, so 41 41 # we still need to override that. 42 42 43 django_conversions = conversions.copy() 43 44 django_conversions.update({ 44 45 FIELD_TYPE.TIME: util.typecast_time, 45 46 FIELD_TYPE.DECIMAL: util.typecast_decimal, 46 47 FIELD_TYPE.NEWDECIMAL: util.typecast_decimal, 48 # By default, mysqldb will return VARCHAR BINARY fields as type str. 49 # This is a bad idea, as BINARY doesn't indicate that it's arbitrary 50 # binary data, but that collation uses the binary representation. 51 # Replacing the list makes it return unicode; mysqldb later adds 52 # another list entry for non-binary fields. 53 FIELD_TYPE.VARCHAR: [(FLAG.BINARY, lambda s: s.decode('utf-8'))], 47 54 }) 48 55 49 56 # This should match the numerical portion of the version numbers (we can treat -
db/backends/mysql/creation.py
5 5 DATA_TYPES = { 6 6 'AutoField': 'integer AUTO_INCREMENT', 7 7 'BooleanField': 'bool', 8 'CharField': 'varchar(%(max_length)s) ',8 'CharField': 'varchar(%(max_length)s) %(binary)s', 9 9 'CommaSeparatedIntegerField': 'varchar(%(max_length)s)', 10 10 'DateField': 'date', 11 11 'DateTimeField': 'datetime', … … 20 20 'PhoneNumberField': 'varchar(20)', 21 21 'PositiveIntegerField': 'integer UNSIGNED', 22 22 'PositiveSmallIntegerField': 'smallint UNSIGNED', 23 'SlugField': 'varchar(%(max_length)s) ',23 'SlugField': 'varchar(%(max_length)s) BINARY', 24 24 'SmallIntegerField': 'smallint', 25 25 'TextField': 'longtext', 26 26 'TimeField': 'time', 27 27 'USStateField': 'varchar(2)', 28 28 } 29 30 31 def backend_parameters(field, field_dict): 32 """ 33 For MySQL a unique CharField has to be created as a BINARY column as 34 database level. 35 """ 36 if field.unique and field.get_internal_type() == 'CharField': 37 return dict(field_dict, binary='BINARY') 38 return dict(field_dict, binary='')