Refactored get_max_name_length() to DatabaseOperations.max_name_length(). Refs #5106
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5960 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
d3e69c3a47
commit
e4b7e369dd
|
@ -148,7 +148,7 @@ def sql_delete(app, style):
|
|||
(style.SQL_KEYWORD('ALTER TABLE'),
|
||||
style.SQL_TABLE(backend.quote_name(table)),
|
||||
style.SQL_KEYWORD(connection.ops.drop_foreignkey_sql()),
|
||||
style.SQL_FIELD(truncate_name(r_name, backend.get_max_name_length()))))
|
||||
style.SQL_FIELD(truncate_name(r_name, connection.ops.max_name_length()))))
|
||||
del references_to_delete[model]
|
||||
if model._meta.has_auto_field and hasattr(backend, 'get_drop_sequence'):
|
||||
output.append(backend.get_drop_sequence(model._meta.db_table))
|
||||
|
@ -297,7 +297,7 @@ def sql_for_pending_references(model, style, pending_references):
|
|||
# So we are careful with character usage here.
|
||||
r_name = '%s_refs_%s_%x' % (r_col, col, abs(hash((r_table, table))))
|
||||
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, connection.ops.max_name_length()),
|
||||
backend.quote_name(r_col), backend.quote_name(table), backend.quote_name(col),
|
||||
connection.ops.deferrable_sql()))
|
||||
del pending_references[model]
|
||||
|
|
|
@ -119,3 +119,10 @@ class BaseDatabaseOperations(object):
|
|||
if offset and offset != 0:
|
||||
sql += " OFFSET %s" % offset
|
||||
return sql
|
||||
|
||||
def max_name_length(self):
|
||||
"""
|
||||
Returns the maximum length of table and column names, or None if there
|
||||
is no limit.
|
||||
"""
|
||||
return None
|
||||
|
|
|
@ -106,9 +106,6 @@ def get_random_function_sql():
|
|||
def get_pk_default_value():
|
||||
return "DEFAULT"
|
||||
|
||||
def get_max_name_length():
|
||||
return None
|
||||
|
||||
def get_start_transaction_sql():
|
||||
return "BEGIN;"
|
||||
|
||||
|
|
|
@ -45,7 +45,6 @@ dictfetchmany = complain
|
|||
dictfetchall = complain
|
||||
get_random_function_sql = complain
|
||||
get_pk_default_value = complain
|
||||
get_max_name_length = ignore
|
||||
get_start_transaction_sql = complain
|
||||
get_sql_flush = complain
|
||||
get_sql_sequence_reset = complain
|
||||
|
|
|
@ -168,9 +168,6 @@ def get_random_function_sql():
|
|||
def get_pk_default_value():
|
||||
return "DEFAULT"
|
||||
|
||||
def get_max_name_length():
|
||||
return None;
|
||||
|
||||
def get_start_transaction_sql():
|
||||
return "BEGIN;"
|
||||
|
||||
|
|
|
@ -187,9 +187,6 @@ def get_random_function_sql():
|
|||
def get_pk_default_value():
|
||||
return "DEFAULT"
|
||||
|
||||
def get_max_name_length():
|
||||
return None;
|
||||
|
||||
def get_start_transaction_sql():
|
||||
return "BEGIN;"
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ class DatabaseOperations(BaseDatabaseOperations):
|
|||
return " DEFERRABLE INITIALLY DEFERRED"
|
||||
|
||||
def last_insert_id(self, cursor, table_name, pk_name):
|
||||
sq_name = util.truncate_name(table_name, get_max_name_length()-3)
|
||||
sq_name = util.truncate_name(table_name, self.max_name_length() - 3)
|
||||
cursor.execute('SELECT %s_sq.currval FROM dual' % sq_name)
|
||||
return cursor.fetchone()[0]
|
||||
|
||||
|
@ -67,6 +67,9 @@ class DatabaseOperations(BaseDatabaseOperations):
|
|||
# Instead, they are handled in django/db/backends/oracle/query.py.
|
||||
return ""
|
||||
|
||||
def max_name_length(self):
|
||||
return 30
|
||||
|
||||
class DatabaseWrapper(BaseDatabaseWrapper):
|
||||
ops = DatabaseOperations()
|
||||
|
||||
|
@ -170,7 +173,7 @@ def quote_name(name):
|
|||
# always defaults to uppercase.
|
||||
# We simplify things by making Oracle identifiers always uppercase.
|
||||
if not name.startswith('"') and not name.endswith('"'):
|
||||
name = '"%s"' % util.truncate_name(name.upper(), get_max_name_length())
|
||||
name = '"%s"' % util.truncate_name(name.upper(), DatabaseOperations().max_name_length())
|
||||
return name.upper()
|
||||
|
||||
dictfetchone = util.dictfetchone
|
||||
|
@ -189,9 +192,6 @@ def get_random_function_sql():
|
|||
def get_pk_default_value():
|
||||
return "DEFAULT"
|
||||
|
||||
def get_max_name_length():
|
||||
return 30
|
||||
|
||||
def get_start_transaction_sql():
|
||||
return None
|
||||
|
||||
|
@ -249,7 +249,7 @@ def get_sql_flush(style, tables, sequences):
|
|||
return []
|
||||
|
||||
def get_sequence_name(table):
|
||||
name_length = get_max_name_length() - 3
|
||||
name_length = DatabaseOperations().max_name_length() - 3
|
||||
return '%s_SQ' % util.truncate_name(table, name_length).upper()
|
||||
|
||||
def get_sql_sequence_reset(style, model_list):
|
||||
|
@ -271,7 +271,7 @@ def get_sql_sequence_reset(style, model_list):
|
|||
return output
|
||||
|
||||
def get_trigger_name(table):
|
||||
name_length = get_max_name_length() - 3
|
||||
name_length = DatabaseOperations().max_name_length() - 3
|
||||
return '%s_TR' % util.truncate_name(table, name_length).upper()
|
||||
|
||||
def get_query_set_class(DefaultQuerySet):
|
||||
|
|
|
@ -137,9 +137,6 @@ def get_random_function_sql():
|
|||
def get_pk_default_value():
|
||||
return "DEFAULT"
|
||||
|
||||
def get_max_name_length():
|
||||
return None
|
||||
|
||||
def get_start_transaction_sql():
|
||||
return "BEGIN;"
|
||||
|
||||
|
|
|
@ -91,9 +91,6 @@ def get_random_function_sql():
|
|||
def get_pk_default_value():
|
||||
return "DEFAULT"
|
||||
|
||||
def get_max_name_length():
|
||||
return None
|
||||
|
||||
def get_start_transaction_sql():
|
||||
return "BEGIN;"
|
||||
|
||||
|
|
|
@ -121,9 +121,6 @@ def get_random_function_sql():
|
|||
def get_pk_default_value():
|
||||
return "NULL"
|
||||
|
||||
def get_max_name_length():
|
||||
return None
|
||||
|
||||
def get_start_transaction_sql():
|
||||
return "BEGIN;"
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ class Options(object):
|
|||
del self.meta
|
||||
|
||||
def _prepare(self, model):
|
||||
from django.db import backend
|
||||
from django.db import connection
|
||||
from django.db.backends.util import truncate_name
|
||||
if self.order_with_respect_to:
|
||||
self.order_with_respect_to = self.get_field(self.order_with_respect_to)
|
||||
|
@ -79,8 +79,7 @@ class Options(object):
|
|||
# If the db_table wasn't provided, use the app_label + module_name.
|
||||
if not self.db_table:
|
||||
self.db_table = "%s_%s" % (self.app_label, self.module_name)
|
||||
self.db_table = truncate_name(self.db_table,
|
||||
backend.get_max_name_length())
|
||||
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
|
||||
|
||||
def add_field(self, field):
|
||||
# Insert the given field in the order in which it was created, using
|
||||
|
|
Loading…
Reference in New Issue