| 1 | Index: django/db/models/fields/__init__.py
|
|---|
| 2 | ===================================================================
|
|---|
| 3 | --- django/db/models/fields/__init__.py (revision 9673)
|
|---|
| 4 | +++ django/db/models/fields/__init__.py (working copy)
|
|---|
| 5 | @@ -417,6 +417,26 @@
|
|---|
| 6 | defaults.update(kwargs)
|
|---|
| 7 | return super(CharField, self).formfield(**defaults)
|
|---|
| 8 |
|
|---|
| 9 | +
|
|---|
| 10 | +class BinaryField(Field):
|
|---|
| 11 | + """Sometimes we have fields that need to store a small amount of binary
|
|---|
| 12 | + data. This is different then a varchar on postgresql at least because it
|
|---|
| 13 | + will not allow fields that are just nul bytes.
|
|---|
| 14 | + """
|
|---|
| 15 | +
|
|---|
| 16 | + def get_internal_type(self):
|
|---|
| 17 | + return "BinaryField"
|
|---|
| 18 | +
|
|---|
| 19 | +class BlobField(Field):
|
|---|
| 20 | + """Sometimes we have fields that need to store a large amounts of binary
|
|---|
| 21 | + data.
|
|---|
| 22 | + """
|
|---|
| 23 | +
|
|---|
| 24 | + def get_internal_type(self):
|
|---|
| 25 | + return "BlobField"
|
|---|
| 26 | +
|
|---|
| 27 | +
|
|---|
| 28 | +
|
|---|
| 29 | # TODO: Maybe move this into contrib, because it's specialized.
|
|---|
| 30 | class CommaSeparatedIntegerField(CharField):
|
|---|
| 31 | def formfield(self, **kwargs):
|
|---|
| 32 | Index: django/db/backends/postgresql/introspection.py
|
|---|
| 33 | ===================================================================
|
|---|
| 34 | --- django/db/backends/postgresql/introspection.py (revision 9673)
|
|---|
| 35 | +++ django/db/backends/postgresql/introspection.py (working copy)
|
|---|
| 36 | @@ -4,6 +4,7 @@
|
|---|
| 37 | # Maps type codes to Django Field types.
|
|---|
| 38 | data_types_reverse = {
|
|---|
| 39 | 16: 'BooleanField',
|
|---|
| 40 | + 17: 'BlobField',
|
|---|
| 41 | 21: 'SmallIntegerField',
|
|---|
| 42 | 23: 'IntegerField',
|
|---|
| 43 | 25: 'TextField',
|
|---|
| 44 | Index: django/db/backends/postgresql/creation.py
|
|---|
| 45 | ===================================================================
|
|---|
| 46 | --- django/db/backends/postgresql/creation.py (revision 9673)
|
|---|
| 47 | +++ django/db/backends/postgresql/creation.py (working copy)
|
|---|
| 48 | @@ -8,6 +8,8 @@
|
|---|
| 49 | # If a column type is set to None, it won't be included in the output.
|
|---|
| 50 | data_types = {
|
|---|
| 51 | 'AutoField': 'serial',
|
|---|
| 52 | + 'BinaryField': 'bytea',
|
|---|
| 53 | + 'BlobField': 'bytea',
|
|---|
| 54 | 'BooleanField': 'boolean',
|
|---|
| 55 | 'CharField': 'varchar(%(max_length)s)',
|
|---|
| 56 | 'CommaSeparatedIntegerField': 'varchar(%(max_length)s)',
|
|---|
| 57 | Index: django/db/backends/sqlite3/creation.py
|
|---|
| 58 | ===================================================================
|
|---|
| 59 | --- django/db/backends/sqlite3/creation.py (revision 9673)
|
|---|
| 60 | +++ django/db/backends/sqlite3/creation.py (working copy)
|
|---|
| 61 | @@ -9,6 +9,8 @@
|
|---|
| 62 | # schema inspection is more useful.
|
|---|
| 63 | data_types = {
|
|---|
| 64 | 'AutoField': 'integer',
|
|---|
| 65 | + 'BinaryField': 'BLOB',
|
|---|
| 66 | + 'BlobField': 'BLOB',
|
|---|
| 67 | 'BooleanField': 'bool',
|
|---|
| 68 | 'CharField': 'varchar(%(max_length)s)',
|
|---|
| 69 | 'CommaSeparatedIntegerField': 'varchar(%(max_length)s)',
|
|---|
| 70 | Index: django/db/backends/mysql/base.py
|
|---|
| 71 | ===================================================================
|
|---|
| 72 | --- django/db/backends/mysql/base.py (revision 9673)
|
|---|
| 73 | +++ django/db/backends/mysql/base.py (working copy)
|
|---|
| 74 | @@ -30,6 +30,7 @@
|
|---|
| 75 | from django.db.backends.mysql.introspection import DatabaseIntrospection
|
|---|
| 76 | from django.db.backends.mysql.validation import DatabaseValidation
|
|---|
| 77 | from django.utils.safestring import SafeString, SafeUnicode
|
|---|
| 78 | +from django.utils.encoding import smart_unicode
|
|---|
| 79 |
|
|---|
| 80 | # Raise exceptions for database warnings if DEBUG is on
|
|---|
| 81 | from django.conf import settings
|
|---|
| 82 | @@ -46,10 +47,22 @@
|
|---|
| 83 | # add special handling for SafeUnicode and SafeString as MySQLdb's type
|
|---|
| 84 | # checking is too tight to catch those (see Django ticket #6052).
|
|---|
| 85 | django_conversions = conversions.copy()
|
|---|
| 86 | +
|
|---|
| 87 | +binstr_conversion = [(FLAG.BINARY, buffer),
|
|---|
| 88 | + (FLAG.BLOB, smart_unicode),
|
|---|
| 89 | + ]
|
|---|
| 90 | +
|
|---|
| 91 | django_conversions.update({
|
|---|
| 92 | FIELD_TYPE.TIME: util.typecast_time,
|
|---|
| 93 | FIELD_TYPE.DECIMAL: util.typecast_decimal,
|
|---|
| 94 | FIELD_TYPE.NEWDECIMAL: util.typecast_decimal,
|
|---|
| 95 | + FIELD_TYPE.TINY_BLOB: binstr_conversion,
|
|---|
| 96 | + FIELD_TYPE.MEDIUM_BLOB: binstr_conversion,
|
|---|
| 97 | + FIELD_TYPE.LONG_BLOB: binstr_conversion,
|
|---|
| 98 | + FIELD_TYPE.BLOB: binstr_conversion,
|
|---|
| 99 | + FIELD_TYPE.VARCHAR: binstr_conversion,
|
|---|
| 100 | + FIELD_TYPE.VAR_STRING: binstr_conversion,
|
|---|
| 101 | + FIELD_TYPE.STRING: binstr_conversion,
|
|---|
| 102 | })
|
|---|
| 103 |
|
|---|
| 104 | # This should match the numerical portion of the version numbers (we can treat
|
|---|
| 105 | Index: django/db/backends/mysql/introspection.py
|
|---|
| 106 | ===================================================================
|
|---|
| 107 | --- django/db/backends/mysql/introspection.py (revision 9673)
|
|---|
| 108 | +++ django/db/backends/mysql/introspection.py (working copy)
|
|---|
| 109 | @@ -7,7 +7,10 @@
|
|---|
| 110 |
|
|---|
| 111 | class DatabaseIntrospection(BaseDatabaseIntrospection):
|
|---|
| 112 | data_types_reverse = {
|
|---|
| 113 | - FIELD_TYPE.BLOB: 'TextField',
|
|---|
| 114 | + FIELD_TYPE.BLOB: 'BlobField',
|
|---|
| 115 | + FIELD_TYPE.LONG_BLOB: 'BlobField',
|
|---|
| 116 | + FIELD_TYPE.TINY_BLOB: 'BlobField',
|
|---|
| 117 | + FIELD_TYPE.MEDIUM_BLOB: 'BlobField',
|
|---|
| 118 | FIELD_TYPE.CHAR: 'CharField',
|
|---|
| 119 | FIELD_TYPE.DECIMAL: 'DecimalField',
|
|---|
| 120 | FIELD_TYPE.NEWDECIMAL: 'DecimalField',
|
|---|
| 121 | Index: django/db/backends/mysql/creation.py
|
|---|
| 122 | ===================================================================
|
|---|
| 123 | --- django/db/backends/mysql/creation.py (revision 9673)
|
|---|
| 124 | +++ django/db/backends/mysql/creation.py (working copy)
|
|---|
| 125 | @@ -8,6 +8,8 @@
|
|---|
| 126 | # If a column type is set to None, it won't be included in the output.
|
|---|
| 127 | data_types = {
|
|---|
| 128 | 'AutoField': 'integer AUTO_INCREMENT',
|
|---|
| 129 | + 'BinaryField': 'varbinary(%(max_length)s)',
|
|---|
| 130 | + 'BlobField': 'blob',
|
|---|
| 131 | 'BooleanField': 'bool',
|
|---|
| 132 | 'CharField': 'varchar(%(max_length)s)',
|
|---|
| 133 | 'CommaSeparatedIntegerField': 'varchar(%(max_length)s)',
|
|---|
| 134 | @@ -63,4 +65,4 @@
|
|---|
| 135 | field.rel.to._meta.db_table, field.rel.to._meta.pk.column)
|
|---|
| 136 | ]
|
|---|
| 137 | return table_output, deferred
|
|---|
| 138 | -
|
|---|
| 139 | \ No newline at end of file
|
|---|
| 140 | +
|
|---|
| 141 | Index: django/db/backends/__init__.py
|
|---|
| 142 | ===================================================================
|
|---|
| 143 | --- django/db/backends/__init__.py (revision 9673)
|
|---|
| 144 | +++ django/db/backends/__init__.py (working copy)
|
|---|
| 145 | @@ -172,7 +172,11 @@
|
|---|
| 146 | from django.utils.encoding import smart_unicode, force_unicode
|
|---|
| 147 |
|
|---|
| 148 | # Convert params to contain Unicode values.
|
|---|
| 149 | - to_unicode = lambda s: force_unicode(s, strings_only=True)
|
|---|
| 150 | + def to_unicode(s):
|
|---|
| 151 | + if isinstance(s,buffer):
|
|---|
| 152 | + return u'<binary data buffer size %d>' % len(s)
|
|---|
| 153 | + return force_unicode(s, strings_only=True)
|
|---|
| 154 | +
|
|---|
| 155 | if isinstance(params, (list, tuple)):
|
|---|
| 156 | u_params = tuple([to_unicode(val) for val in params])
|
|---|
| 157 | else:
|
|---|