mirror of
				https://github.com/django/django.git
				synced 2025-10-30 17:16:10 +00:00 
			
		
		
		
	magic-removal: Fixed #1082 -- Added a 'supports_constraints' variable 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
This commit is contained in:
		| @@ -117,18 +117,19 @@ def get_sql_create(app): | |||||||
|  |  | ||||||
|         # Take care of any ALTER TABLE statements to add constraints |         # Take care of any ALTER TABLE statements to add constraints | ||||||
|         # after the fact. |         # after the fact. | ||||||
|         if klass in pending_references: |         if backend.supports_constraints: | ||||||
|             for rel_class, f in pending_references[klass]: |             if klass in pending_references: | ||||||
|                 rel_opts = rel_class._meta |                 for rel_class, f in pending_references[klass]: | ||||||
|                 r_table = rel_opts.db_table |                     rel_opts = rel_class._meta | ||||||
|                 r_col = f.column |                     r_table = rel_opts.db_table | ||||||
|                 table = opts.db_table |                     r_col = f.column | ||||||
|                 col = opts.get_field(f.rel.field_name).column |                     table = opts.db_table | ||||||
|                 final_output.append('ALTER TABLE %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s);' % \ |                     col = opts.get_field(f.rel.field_name).column | ||||||
|                     (backend.quote_name(r_table), |                     final_output.append('ALTER TABLE %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s);' % \ | ||||||
|                     backend.quote_name("%s_referencing_%s_%s" % (r_col, table, col)), |                         (backend.quote_name(r_table), | ||||||
|                     backend.quote_name(r_col), backend.quote_name(table), backend.quote_name(col))) |                         backend.quote_name("%s_referencing_%s_%s" % (r_col, table, col)), | ||||||
|             del pending_references[klass] |                         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. |         # Keep track of the fact that we've created the table for this model. | ||||||
|         models_output.add(klass) |         models_output.add(klass) | ||||||
|   | |||||||
| @@ -76,6 +76,8 @@ class DatabaseWrapper: | |||||||
|             self.connection.close() |             self.connection.close() | ||||||
|             self.connection = None |             self.connection = None | ||||||
|  |  | ||||||
|  | supports_constraints = True | ||||||
|  |  | ||||||
| def quote_name(name): | def quote_name(name): | ||||||
|     if name.startswith('[') and name.endswith(']'): |     if name.startswith('[') and name.endswith(']'): | ||||||
|         return name # Quoting once is enough. |         return name # Quoting once is enough. | ||||||
|   | |||||||
| @@ -83,6 +83,8 @@ class DatabaseWrapper: | |||||||
|             self.connection.close() |             self.connection.close() | ||||||
|             self.connection = None |             self.connection = None | ||||||
|  |  | ||||||
|  | supports_constraints = True | ||||||
|  |  | ||||||
| def quote_name(name): | def quote_name(name): | ||||||
|     if name.startswith("`") and name.endswith("`"): |     if name.startswith("`") and name.endswith("`"): | ||||||
|         return name # Quoting once is enough. |         return name # Quoting once is enough. | ||||||
|   | |||||||
| @@ -49,6 +49,8 @@ class DatabaseWrapper: | |||||||
|             self.connection.close() |             self.connection.close() | ||||||
|             self.connection = None |             self.connection = None | ||||||
|  |  | ||||||
|  | supports_constraints = True | ||||||
|  |  | ||||||
| def quote_name(name): | def quote_name(name): | ||||||
|     if name.startswith('"') and name.endswith('"'): |     if name.startswith('"') and name.endswith('"'): | ||||||
|         return name # Quoting once is enough. |         return name # Quoting once is enough. | ||||||
|   | |||||||
| @@ -70,6 +70,8 @@ class SQLiteCursorWrapper(Database.Cursor): | |||||||
|         # XXX this seems too simple to be correct... is this right? |         # XXX this seems too simple to be correct... is this right? | ||||||
|         return query % tuple("?" * num_params) |         return query % tuple("?" * num_params) | ||||||
|  |  | ||||||
|  | supports_constraints = False | ||||||
|  |  | ||||||
| def quote_name(name): | def quote_name(name): | ||||||
|     if name.startswith('"') and name.endswith('"'): |     if name.startswith('"') and name.endswith('"'): | ||||||
|         return name # Quoting once is enough. |         return name # Quoting once is enough. | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user