1
0
mirror of https://github.com/django/django.git synced 2025-10-27 23:56:08 +00:00

Fixed #21844: Move quote_parameter off of Operations and rename

This commit is contained in:
Andrew Godwin
2014-02-09 12:41:55 +00:00
parent 5cc0555603
commit 42607a9e33
10 changed files with 55 additions and 51 deletions

View File

@@ -1,5 +1,7 @@
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)