Loading django/db/backends/base/operations.py +3 −2 Original line number Diff line number Diff line Loading @@ -505,10 +505,11 @@ class BaseDatabaseOperations(object): return [first, second] def get_db_converters(self, expression): """Get a list of functions needed to convert field data. """ Get a list of functions needed to convert field data. Some field types on some backends do not provide data in the correct format, this is the hook for coverter functions. format, this is the hook for converter functions. """ return [] Loading django/db/backends/mysql/operations.py +10 −10 Original line number Diff line number Diff line Loading @@ -182,16 +182,21 @@ class DatabaseOperations(BaseDatabaseOperations): def get_db_converters(self, expression): converters = super(DatabaseOperations, self).get_db_converters(expression) internal_type = expression.output_field.get_internal_type() if internal_type in ['BooleanField', 'NullBooleanField']: if internal_type == 'TextField': converters.append(self.convert_textfield_value) elif internal_type in ['BooleanField', 'NullBooleanField']: converters.append(self.convert_booleanfield_value) if internal_type == 'DateTimeField': elif internal_type == 'DateTimeField': converters.append(self.convert_datetimefield_value) if internal_type == 'UUIDField': elif internal_type == 'UUIDField': converters.append(self.convert_uuidfield_value) if internal_type == 'TextField': converters.append(self.convert_textfield_value) return converters def convert_textfield_value(self, value, expression, connection, context): if value is not None: value = force_text(value) return value def convert_booleanfield_value(self, value, expression, connection, context): if value in (0, 1): value = bool(value) Loading @@ -207,8 +212,3 @@ class DatabaseOperations(BaseDatabaseOperations): if value is not None: value = uuid.UUID(value) return value def convert_textfield_value(self, value, expression, connection, context): if value is not None: value = force_text(value) return value django/db/backends/oracle/operations.py +15 −14 Original line number Diff line number Diff line Loading @@ -174,18 +174,6 @@ WHEN (new.%(col_name)s IS NULL) converters.append(self.convert_empty_values) return converters def convert_empty_values(self, value, expression, connection, context): # Oracle stores empty strings as null. We need to undo this in # order to adhere to the Django convention of using the empty # string instead of null, but only if the field accepts the # empty string. field = expression.output_field if value is None and field.empty_strings_allowed: value = '' if field.get_internal_type() == 'BinaryField': value = b'' return value def convert_textfield_value(self, value, expression, connection, context): if isinstance(value, Database.LOB): value = force_text(value.read()) Loading @@ -197,7 +185,7 @@ WHEN (new.%(col_name)s IS NULL) return value def convert_booleanfield_value(self, value, expression, connection, context): if value in (1, 0): if value in (0, 1): value = bool(value) return value Loading @@ -213,7 +201,8 @@ WHEN (new.%(col_name)s IS NULL) def convert_datefield_value(self, value, expression, connection, context): if isinstance(value, Database.Timestamp): return value.date() value = value.date() return value def convert_timefield_value(self, value, expression, connection, context): if isinstance(value, Database.Timestamp): Loading @@ -225,6 +214,18 @@ WHEN (new.%(col_name)s IS NULL) value = uuid.UUID(value) return value def convert_empty_values(self, value, expression, connection, context): # Oracle stores empty strings as null. We need to undo this in # order to adhere to the Django convention of using the empty # string instead of null, but only if the field accepts the # empty string. field = expression.output_field if value is None and field.empty_strings_allowed: value = '' if field.get_internal_type() == 'BinaryField': value = b'' return value def deferrable_sql(self): return " DEFERRABLE INITIALLY DEFERRED" Loading django/db/backends/sqlite3/operations.py +12 −9 Original line number Diff line number Diff line Loading @@ -151,15 +151,6 @@ class DatabaseOperations(BaseDatabaseOperations): converters.append(self.convert_uuidfield_value) return converters def convert_decimalfield_value(self, value, expression, connection, context): return backend_utils.typecast_decimal(expression.output_field.format_number(value)) def convert_datefield_value(self, value, expression, connection, context): if value is not None: if not isinstance(value, datetime.date): value = parse_date(value) return value def convert_datetimefield_value(self, value, expression, connection, context): if value is not None: if not isinstance(value, datetime.datetime): Loading @@ -168,12 +159,24 @@ class DatabaseOperations(BaseDatabaseOperations): value = value.replace(tzinfo=timezone.utc) return value def convert_datefield_value(self, value, expression, connection, context): if value is not None: if not isinstance(value, datetime.date): value = parse_date(value) return value def convert_timefield_value(self, value, expression, connection, context): if value is not None: if not isinstance(value, datetime.time): value = parse_time(value) return value def convert_decimalfield_value(self, value, expression, connection, context): if value is not None: value = expression.output_field.format_number(value) value = backend_utils.typecast_decimal(value) return value def convert_uuidfield_value(self, value, expression, connection, context): if value is not None: value = uuid.UUID(value) Loading Loading
django/db/backends/base/operations.py +3 −2 Original line number Diff line number Diff line Loading @@ -505,10 +505,11 @@ class BaseDatabaseOperations(object): return [first, second] def get_db_converters(self, expression): """Get a list of functions needed to convert field data. """ Get a list of functions needed to convert field data. Some field types on some backends do not provide data in the correct format, this is the hook for coverter functions. format, this is the hook for converter functions. """ return [] Loading
django/db/backends/mysql/operations.py +10 −10 Original line number Diff line number Diff line Loading @@ -182,16 +182,21 @@ class DatabaseOperations(BaseDatabaseOperations): def get_db_converters(self, expression): converters = super(DatabaseOperations, self).get_db_converters(expression) internal_type = expression.output_field.get_internal_type() if internal_type in ['BooleanField', 'NullBooleanField']: if internal_type == 'TextField': converters.append(self.convert_textfield_value) elif internal_type in ['BooleanField', 'NullBooleanField']: converters.append(self.convert_booleanfield_value) if internal_type == 'DateTimeField': elif internal_type == 'DateTimeField': converters.append(self.convert_datetimefield_value) if internal_type == 'UUIDField': elif internal_type == 'UUIDField': converters.append(self.convert_uuidfield_value) if internal_type == 'TextField': converters.append(self.convert_textfield_value) return converters def convert_textfield_value(self, value, expression, connection, context): if value is not None: value = force_text(value) return value def convert_booleanfield_value(self, value, expression, connection, context): if value in (0, 1): value = bool(value) Loading @@ -207,8 +212,3 @@ class DatabaseOperations(BaseDatabaseOperations): if value is not None: value = uuid.UUID(value) return value def convert_textfield_value(self, value, expression, connection, context): if value is not None: value = force_text(value) return value
django/db/backends/oracle/operations.py +15 −14 Original line number Diff line number Diff line Loading @@ -174,18 +174,6 @@ WHEN (new.%(col_name)s IS NULL) converters.append(self.convert_empty_values) return converters def convert_empty_values(self, value, expression, connection, context): # Oracle stores empty strings as null. We need to undo this in # order to adhere to the Django convention of using the empty # string instead of null, but only if the field accepts the # empty string. field = expression.output_field if value is None and field.empty_strings_allowed: value = '' if field.get_internal_type() == 'BinaryField': value = b'' return value def convert_textfield_value(self, value, expression, connection, context): if isinstance(value, Database.LOB): value = force_text(value.read()) Loading @@ -197,7 +185,7 @@ WHEN (new.%(col_name)s IS NULL) return value def convert_booleanfield_value(self, value, expression, connection, context): if value in (1, 0): if value in (0, 1): value = bool(value) return value Loading @@ -213,7 +201,8 @@ WHEN (new.%(col_name)s IS NULL) def convert_datefield_value(self, value, expression, connection, context): if isinstance(value, Database.Timestamp): return value.date() value = value.date() return value def convert_timefield_value(self, value, expression, connection, context): if isinstance(value, Database.Timestamp): Loading @@ -225,6 +214,18 @@ WHEN (new.%(col_name)s IS NULL) value = uuid.UUID(value) return value def convert_empty_values(self, value, expression, connection, context): # Oracle stores empty strings as null. We need to undo this in # order to adhere to the Django convention of using the empty # string instead of null, but only if the field accepts the # empty string. field = expression.output_field if value is None and field.empty_strings_allowed: value = '' if field.get_internal_type() == 'BinaryField': value = b'' return value def deferrable_sql(self): return " DEFERRABLE INITIALLY DEFERRED" Loading
django/db/backends/sqlite3/operations.py +12 −9 Original line number Diff line number Diff line Loading @@ -151,15 +151,6 @@ class DatabaseOperations(BaseDatabaseOperations): converters.append(self.convert_uuidfield_value) return converters def convert_decimalfield_value(self, value, expression, connection, context): return backend_utils.typecast_decimal(expression.output_field.format_number(value)) def convert_datefield_value(self, value, expression, connection, context): if value is not None: if not isinstance(value, datetime.date): value = parse_date(value) return value def convert_datetimefield_value(self, value, expression, connection, context): if value is not None: if not isinstance(value, datetime.datetime): Loading @@ -168,12 +159,24 @@ class DatabaseOperations(BaseDatabaseOperations): value = value.replace(tzinfo=timezone.utc) return value def convert_datefield_value(self, value, expression, connection, context): if value is not None: if not isinstance(value, datetime.date): value = parse_date(value) return value def convert_timefield_value(self, value, expression, connection, context): if value is not None: if not isinstance(value, datetime.time): value = parse_time(value) return value def convert_decimalfield_value(self, value, expression, connection, context): if value is not None: value = expression.output_field.format_number(value) value = backend_utils.typecast_decimal(value) return value def convert_uuidfield_value(self, value, expression, connection, context): if value is not None: value = uuid.UUID(value) Loading