Ticket #20001: bigauto.diff

File bigauto.diff, 9.2 KB (added by jim@…, 12 years ago)

BigAutoField patch file.

  • django/db/backends/__init__.py

    diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py
    index fe26c98..97d0e68 100644
    a b class BaseDatabaseOperations(object):  
    10551055        if internal_type == 'FloatField':
    10561056            return float(value)
    10571057        elif (internal_type and (internal_type.endswith('IntegerField')
    1058                                  or internal_type == 'AutoField')):
     1058                                 or internal_type.endswith('AutoField'))):
    10591059            return int(value)
    10601060        return value
    10611061
  • django/db/backends/mysql/creation.py

    diff --git a/django/db/backends/mysql/creation.py b/django/db/backends/mysql/creation.py
    index 3a57c29..9dfc641 100644
    a b class DatabaseCreation(BaseDatabaseCreation):  
    77    # If a column type is set to None, it won't be included in the output.
    88    data_types = {
    99        'AutoField':         'integer AUTO_INCREMENT',
     10        'BigAutoField':      'bigint AUTO_INCREMENT',
    1011        'BinaryField':       'longblob',
    1112        'BooleanField':      'bool',
    1213        'CharField':         'varchar(%(max_length)s)',
  • django/db/backends/oracle/creation.py

    diff --git a/django/db/backends/oracle/creation.py b/django/db/backends/oracle/creation.py
    index aaca74e..dd3ddb3 100644
    a b class DatabaseCreation(BaseDatabaseCreation):  
    1717
    1818    data_types = {
    1919        'AutoField':                    'NUMBER(11)',
     20        'BigAutoField':                 'NUMBER(19)',
    2021        'BinaryField':                  'BLOB',
    2122        'BooleanField':                 'NUMBER(1) CHECK (%(qn_column)s IN (0,1))',
    2223        'CharField':                    'NVARCHAR2(%(max_length)s)',
  • django/db/backends/postgresql_psycopg2/creation.py

    diff --git a/django/db/backends/postgresql_psycopg2/creation.py b/django/db/backends/postgresql_psycopg2/creation.py
    index b19926b..b745ef8 100644
    a b class DatabaseCreation(BaseDatabaseCreation):  
    1111    # If a column type is set to None, it won't be included in the output.
    1212    data_types = {
    1313        'AutoField':         'serial',
     14        'BigAutoField':      'bigserial',
    1415        'BinaryField':       'bytea',
    1516        'BooleanField':      'boolean',
    1617        'CharField':         'varchar(%(max_length)s)',
  • django/db/backends/sqlite3/base.py

    diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py
    index 416a629..d96cdfe 100644
    a b class DatabaseOperations(BaseDatabaseOperations):  
    248248        internal_type = field.get_internal_type()
    249249        if internal_type == 'DecimalField':
    250250            return util.typecast_decimal(field.format_number(value))
    251         elif internal_type and internal_type.endswith('IntegerField') or internal_type == 'AutoField':
     251        elif (internal_type and internal_type.endswith('IntegerField') or
     252                internal_type.endswith('AutoField')):
    252253            return int(value)
    253254        elif internal_type == 'DateField':
    254255            return parse_date(value)
  • django/db/backends/sqlite3/creation.py

    diff --git a/django/db/backends/sqlite3/creation.py b/django/db/backends/sqlite3/creation.py
    index c90a697..6132b10 100644
    a b class DatabaseCreation(BaseDatabaseCreation):  
    99    # schema inspection is more useful.
    1010    data_types = {
    1111        'AutoField':                    'integer',
     12        'BigAutoField':                 'integer',
    1213        'BinaryField':                  'BLOB',
    1314        'BooleanField':                 'bool',
    1415        'CharField':                    'varchar(%(max_length)s)',
  • django/db/models/fields/__init__.py

    diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
    index f9f913b..8b9f9ed 100644
    a b class Field(object):  
    215215        self.run_validators(value)
    216216        return value
    217217
     218    def _internal_to_db_type(self, internal_type, connection):
     219        data = DictWrapper(self.__dict__, connection.ops.quote_name, "qn_")
     220        try:
     221            return connection.creation.data_types[internal_type] % data
     222        except KeyError:
     223            return None
     224
    218225    def db_type(self, connection):
    219226        """
    220227        Returns the database column data type for this field, for the provided
    class Field(object):  
    235242        # mapped to one of the built-in Django field types. In this case, you
    236243        # can implement db_type() instead of get_internal_type() to specify
    237244        # exactly which wacky database column type you want to use.
    238         data = DictWrapper(self.__dict__, connection.ops.quote_name, "qn_")
    239         try:
    240             return (connection.creation.data_types[self.get_internal_type()]
    241                     % data)
    242         except KeyError:
    243             return None
     245        return self._internal_to_db_type(self.get_internal_type(), connection)
     246
     247    def rel_db_type(self, connection):
     248        """
     249        Returns the database column data type for related field
     250        referencing to this.
     251        """
     252        return self.db_type(connection)
    244253
    245254    @property
    246255    def unique(self):
    class AutoField(Field):  
    530539        'invalid': _("'%s' value must be an integer."),
    531540    }
    532541
    533     def __init__(self, *args, **kwargs):
     542    def __init__(self, verbose_name=None, name=None, big=False, **kwargs):
    534543        assert kwargs.get('primary_key', False) is True, \
    535544               "%ss must have primary_key=True." % self.__class__.__name__
    536545        kwargs['blank'] = True
    537         Field.__init__(self, *args, **kwargs)
     546        self.big = big
     547        Field.__init__(self, verbose_name, name, **kwargs)
    538548
    539549    def get_internal_type(self):
    540         return "AutoField"
     550        return "AutoField" if not self.big else 'BigAutoField'
     551
     552    def rel_db_type(self, connection):
     553        db_type = 'IntegerField' if not self.big else 'BigIntegerField'
     554        return self._internal_to_db_type(db_type, connection)
    541555
    542556    def to_python(self, value):
    543557        if value is None:
    class PositiveIntegerField(IntegerField):  
    11521166    def get_internal_type(self):
    11531167        return "PositiveIntegerField"
    11541168
     1169    def rel_db_type(self, connection):
     1170        if connection.features.related_fields_match_type:
     1171            return self.db_type(connection)
     1172        return self._internal_to_db_type('IntegerField', connection)
     1173
    11551174    def formfield(self, **kwargs):
    11561175        defaults = {'min_value': 0}
    11571176        defaults.update(kwargs)
    class PositiveSmallIntegerField(IntegerField):  
    11631182    def get_internal_type(self):
    11641183        return "PositiveSmallIntegerField"
    11651184
     1185    def rel_db_type(self, connection):
     1186        if connection.features.related_fields_match_type:
     1187            return self.db_type(connection)
     1188        return self._internal_to_db_type('IntegerField', connection)
     1189
    11661190    def formfield(self, **kwargs):
    11671191        defaults = {'min_value': 0}
    11681192        defaults.update(kwargs)
  • django/db/models/fields/related.py

    diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
    index 01b8a55..071a5a9 100644
    a b class ForeignKey(RelatedField, Field):  
    11131113        return super(ForeignKey, self).formfield(**defaults)
    11141114
    11151115    def db_type(self, connection):
    1116         # The database column type of a ForeignKey is the column type
    1117         # of the field to which it points. An exception is if the ForeignKey
    1118         # points to an AutoField/PositiveIntegerField/PositiveSmallIntegerField,
    1119         # in which case the column type is simply that of an IntegerField.
    1120         # If the database needs similar types for key fields however, the only
    1121         # thing we can do is making AutoField an IntegerField.
    11221116        rel_field = self.rel.get_related_field()
    1123         if (isinstance(rel_field, AutoField) or
    1124                 (not connection.features.related_fields_match_type and
    1125                 isinstance(rel_field, (PositiveIntegerField,
    1126                                        PositiveSmallIntegerField)))):
    1127             return IntegerField().db_type(connection=connection)
    1128         return rel_field.db_type(connection=connection)
     1117        return rel_field.rel_db_type(connection=connection)
    11291118
    11301119
    11311120class OneToOneField(ForeignKey):
  • docs/ref/models/fields.txt

    diff --git a/docs/ref/models/fields.txt b/docs/ref/models/fields.txt
    index 1dbc8c3..d00e1f2 100644
    a b Field types  
    331331``AutoField``
    332332-------------
    333333
    334 .. class:: AutoField(**options)
     334.. class:: AutoField([big=False, **options]
    335335
    336336An :class:`IntegerField` that automatically increments
    337337according to available IDs. You usually won't need to use this directly; a
    338338primary key field will automatically be added to your model if you don't specify
    339339otherwise. See :ref:`automatic-primary-key-fields`.
    340340
     341.. attribute:: AutoField.big
     342
     343.. versionadded:: 1.5
     344
     345Optional.  Either ``False`` or ``True``.  Default is ``False``. Allow you
     346to use bigint for storing field values. This extends values range up to
     347max 64 bit integer (from 1 to 9223372036854775807).
     348
     349
    341350``BigIntegerField``
    342351-------------------
    343352
Back to Top