Commit 42607a9e authored by Andrew Godwin's avatar Andrew Godwin
Browse files

Fixed #21844: Move quote_parameter off of Operations and rename

parent 5cc05556
Loading
Loading
Loading
Loading
+0 −9
Original line number Diff line number Diff line
@@ -975,15 +975,6 @@ class BaseDatabaseOperations(object):
        """
        raise NotImplementedError('subclasses of BaseDatabaseOperations may require a quote_name() method')

    def quote_parameter(self, value):
        """
        Returns a quoted version of the value so it's safe to use in an SQL
        string. This should NOT be used to prepare SQL statements to send to
        the database; it is meant for outputting SQL statements to a file
        or the console for later execution by a developer/DBA.
        """
        raise NotImplementedError()

    def random_function_sql(self):
        """
        Returns an SQL expression that returns a random value.
+0 −5
Original line number Diff line number Diff line
@@ -311,11 +311,6 @@ class DatabaseOperations(BaseDatabaseOperations):
            return name  # Quoting once is enough.
        return "`%s`" % name

    def quote_parameter(self, value):
        # Inner import to allow module to fail to load gracefully
        import MySQLdb.converters
        return MySQLdb.escape(value, MySQLdb.converters.conversions)

    def random_function_sql(self):
        return 'RAND()'

+5 −0
Original line number Diff line number Diff line
@@ -24,3 +24,8 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):

    sql_create_pk = "ALTER TABLE %(table)s ADD CONSTRAINT %(name)s PRIMARY KEY (%(columns)s)"
    sql_delete_pk = "ALTER TABLE %(table)s DROP PRIMARY KEY"

    def quote_value(self, value):
        # Inner import to allow module to fail to load gracefully
        import MySQLdb.converters
        return MySQLdb.escape(value, MySQLdb.converters.conversions)
+0 −10
Original line number Diff line number Diff line
@@ -326,16 +326,6 @@ WHEN (new.%(col_name)s IS NULL)
        name = name.replace('%', '%%')
        return name.upper()

    def quote_parameter(self, value):
        if isinstance(value, (datetime.date, datetime.time, datetime.datetime)):
            return "'%s'" % value
        elif isinstance(value, six.string_types):
            return repr(value)
        elif isinstance(value, bool):
            return "1" if value else "0"
        else:
            return str(value)

    def random_function_sql(self):
        return "DBMS_RANDOM.RANDOM"

+13 −1
Original line number Diff line number Diff line
import copy
import datetime

from django.utils import six
from django.db.backends.schema import BaseDatabaseSchemaEditor
from django.db.utils import DatabaseError

@@ -15,6 +17,16 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
    sql_delete_column = "ALTER TABLE %(table)s DROP COLUMN %(column)s"
    sql_delete_table = "DROP TABLE %(table)s CASCADE CONSTRAINTS"

    def quote_value(self, value):
        if isinstance(value, (datetime.date, datetime.time, datetime.datetime)):
            return "'%s'" % value
        elif isinstance(value, six.string_types):
            return repr(value)
        elif isinstance(value, bool):
            return "1" if value else "0"
        else:
            return str(value)

    def delete_model(self, model):
        # Run superclass action
        super(DatabaseSchemaEditor, self).delete_model(model)
@@ -92,4 +104,4 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
        return self.normalize_name(for_name + "_" + suffix)

    def prepare_default(self, value):
        return self.connection.ops.quote_parameter(value)
        return self.quote_value(value)
Loading