Ticket #2188: Option 3.diff
File Option 3.diff, 4.4 KB (added by , 18 years ago) |
---|
-
core/management.py
134 134 135 135 Returns list_of_sql, pending_references_dict 136 136 """ 137 from django.db import backend, get_creation_module, models137 from django.db import backend, connection, get_creation_module, models 138 138 data_types = get_creation_module().DATA_TYPES 139 139 140 140 opts = klass._meta … … 151 151 col_type = data_types[data_type] 152 152 if col_type is not None: 153 153 # Make the definition (e.g. 'foo VARCHAR(30)') for this field. 154 if type(col_type).__name__ == 'function': 155 col_type = col_type(rel_field.__dict__, connection) 154 156 field_output = [style.SQL_FIELD(backend.quote_name(f.column)), 155 157 style.SQL_COLTYPE(col_type % rel_field.__dict__)] 156 158 field_output.append(style.SQL_KEYWORD('%sNULL' % (not f.null and 'NOT ' or ''))) -
db/backends/mysql/base.py
12 12 raise ImproperlyConfigured, "Error loading MySQLdb module: %s" % e 13 13 from MySQLdb.converters import conversions 14 14 from MySQLdb.constants import FIELD_TYPE 15 import types 15 import types, re 16 16 17 17 DatabaseError = Database.DatabaseError 18 18 … … 61 61 def __init__(self): 62 62 self.connection = None 63 63 self.queries = [] 64 self.server_version = None 64 65 65 66 def _valid_connection(self): 66 67 if self.connection is not None: … … 95 96 return util.CursorDebugWrapper(MysqlDebugWrapper(cursor), self) 96 97 return cursor 97 98 99 def get_server_version(self): 100 if not self.server_version: 101 if not self._valid_connection(): 102 self.cursor() 103 version = re.compile('[\.-]').split(self.connection.get_server_info()) 104 self.server_version = tuple(int(x) for x in version[:3]) + tuple(version[3:]) 105 return self.server_version 106 98 107 def _commit(self): 99 108 self.connection.commit() 100 109 -
db/backends/mysql/creation.py
1 1 # This dictionary maps Field objects to their associated MySQL column 2 # types, as strings. Column-type strings can contain format strings; they'll 3 # be interpolated against the values of Field.__dict__ before being output. 4 # If a column type is set to None, it won't be included in the output. 2 # types, as strings. Column-type strings can contain format strings or lambda 3 # functions. Any lambda functions will be passed two arguments, the first being 4 # Field.__dict__ and the second a database connection, and shoud return a 5 # string. In either case, the string will be interpolated against the values of 6 # Field.__dict__ before being output. If a column type is set to None, it won't 7 # be included in the output. 5 8 DATA_TYPES = { 6 9 'AutoField': 'integer AUTO_INCREMENT', 7 10 'BooleanField': 'bool', 8 'CharField': 'varchar(%(maxlength)s)', 9 'CommaSeparatedIntegerField': 'varchar(%(maxlength)s)', 11 'CharField': lambda details, connection: 12 (details['maxlength'] > 255 and connection.get_server_version() < (5, 0, 3) and 'text') 13 or 'varchar(%(maxlength)s)', 14 'CommaSeparatedIntegerField': lambda details, connection: 15 (details['maxlength'] > 255 and connection.get_server_version() < (5, 0, 3) and 'text') 16 or 'varchar(%(maxlength)s)', 10 17 'DateField': 'date', 11 18 'DateTimeField': 'datetime', 12 19 'FileField': 'varchar(100)', … … 21 28 'PhoneNumberField': 'varchar(20)', 22 29 'PositiveIntegerField': 'integer UNSIGNED', 23 30 'PositiveSmallIntegerField': 'smallint UNSIGNED', 24 'SlugField': 'varchar(%(maxlength)s)', 31 'SlugField': lambda details, connection: 32 (details['maxlength'] > 255 and connection.get_server_version() < (5, 0, 3) and 'text') 33 or 'varchar(%(maxlength)s)', 25 34 'SmallIntegerField': 'smallint', 26 35 'TextField': 'longtext', 27 36 'TimeField': 'time',