Fixed #26140 -- Suppressed MySQL warning when inserting binary content

Thanks Tim Graham for the review.
This commit is contained in:
Claude Paroz 2016-02-13 19:07:58 +01:00
parent cacc7e85e1
commit 204e00c0c5
3 changed files with 13 additions and 0 deletions

View File

@ -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.

View File

@ -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

View File

@ -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