Skip to content

Commit

Permalink
Fixed #26140 -- Suppressed MySQL warning when inserting binary content
Browse files Browse the repository at this point in the history
Thanks Tim Graham for the review.
  • Loading branch information
claudep committed Mar 14, 2016
1 parent cacc7e8 commit 204e00c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions django/db/backends/base/operations.py
Expand Up @@ -578,6 +578,13 @@ def combine_expression(self, connector, sub_expressions):
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.
Expand Down
3 changes: 3 additions & 0 deletions django/db/backends/mysql/operations.py
Expand Up @@ -212,6 +212,9 @@ def convert_uuidfield_value(self, value, expression, connection, context):
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
Expand Down
3 changes: 3 additions & 0 deletions django/db/models/fields/__init__.py
Expand Up @@ -2371,6 +2371,9 @@ def deconstruct(self):
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
Expand Down

0 comments on commit 204e00c

Please sign in to comment.