Skip to content

Commit

Permalink
magic-removal: Fixed #1082 -- Added a 'supports_constraints' variable…
Browse files Browse the repository at this point in the history
… for each database backend, and set SQLite's to False

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1757 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
adrianholovaty committed Dec 21, 2005
1 parent aa9fa34 commit 2d4acdc
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
25 changes: 13 additions & 12 deletions django/core/management.py
Expand Up @@ -117,18 +117,19 @@ def get_sql_create(app):

# Take care of any ALTER TABLE statements to add constraints
# after the fact.
if klass in pending_references:
for rel_class, f in pending_references[klass]:
rel_opts = rel_class._meta
r_table = rel_opts.db_table
r_col = f.column
table = opts.db_table
col = opts.get_field(f.rel.field_name).column
final_output.append('ALTER TABLE %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s);' % \
(backend.quote_name(r_table),
backend.quote_name("%s_referencing_%s_%s" % (r_col, table, col)),
backend.quote_name(r_col), backend.quote_name(table), backend.quote_name(col)))
del pending_references[klass]
if backend.supports_constraints:
if klass in pending_references:
for rel_class, f in pending_references[klass]:
rel_opts = rel_class._meta
r_table = rel_opts.db_table
r_col = f.column
table = opts.db_table
col = opts.get_field(f.rel.field_name).column
final_output.append('ALTER TABLE %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s);' % \
(backend.quote_name(r_table),
backend.quote_name("%s_referencing_%s_%s" % (r_col, table, col)),
backend.quote_name(r_col), backend.quote_name(table), backend.quote_name(col)))
del pending_references[klass]

# Keep track of the fact that we've created the table for this model.
models_output.add(klass)
Expand Down
2 changes: 2 additions & 0 deletions django/db/backends/ado_mssql/base.py
Expand Up @@ -76,6 +76,8 @@ def close(self):
self.connection.close()
self.connection = None

supports_constraints = True

def quote_name(name):
if name.startswith('[') and name.endswith(']'):
return name # Quoting once is enough.
Expand Down
2 changes: 2 additions & 0 deletions django/db/backends/mysql/base.py
Expand Up @@ -83,6 +83,8 @@ def close(self):
self.connection.close()
self.connection = None

supports_constraints = True

def quote_name(name):
if name.startswith("`") and name.endswith("`"):
return name # Quoting once is enough.
Expand Down
2 changes: 2 additions & 0 deletions django/db/backends/postgresql/base.py
Expand Up @@ -49,6 +49,8 @@ def close(self):
self.connection.close()
self.connection = None

supports_constraints = True

def quote_name(name):
if name.startswith('"') and name.endswith('"'):
return name # Quoting once is enough.
Expand Down
2 changes: 2 additions & 0 deletions django/db/backends/sqlite3/base.py
Expand Up @@ -70,6 +70,8 @@ def convert_query(self, query, num_params):
# XXX this seems too simple to be correct... is this right?
return query % tuple("?" * num_params)

supports_constraints = False

def quote_name(name):
if name.startswith('"') and name.endswith('"'):
return name # Quoting once is enough.
Expand Down

0 comments on commit 2d4acdc

Please sign in to comment.