Skip to content

Commit

Permalink
Refactored get_drop_sequence() to DatabaseOperations.drop_sequence_sq…
Browse files Browse the repository at this point in the history
…l(). Refs #5106

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5978 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
adrianholovaty committed Aug 20, 2007
1 parent 4c5248f commit b105a52
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
11 changes: 7 additions & 4 deletions django/core/management/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand Down
7 changes: 7 additions & 0 deletions django/db/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ def drop_foreignkey_sql(self):
"""
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
Expand Down
6 changes: 3 additions & 3 deletions django/db/backends/oracle/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def datetime_cast_sql(self):
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)"
Expand Down Expand Up @@ -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 """
Expand Down

0 comments on commit b105a52

Please sign in to comment.