mirror of https://github.com/django/django.git
Refactored get_deferrable_sql() to DatabaseOperations.deferrable_sql(). Refs #5106
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5955 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
ed8e392f77
commit
8e84d35d38
|
@ -243,7 +243,7 @@ def sql_model_create(model, style, known_models=set()):
|
||||||
field_output.append(style.SQL_KEYWORD('REFERENCES') + ' ' + \
|
field_output.append(style.SQL_KEYWORD('REFERENCES') + ' ' + \
|
||||||
style.SQL_TABLE(backend.quote_name(f.rel.to._meta.db_table)) + ' (' + \
|
style.SQL_TABLE(backend.quote_name(f.rel.to._meta.db_table)) + ' (' + \
|
||||||
style.SQL_FIELD(backend.quote_name(f.rel.to._meta.get_field(f.rel.field_name).column)) + ')' +
|
style.SQL_FIELD(backend.quote_name(f.rel.to._meta.get_field(f.rel.field_name).column)) + ')' +
|
||||||
backend.get_deferrable_sql()
|
connection.ops.deferrable_sql()
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# We haven't yet created the table to which this field
|
# We haven't yet created the table to which this field
|
||||||
|
@ -280,7 +280,7 @@ def sql_for_pending_references(model, style, pending_references):
|
||||||
"""
|
"""
|
||||||
Returns any ALTER TABLE statements to add constraints after the fact.
|
Returns any ALTER TABLE statements to add constraints after the fact.
|
||||||
"""
|
"""
|
||||||
from django.db import backend
|
from django.db import backend, connection
|
||||||
from django.db.backends.util import truncate_name
|
from django.db.backends.util import truncate_name
|
||||||
|
|
||||||
final_output = []
|
final_output = []
|
||||||
|
@ -299,12 +299,12 @@ def sql_for_pending_references(model, style, pending_references):
|
||||||
final_output.append(style.SQL_KEYWORD('ALTER TABLE') + ' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s)%s;' % \
|
final_output.append(style.SQL_KEYWORD('ALTER TABLE') + ' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s)%s;' % \
|
||||||
(backend.quote_name(r_table), truncate_name(r_name, backend.get_max_name_length()),
|
(backend.quote_name(r_table), truncate_name(r_name, backend.get_max_name_length()),
|
||||||
backend.quote_name(r_col), backend.quote_name(table), backend.quote_name(col),
|
backend.quote_name(r_col), backend.quote_name(table), backend.quote_name(col),
|
||||||
backend.get_deferrable_sql()))
|
connection.ops.deferrable_sql()))
|
||||||
del pending_references[model]
|
del pending_references[model]
|
||||||
return final_output
|
return final_output
|
||||||
|
|
||||||
def many_to_many_sql_for_model(model, style):
|
def many_to_many_sql_for_model(model, style):
|
||||||
from django.db import backend, models
|
from django.db import backend, connection, models
|
||||||
from django.contrib.contenttypes import generic
|
from django.contrib.contenttypes import generic
|
||||||
|
|
||||||
opts = model._meta
|
opts = model._meta
|
||||||
|
@ -329,14 +329,14 @@ def many_to_many_sql_for_model(model, style):
|
||||||
style.SQL_KEYWORD('NOT NULL REFERENCES'),
|
style.SQL_KEYWORD('NOT NULL REFERENCES'),
|
||||||
style.SQL_TABLE(backend.quote_name(opts.db_table)),
|
style.SQL_TABLE(backend.quote_name(opts.db_table)),
|
||||||
style.SQL_FIELD(backend.quote_name(opts.pk.column)),
|
style.SQL_FIELD(backend.quote_name(opts.pk.column)),
|
||||||
backend.get_deferrable_sql()))
|
connection.ops.deferrable_sql()))
|
||||||
table_output.append(' %s %s %s %s (%s)%s,' % \
|
table_output.append(' %s %s %s %s (%s)%s,' % \
|
||||||
(style.SQL_FIELD(backend.quote_name(f.m2m_reverse_name())),
|
(style.SQL_FIELD(backend.quote_name(f.m2m_reverse_name())),
|
||||||
style.SQL_COLTYPE(models.ForeignKey(f.rel.to).db_type()),
|
style.SQL_COLTYPE(models.ForeignKey(f.rel.to).db_type()),
|
||||||
style.SQL_KEYWORD('NOT NULL REFERENCES'),
|
style.SQL_KEYWORD('NOT NULL REFERENCES'),
|
||||||
style.SQL_TABLE(backend.quote_name(f.rel.to._meta.db_table)),
|
style.SQL_TABLE(backend.quote_name(f.rel.to._meta.db_table)),
|
||||||
style.SQL_FIELD(backend.quote_name(f.rel.to._meta.pk.column)),
|
style.SQL_FIELD(backend.quote_name(f.rel.to._meta.pk.column)),
|
||||||
backend.get_deferrable_sql()))
|
connection.ops.deferrable_sql()))
|
||||||
table_output.append(' %s (%s, %s)%s' % \
|
table_output.append(' %s (%s, %s)%s' % \
|
||||||
(style.SQL_KEYWORD('UNIQUE'),
|
(style.SQL_KEYWORD('UNIQUE'),
|
||||||
style.SQL_FIELD(backend.quote_name(f.m2m_column_name())),
|
style.SQL_FIELD(backend.quote_name(f.m2m_column_name())),
|
||||||
|
|
|
@ -78,3 +78,10 @@ class BaseDatabaseOperations(object):
|
||||||
method should return None if no casting is necessary.
|
method should return None if no casting is necessary.
|
||||||
"""
|
"""
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def deferrable_sql(self):
|
||||||
|
"""
|
||||||
|
Returns the SQL necessary to make a constraint "initially deferred"
|
||||||
|
during a CREATE TABLE statement.
|
||||||
|
"""
|
||||||
|
return ''
|
||||||
|
|
|
@ -60,6 +60,9 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||||
if lookup_type == 'day':
|
if lookup_type == 'day':
|
||||||
return "Convert(datetime, Convert(varchar(12), %s))" % field_name
|
return "Convert(datetime, Convert(varchar(12), %s))" % field_name
|
||||||
|
|
||||||
|
def deferrable_sql(self):
|
||||||
|
return " DEFERRABLE INITIALLY DEFERRED"
|
||||||
|
|
||||||
class DatabaseWrapper(BaseDatabaseWrapper):
|
class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
ops = DatabaseOperations()
|
ops = DatabaseOperations()
|
||||||
|
|
||||||
|
@ -107,9 +110,6 @@ def get_limit_offset_sql(limit, offset=None):
|
||||||
def get_random_function_sql():
|
def get_random_function_sql():
|
||||||
return "RAND()"
|
return "RAND()"
|
||||||
|
|
||||||
def get_deferrable_sql():
|
|
||||||
return " DEFERRABLE INITIALLY DEFERRED"
|
|
||||||
|
|
||||||
def get_fulltext_search_sql(field_name):
|
def get_fulltext_search_sql(field_name):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,6 @@ dictfetchall = complain
|
||||||
get_last_insert_id = complain
|
get_last_insert_id = complain
|
||||||
get_limit_offset_sql = complain
|
get_limit_offset_sql = complain
|
||||||
get_random_function_sql = complain
|
get_random_function_sql = complain
|
||||||
get_deferrable_sql = complain
|
|
||||||
get_fulltext_search_sql = complain
|
get_fulltext_search_sql = complain
|
||||||
get_drop_foreignkey_sql = complain
|
get_drop_foreignkey_sql = complain
|
||||||
get_pk_default_value = complain
|
get_pk_default_value = complain
|
||||||
|
|
|
@ -161,9 +161,6 @@ def get_limit_offset_sql(limit, offset=None):
|
||||||
def get_random_function_sql():
|
def get_random_function_sql():
|
||||||
return "RAND()"
|
return "RAND()"
|
||||||
|
|
||||||
def get_deferrable_sql():
|
|
||||||
return ""
|
|
||||||
|
|
||||||
def get_fulltext_search_sql(field_name):
|
def get_fulltext_search_sql(field_name):
|
||||||
return 'MATCH (%s) AGAINST (%%s IN BOOLEAN MODE)' % field_name
|
return 'MATCH (%s) AGAINST (%%s IN BOOLEAN MODE)' % field_name
|
||||||
|
|
||||||
|
|
|
@ -180,9 +180,6 @@ def get_limit_offset_sql(limit, offset=None):
|
||||||
def get_random_function_sql():
|
def get_random_function_sql():
|
||||||
return "RAND()"
|
return "RAND()"
|
||||||
|
|
||||||
def get_deferrable_sql():
|
|
||||||
return ""
|
|
||||||
|
|
||||||
def get_fulltext_search_sql(field_name):
|
def get_fulltext_search_sql(field_name):
|
||||||
return 'MATCH (%s) AGAINST (%%s IN BOOLEAN MODE)' % field_name
|
return 'MATCH (%s) AGAINST (%%s IN BOOLEAN MODE)' % field_name
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,9 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||||
def datetime_cast_sql(self):
|
def datetime_cast_sql(self):
|
||||||
return "TO_TIMESTAMP(%s, 'YYYY-MM-DD HH24:MI:SS.FF')"
|
return "TO_TIMESTAMP(%s, 'YYYY-MM-DD HH24:MI:SS.FF')"
|
||||||
|
|
||||||
|
def deferrable_sql(self):
|
||||||
|
return " DEFERRABLE INITIALLY DEFERRED"
|
||||||
|
|
||||||
class DatabaseWrapper(BaseDatabaseWrapper):
|
class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
ops = DatabaseOperations()
|
ops = DatabaseOperations()
|
||||||
|
|
||||||
|
@ -183,9 +186,6 @@ def get_limit_offset_sql(limit, offset=None):
|
||||||
def get_random_function_sql():
|
def get_random_function_sql():
|
||||||
return "DBMS_RANDOM.RANDOM"
|
return "DBMS_RANDOM.RANDOM"
|
||||||
|
|
||||||
def get_deferrable_sql():
|
|
||||||
return " DEFERRABLE INITIALLY DEFERRED"
|
|
||||||
|
|
||||||
def get_fulltext_search_sql(field_name):
|
def get_fulltext_search_sql(field_name):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
|
@ -66,6 +66,9 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||||
# http://www.postgresql.org/docs/8.0/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC
|
# http://www.postgresql.org/docs/8.0/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC
|
||||||
return "DATE_TRUNC('%s', %s)" % (lookup_type, field_name)
|
return "DATE_TRUNC('%s', %s)" % (lookup_type, field_name)
|
||||||
|
|
||||||
|
def deferrable_sql(self):
|
||||||
|
return " DEFERRABLE INITIALLY DEFERRED"
|
||||||
|
|
||||||
class DatabaseWrapper(BaseDatabaseWrapper):
|
class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
ops = DatabaseOperations()
|
ops = DatabaseOperations()
|
||||||
|
|
||||||
|
@ -137,9 +140,6 @@ def get_limit_offset_sql(limit, offset=None):
|
||||||
def get_random_function_sql():
|
def get_random_function_sql():
|
||||||
return "RANDOM()"
|
return "RANDOM()"
|
||||||
|
|
||||||
def get_deferrable_sql():
|
|
||||||
return " DEFERRABLE INITIALLY DEFERRED"
|
|
||||||
|
|
||||||
def get_fulltext_search_sql(field_name):
|
def get_fulltext_search_sql(field_name):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,9 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||||
# http://www.postgresql.org/docs/8.0/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC
|
# http://www.postgresql.org/docs/8.0/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC
|
||||||
return "DATE_TRUNC('%s', %s)" % (lookup_type, field_name)
|
return "DATE_TRUNC('%s', %s)" % (lookup_type, field_name)
|
||||||
|
|
||||||
|
def deferrable_sql(self):
|
||||||
|
return " DEFERRABLE INITIALLY DEFERRED"
|
||||||
|
|
||||||
class DatabaseWrapper(BaseDatabaseWrapper):
|
class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
ops = DatabaseOperations()
|
ops = DatabaseOperations()
|
||||||
|
|
||||||
|
@ -91,9 +94,6 @@ def get_limit_offset_sql(limit, offset=None):
|
||||||
def get_random_function_sql():
|
def get_random_function_sql():
|
||||||
return "RANDOM()"
|
return "RANDOM()"
|
||||||
|
|
||||||
def get_deferrable_sql():
|
|
||||||
return " DEFERRABLE INITIALLY DEFERRED"
|
|
||||||
|
|
||||||
def get_fulltext_search_sql(field_name):
|
def get_fulltext_search_sql(field_name):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
|
@ -124,9 +124,6 @@ def get_limit_offset_sql(limit, offset=None):
|
||||||
def get_random_function_sql():
|
def get_random_function_sql():
|
||||||
return "RANDOM()"
|
return "RANDOM()"
|
||||||
|
|
||||||
def get_deferrable_sql():
|
|
||||||
return ""
|
|
||||||
|
|
||||||
def get_fulltext_search_sql(field_name):
|
def get_fulltext_search_sql(field_name):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue