From b105a528828377757e3c654bcd3221406409ab25 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Mon, 20 Aug 2007 03:08:32 +0000 Subject: [PATCH] Refactored get_drop_sequence() to DatabaseOperations.drop_sequence_sql(). Refs #5106 git-svn-id: http://code.djangoproject.com/svn/django/trunk@5978 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/core/management/sql.py | 11 +++++++---- django/db/backends/__init__.py | 7 +++++++ django/db/backends/oracle/base.py | 6 +++--- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/django/core/management/sql.py b/django/core/management/sql.py index 4db32fda74..2c495e40dd 100644 --- a/django/core/management/sql.py +++ b/django/core/management/sql.py @@ -151,8 +151,10 @@ def sql_delete(app, style): style.SQL_KEYWORD(connection.ops.drop_foreignkey_sql()), 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)) + if model._meta.has_auto_field: + ds = connection.ops.drop_sequence_sql(model._meta.db_table) + if ds: + output.append(ds) # Output DROP TABLE statements for many-to-many tables. for model in app_models: @@ -161,8 +163,9 @@ def sql_delete(app, style): if cursor and table_name_converter(f.m2m_db_table()) in table_names: output.append("%s %s;" % (style.SQL_KEYWORD('DROP TABLE'), style.SQL_TABLE(qn(f.m2m_db_table())))) - if hasattr(backend, 'get_drop_sequence'): - output.append(backend.get_drop_sequence("%s_%s" % (model._meta.db_table, f.column))) + ds = connection.ops.drop_sequence_sql("%s_%s" % (model._meta.db_table, f.column)) + if ds: + output.append(ds) app_label = app_models[0]._meta.app_label diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py index 01cc025608..f3c6f59258 100644 --- a/django/db/backends/__init__.py +++ b/django/db/backends/__init__.py @@ -103,6 +103,13 @@ class BaseDatabaseOperations(object): """ return "DROP CONSTRAINT" + def drop_sequence_sql(self, table): + """ + Returns any SQL necessary to drop the sequence for the given table. + Returns None if no SQL is necessary. + """ + return None + def field_cast_sql(self, db_type): """ Given a column type (e.g. 'BLOB', 'VARCHAR'), returns the SQL necessary diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py index 1a23d36709..578576a26f 100644 --- a/django/db/backends/oracle/base.py +++ b/django/db/backends/oracle/base.py @@ -66,6 +66,9 @@ class DatabaseOperations(BaseDatabaseOperations): def deferrable_sql(self): return " DEFERRABLE INITIALLY DEFERRED" + def drop_sequence_sql(self, table): + return "DROP SEQUENCE %s;" % self.quote_name(get_sequence_name(table)) + def field_cast_sql(self, db_type): if db_type.endswith('LOB'): return "DBMS_LOB.SUBSTR(%s)" @@ -468,9 +471,6 @@ def to_unicode(s): return force_unicode(s) return s -def get_drop_sequence(table): - return "DROP SEQUENCE %s;" % DatabaseOperations().quote_name(get_sequence_name(table)) - def _get_sequence_reset_sql(): # TODO: colorize this SQL code with style.SQL_KEYWORD(), etc. return """