Ticket #399: bigint-patch-20091215.diff
File bigint-patch-20091215.diff, 12.6 KB (added by , 15 years ago) |
---|
-
django/db/models/fields/__init__.py
743 743 defaults.update(kwargs) 744 744 return super(IntegerField, self).formfield(**defaults) 745 745 746 class BigIntegerField(IntegerField): 747 MAX_BIGINT = 9223372036854775807 748 empty_strings_allowed = False 749 def get_internal_type(self): 750 return "BigIntegerField" 751 752 def get_db_prep_save(self, value): 753 if value is not None: 754 value = long(value) 755 if value > BigIntegerField.MAX_BIGINT or value < -BigIntegerField.MAX_BIGINT - 1: 756 raise ValueError("Value is to small/large to fit this field") 757 return super(BigIntegerField, self).get_db_prep_save(value) 758 759 def formfield(self, **kwargs): 760 defaults = {'min_value': -BigIntegerField.MAX_BIGINT - 1, 761 'max_value': BigIntegerField.MAX_BIGINT} 762 defaults.update(kwargs) 763 return super(BigIntegerField, self).formfield(**defaults) 764 765 746 766 class IPAddressField(Field): 747 767 """IP address""" 748 768 -
django/db/backends/postgresql/introspection.py
4 4 # Maps type codes to Django Field types. 5 5 data_types_reverse = { 6 6 16: 'BooleanField', 7 20: 'BigIntegerField', 7 8 21: 'SmallIntegerField', 8 9 23: 'IntegerField', 9 10 25: 'TextField', -
django/db/backends/postgresql/creation.py
18 18 'FilePathField': 'varchar(%(max_length)s)', 19 19 'FloatField': 'double precision', 20 20 'IntegerField': 'integer', 21 'BigIntegerField': 'bigint', 21 22 'IPAddressField': 'inet', 22 23 'NullBooleanField': 'boolean', 23 24 'OneToOneField': 'integer', -
django/db/backends/sqlite3/introspection.py
16 16 'smallinteger': 'SmallIntegerField', 17 17 'int': 'IntegerField', 18 18 'integer': 'IntegerField', 19 'bigint': 'BigIntegerField', 19 20 'integer unsigned': 'PositiveIntegerField', 20 21 'decimal': 'DecimalField', 21 22 'real': 'FloatField', -
django/db/backends/sqlite3/creation.py
19 19 'FilePathField': 'varchar(%(max_length)s)', 20 20 'FloatField': 'real', 21 21 'IntegerField': 'integer', 22 'BigIntegerField': 'bigint', 22 23 'IPAddressField': 'char(15)', 23 24 'NullBooleanField': 'bool', 24 25 'OneToOneField': 'integer', -
django/db/backends/mysql/introspection.py
17 17 FIELD_TYPE.FLOAT: 'FloatField', 18 18 FIELD_TYPE.INT24: 'IntegerField', 19 19 FIELD_TYPE.LONG: 'IntegerField', 20 FIELD_TYPE.LONGLONG: ' IntegerField',20 FIELD_TYPE.LONGLONG: 'BigIntegerField', 21 21 FIELD_TYPE.SHORT: 'IntegerField', 22 22 FIELD_TYPE.STRING: 'CharField', 23 23 FIELD_TYPE.TIMESTAMP: 'DateTimeField', -
django/db/backends/mysql/creation.py
18 18 'FilePathField': 'varchar(%(max_length)s)', 19 19 'FloatField': 'double precision', 20 20 'IntegerField': 'integer', 21 'BigIntegerField': 'bigint', 21 22 'IPAddressField': 'char(15)', 22 23 'NullBooleanField': 'bool', 23 24 'OneToOneField': 'integer', … … 63 64 field.rel.to._meta.db_table, field.rel.to._meta.pk.column) 64 65 ] 65 66 return table_output, deferred 66 67 No newline at end of file 67 -
django/db/backends/oracle/introspection.py
29 29 def get_field_type(self, data_type, description): 30 30 # If it's a NUMBER with scale == 0, consider it an IntegerField 31 31 if data_type == cx_Oracle.NUMBER and description[5] == 0: 32 return 'IntegerField' 32 if description[4] > 11: 33 return 'BigIntegerField' 34 else: 35 return 'IntegerField' 33 36 else: 34 37 return super(DatabaseIntrospection, self).get_field_type( 35 38 data_type, description) -
django/db/backends/oracle/creation.py
27 27 'FilePathField': 'NVARCHAR2(%(max_length)s)', 28 28 'FloatField': 'DOUBLE PRECISION', 29 29 'IntegerField': 'NUMBER(11)', 30 'BigIntegerField': 'NUMBER(19)', 30 31 'IPAddressField': 'VARCHAR2(15)', 31 32 'NullBooleanField': 'NUMBER(1) CHECK ((%(qn_column)s IN (0,1)) OR (%(qn_column)s IS NULL))', 32 33 'OneToOneField': 'NUMBER(11)', -
django/contrib/admin/options.py
42 42 'form_class': forms.SplitDateTimeField, 43 43 'widget': widgets.AdminSplitDateTime 44 44 }, 45 models.DateField: {'widget': widgets.AdminDateWidget}, 46 models.TimeField: {'widget': widgets.AdminTimeWidget}, 47 models.TextField: {'widget': widgets.AdminTextareaWidget}, 48 models.URLField: {'widget': widgets.AdminURLFieldWidget}, 49 models.IntegerField: {'widget': widgets.AdminIntegerFieldWidget}, 50 models.CharField: {'widget': widgets.AdminTextInputWidget}, 51 models.ImageField: {'widget': widgets.AdminFileWidget}, 52 models.FileField: {'widget': widgets.AdminFileWidget}, 45 models.DateField: {'widget': widgets.AdminDateWidget}, 46 models.TimeField: {'widget': widgets.AdminTimeWidget}, 47 models.TextField: {'widget': widgets.AdminTextareaWidget}, 48 models.URLField: {'widget': widgets.AdminURLFieldWidget}, 49 models.IntegerField: {'widget': widgets.AdminIntegerFieldWidget}, 50 models.BigIntegerField: {'widget': widgets.AdminIntegerFieldWidget}, 51 models.CharField: {'widget': widgets.AdminTextInputWidget}, 52 models.ImageField: {'widget': widgets.AdminFileWidget}, 53 models.FileField: {'widget': widgets.AdminFileWidget}, 53 54 } 54 55 55 56 -
tests/regressiontests/model_fields/tests.py
6 6 from django.db import models 7 7 from django.core.exceptions import ValidationError 8 8 9 from models import Foo, Bar, Whiz, BigD, BigS, Image 9 from models import Foo, Bar, Whiz, BigD, BigS, Image, BigInt 10 10 11 11 try: 12 12 from decimal import Decimal … … 144 144 bs = BigS.objects.create(s = 'slug'*50) 145 145 bs = BigS.objects.get(pk=bs.pk) 146 146 self.assertEqual(bs.s, 'slug'*50) 147 148 class BigIntegerFieldTests(django.test.TestCase): 149 def test_existence(self): 150 self.assertEqual(len(BigInt.objects.all()), 0) 151 152 def test_limits(self): 153 self.assertRaises(ValueError, BigInt(value = 9223372036854775809111111111111111111).save) 154 self.assertRaises(ValueError, BigInt(value = -9223372036854775809111111111111111111).save) 155 self.assertRaises(ValueError, BigInt(value = 9223372036854775808).save) 156 self.assertRaises(ValueError, BigInt(value = -9223372036854775809).save) 157 self.assertEqual(BigInt(value = -9223372036854775808).save(), None) 158 self.assertEqual(BigInt(value = 9223372036854775807).save(), None) 159 self.assertEqual(BigInt(value = 0).save(), None) 160 161 def test_types(self): 162 b = BigInt(value = 0) 163 self.assertTrue(isinstance(b.value, (int, long))) 164 b.save() 165 self.assertTrue(isinstance(b.value, (int, long))) 166 b = BigInt.objects.all()[0] 167 self.assertTrue(isinstance(b.value, (int, long))) 168 169 def test_coercing(self): 170 b = BigInt(value = 10) 171 b.save() 172 self.assertEqual(b.value, 10) 173 self.assertEqual(unicode(b), unicode(10)) 174 175 def test_null(self): 176 # this test needs to be run in one transaction, so null tests need to 177 # be split 178 try: 179 # it raises different exceptions depending on backend 180 BigInt(value = None).save() 181 self.assertTrue(False, 'null saved in not null field') 182 except: 183 pass 184 185 def test_null2(self): 186 BigInt(value = 1, null_value = 4).save() 187 BigInt(value = 1, null_value = None).save() -
tests/regressiontests/model_fields/models.py
51 51 class BigS(models.Model): 52 52 s = models.SlugField(max_length=255) 53 53 54 class BigInt(models.Model): 55 value = models.BigIntegerField() 56 null_value = models.BigIntegerField(null = True, blank = True) 54 57 58 def __unicode__(self): 59 return unicode(self.value) 60 55 61 ############################################################################### 56 62 # ImageField 57 63 -
tests/regressiontests/introspection/tests.py
77 77 cursor = connection.cursor() 78 78 desc = connection.introspection.get_table_description(cursor, Reporter._meta.db_table) 79 79 self.assertEqual([datatype(r[1], r) for r in desc], 80 ['IntegerField', 'CharField', 'CharField', 'CharField' ])80 ['IntegerField', 'CharField', 'CharField', 'CharField', 'BigIntegerField']) 81 81 82 82 # Regression test for #9991 - 'real' types in postgres 83 83 if settings.DATABASE_ENGINE.startswith('postgresql'): -
tests/regressiontests/introspection/models.py
4 4 first_name = models.CharField(max_length=30) 5 5 last_name = models.CharField(max_length=30) 6 6 email = models.EmailField() 7 facebook_user_id = models.BigIntegerField() 7 8 8 9 def __unicode__(self): 9 10 return u"%s %s" % (self.first_name, self.last_name) … … 17 18 return self.headline 18 19 19 20 class Meta: 20 ordering = ('headline',) 21 No newline at end of file 21 ordering = ('headline',) -
docs/ref/models/fields.txt
641 641 An integer. The admin represents this as an ``<input type="text">`` (a 642 642 single-line input). 643 643 644 ``bigintegerfield`` 645 ~~~~~~~~~~~~~~~~ 646 647 .. class:: BigIntegerField([**options]) 648 649 A big integer. The admin represents this as an ``<input type="text">`` 650 (a single-line input). 651 652 a 64 bit type like an ``integerfield``, except that it fits numbers from 653 -9223372036854775808 to 9223372036854775807 654 655 644 656 ``IPAddressField`` 645 657 ------------------ 646 658