From 204e00c0c57c34528157a739389b6935e4af2f36 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 13 Feb 2016 19:07:58 +0100 Subject: [PATCH] Fixed #26140 -- Suppressed MySQL warning when inserting binary content Thanks Tim Graham for the review. --- django/db/backends/base/operations.py | 7 +++++++ django/db/backends/mysql/operations.py | 3 +++ django/db/models/fields/__init__.py | 3 +++ 3 files changed, 13 insertions(+) diff --git a/django/db/backends/base/operations.py b/django/db/backends/base/operations.py index e3fa8904ef..6cd466411a 100644 --- a/django/db/backends/base/operations.py +++ b/django/db/backends/base/operations.py @@ -578,6 +578,13 @@ class BaseDatabaseOperations(object): def combine_duration_expression(self, connector, sub_expressions): return self.combine_expression(connector, sub_expressions) + def binary_placeholder_sql(self, value): + """ + Some backends require special syntax to insert binary content (MySQL + for example uses '_binary %s'). + """ + return '%s' + def modify_insert_params(self, placeholder, params): """Allow modification of insert parameters. Needed for Oracle Spatial backend due to #10888. diff --git a/django/db/backends/mysql/operations.py b/django/db/backends/mysql/operations.py index 8a0fe80583..963ad42f10 100644 --- a/django/db/backends/mysql/operations.py +++ b/django/db/backends/mysql/operations.py @@ -212,6 +212,9 @@ class DatabaseOperations(BaseDatabaseOperations): value = uuid.UUID(value) return value + def binary_placeholder_sql(self, value): + return '_binary %s' if value is not None else '%s' + def subtract_temporals(self, internal_type, lhs, rhs): lhs_sql, lhs_params = lhs rhs_sql, rhs_params = rhs diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index de69e5a35f..333afc5ddc 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -2371,6 +2371,9 @@ class BinaryField(Field): def get_internal_type(self): return "BinaryField" + def get_placeholder(self, value, compiler, connection): + return connection.ops.binary_placeholder_sql(value) + def get_default(self): if self.has_default() and not callable(self.default): return self.default