summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Pellerin <jpellerin@gmail.com>2006-07-03 20:49:50 +0000
committerJason Pellerin <jpellerin@gmail.com>2006-07-03 20:49:50 +0000
commitd2d269ea15d409ba0ddc1032d8b0d9443d820375 (patch)
treefa1d60c8b056a144465d11c09bd12e4a3e60cfae
parent8f1d2bc98a8575302f28cb297cc29646175b31e7 (diff)
[multi-db] Made minor formatting updates. Added basic support for drop table, still needs to handle cascade.
git-svn-id: http://code.djangoproject.com/svn/django/branches/multiple-db-support@3264 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/db/backends/ansi/sql.py35
1 files changed, 30 insertions, 5 deletions
diff --git a/django/db/backends/ansi/sql.py b/django/db/backends/ansi/sql.py
index 5235e98f66..3f3f0af7a9 100644
--- a/django/db/backends/ansi/sql.py
+++ b/django/db/backends/ansi/sql.py
@@ -60,7 +60,6 @@ class SchemaBuilder(object):
info = opts.connection_info
backend = info.backend
quote_name = backend.quote_name
-
data_types = info.get_creation_module().DATA_TYPES
table_output = []
pending_references = {}
@@ -177,8 +176,9 @@ class SchemaBuilder(object):
output = []
for f in opts.many_to_many:
if not isinstance(f.rel, models.GenericRel):
- table_output = [style.SQL_KEYWORD('CREATE TABLE') + ' ' + \
- style.SQL_TABLE(quote_name(f.m2m_db_table())) + ' (']
+ table_output = [
+ style.SQL_KEYWORD('CREATE TABLE') + ' ' + \
+ style.SQL_TABLE(quote_name(f.m2m_db_table())) + ' (']
table_output.append(' %s %s %s,' % \
(style.SQL_FIELD(quote_name('id')),
style.SQL_COLTYPE(data_types['AutoField']),
@@ -204,6 +204,32 @@ class SchemaBuilder(object):
connection))
return output
+ def get_drop_table(self, model, cascade=False, style=None):
+ """Construct and return the SQL statment(s) needed to drop a model's
+ table. If cascade is true, then output additional statments to drop any
+ dependant man-many tables and drop any foreign keys that reference
+ this table.
+ """
+ if style is None:
+ style = default_style
+ opts = model._meta
+ info = opts.connection_info
+ db_table = opts.db_table
+ backend = info.backend
+ output = []
+ output.append(BoundStatement(
+ '%s %s;' % (style.SQL_KEYWORD('DROP TABLE'),
+ style.SQL_TABLE(backend.quote_name(db_table))),
+ info.connection))
+
+ if cascade:
+ # FIXME deal with my foreign keys, others that might have a foreign
+ # key TO me, and many-many
+ pass
+ # Reverse it, to deal with table dependencies.
+ output.reverse()
+ return output
+
def get_initialdata(self, model, style=None):
if style is None:
style = default_style
@@ -239,8 +265,7 @@ class SchemaBuilder(object):
"""Get the path from which to load sql initial data files for a model.
"""
return os.path.normpath(os.path.join(os.path.dirname(models.get_app(model._meta.app_label).__file__), 'sql'))
-
-
+
def get_rel_data_type(self, f):
return (f.get_internal_type() in ('AutoField', 'PositiveIntegerField',
'PositiveSmallIntegerField')) \