From e4b7e369ddc511dac78e1bf735e927c5fe0afe68 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Sun, 19 Aug 2007 23:53:39 +0000 Subject: 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 --- django/db/backends/__init__.py | 7 +++++++ django/db/backends/ado_mssql/base.py | 3 --- django/db/backends/dummy/base.py | 1 - django/db/backends/mysql/base.py | 3 --- django/db/backends/mysql_old/base.py | 3 --- django/db/backends/oracle/base.py | 14 +++++++------- django/db/backends/postgresql/base.py | 3 --- django/db/backends/postgresql_psycopg2/base.py | 3 --- django/db/backends/sqlite3/base.py | 3 --- 9 files changed, 14 insertions(+), 26 deletions(-) (limited to 'django/db/backends') diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py index e6776a19b7..5df24eb3c8 100644 --- a/django/db/backends/__init__.py +++ b/django/db/backends/__init__.py @@ -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 diff --git a/django/db/backends/ado_mssql/base.py b/django/db/backends/ado_mssql/base.py index 19dd7278d2..f42bc7e2af 100644 --- a/django/db/backends/ado_mssql/base.py +++ b/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;" diff --git a/django/db/backends/dummy/base.py b/django/db/backends/dummy/base.py index 334e5146b7..1cee9687f7 100644 --- a/django/db/backends/dummy/base.py +++ b/django/db/backends/dummy/base.py @@ -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 diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index 259034b4bb..545ae3dcdf 100644 --- a/django/db/backends/mysql/base.py +++ b/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;" diff --git a/django/db/backends/mysql_old/base.py b/django/db/backends/mysql_old/base.py index 5de2cbfda8..f445dcb8d6 100644 --- a/django/db/backends/mysql_old/base.py +++ b/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;" diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py index df153378f0..9908518d47 100644 --- a/django/db/backends/oracle/base.py +++ b/django/db/backends/oracle/base.py @@ -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): diff --git a/django/db/backends/postgresql/base.py b/django/db/backends/postgresql/base.py index 4926ddf8d1..9193e532c8 100644 --- a/django/db/backends/postgresql/base.py +++ b/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;" diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py index f8d8765e92..b1611c5848 100644 --- a/django/db/backends/postgresql_psycopg2/base.py +++ b/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;" diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py index 75c753ef22..ad792e1fa0 100644 --- a/django/db/backends/sqlite3/base.py +++ b/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;" -- cgit v1.3