Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactored get_max_name_length() to DatabaseOperations.max_name_lengt…

…h(). Refs #5106

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5960 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit e4b7e369ddc511dac78e1bf735e927c5fe0afe68 1 parent d3e69c3
@adrianholovaty adrianholovaty authored
View
4 django/core/management/sql.py
@@ -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]
View
7 django/db/backends/__init__.py
@@ -119,3 +119,10 @@ def limit_offset_sql(self, limit, offset=None):
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
View
3  django/db/backends/ado_mssql/base.py
@@ -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;"
View
1  django/db/backends/dummy/base.py
@@ -45,7 +45,6 @@ def close(self):
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
View
3  django/db/backends/mysql/base.py
@@ -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;"
View
3  django/db/backends/mysql_old/base.py
@@ -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;"
View
14 django/db/backends/oracle/base.py
@@ -58,7 +58,7 @@ def deferrable_sql(self):
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 @@ def limit_offset_sql(self, limit, offset=None):
# 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):
View
3  django/db/backends/postgresql/base.py
@@ -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;"
View
3  django/db/backends/postgresql_psycopg2/base.py
@@ -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;"
View
3  django/db/backends/sqlite3/base.py
@@ -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;"
View
5 django/db/models/options.py
@@ -63,7 +63,7 @@ def contribute_to_class(self, cls, name):
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 @@ def _prepare(self, model):
# 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
Please sign in to comment.
Something went wrong with that request. Please try again.