Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Refactored get_deferrable_sql() to DatabaseOperations.deferrable_sql(…

…). Refs #5106

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5955 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 8e84d35d38d429fb00a35fd4f770ade39d7772ec 1 parent ed8e392
Adrian Holovaty authored August 19, 2007
12  django/core/management/sql.py
@@ -243,7 +243,7 @@ def sql_model_create(model, style, known_models=set()):
243 243
                 field_output.append(style.SQL_KEYWORD('REFERENCES') + ' ' + \
244 244
                     style.SQL_TABLE(backend.quote_name(f.rel.to._meta.db_table)) + ' (' + \
245 245
                     style.SQL_FIELD(backend.quote_name(f.rel.to._meta.get_field(f.rel.field_name).column)) + ')' +
246  
-                    backend.get_deferrable_sql()
  246
+                    connection.ops.deferrable_sql()
247 247
                 )
248 248
             else:
249 249
                 # We haven't yet created the table to which this field
@@ -280,7 +280,7 @@ def sql_for_pending_references(model, style, pending_references):
280 280
     """
281 281
     Returns any ALTER TABLE statements to add constraints after the fact.
282 282
     """
283  
-    from django.db import backend
  283
+    from django.db import backend, connection
284 284
     from django.db.backends.util import truncate_name
285 285
 
286 286
     final_output = []
@@ -299,12 +299,12 @@ def sql_for_pending_references(model, style, pending_references):
299 299
                 final_output.append(style.SQL_KEYWORD('ALTER TABLE') + ' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s)%s;' % \
300 300
                     (backend.quote_name(r_table), truncate_name(r_name, backend.get_max_name_length()),
301 301
                     backend.quote_name(r_col), backend.quote_name(table), backend.quote_name(col),
302  
-                    backend.get_deferrable_sql()))
  302
+                    connection.ops.deferrable_sql()))
303 303
             del pending_references[model]
304 304
     return final_output
305 305
 
306 306
 def many_to_many_sql_for_model(model, style):
307  
-    from django.db import backend, models
  307
+    from django.db import backend, connection, models
308 308
     from django.contrib.contenttypes import generic
309 309
 
310 310
     opts = model._meta
@@ -329,14 +329,14 @@ def many_to_many_sql_for_model(model, style):
329 329
                 style.SQL_KEYWORD('NOT NULL REFERENCES'),
330 330
                 style.SQL_TABLE(backend.quote_name(opts.db_table)),
331 331
                 style.SQL_FIELD(backend.quote_name(opts.pk.column)),
332  
-                backend.get_deferrable_sql()))
  332
+                connection.ops.deferrable_sql()))
333 333
             table_output.append('    %s %s %s %s (%s)%s,' % \
334 334
                 (style.SQL_FIELD(backend.quote_name(f.m2m_reverse_name())),
335 335
                 style.SQL_COLTYPE(models.ForeignKey(f.rel.to).db_type()),
336 336
                 style.SQL_KEYWORD('NOT NULL REFERENCES'),
337 337
                 style.SQL_TABLE(backend.quote_name(f.rel.to._meta.db_table)),
338 338
                 style.SQL_FIELD(backend.quote_name(f.rel.to._meta.pk.column)),
339  
-                backend.get_deferrable_sql()))
  339
+                connection.ops.deferrable_sql()))
340 340
             table_output.append('    %s (%s, %s)%s' % \
341 341
                 (style.SQL_KEYWORD('UNIQUE'),
342 342
                 style.SQL_FIELD(backend.quote_name(f.m2m_column_name())),
7  django/db/backends/__init__.py
@@ -78,3 +78,10 @@ def datetime_cast_sql(self):
78 78
         method should return None if no casting is necessary.
79 79
         """
80 80
         return None
  81
+
  82
+    def deferrable_sql(self):
  83
+        """
  84
+        Returns the SQL necessary to make a constraint "initially deferred"
  85
+        during a CREATE TABLE statement.
  86
+        """
  87
+        return ''
6  django/db/backends/ado_mssql/base.py
@@ -60,6 +60,9 @@ def date_trunc_sql(self, lookup_type, field_name):
60 60
         if lookup_type == 'day':
61 61
             return "Convert(datetime, Convert(varchar(12), %s))" % field_name
62 62
 
  63
+    def deferrable_sql(self):
  64
+        return " DEFERRABLE INITIALLY DEFERRED"
  65
+
63 66
 class DatabaseWrapper(BaseDatabaseWrapper):
64 67
     ops = DatabaseOperations()
65 68
 
@@ -107,9 +110,6 @@ def get_limit_offset_sql(limit, offset=None):
107 110
 def get_random_function_sql():
108 111
     return "RAND()"
109 112
 
110  
-def get_deferrable_sql():
111  
-    return " DEFERRABLE INITIALLY DEFERRED"
112  
-
113 113
 def get_fulltext_search_sql(field_name):
114 114
     raise NotImplementedError
115 115
 
1  django/db/backends/dummy/base.py
@@ -46,7 +46,6 @@ def close(self):
46 46
 get_last_insert_id = complain
47 47
 get_limit_offset_sql = complain
48 48
 get_random_function_sql = complain
49  
-get_deferrable_sql = complain
50 49
 get_fulltext_search_sql = complain
51 50
 get_drop_foreignkey_sql = complain
52 51
 get_pk_default_value = complain
3  django/db/backends/mysql/base.py
@@ -161,9 +161,6 @@ def get_limit_offset_sql(limit, offset=None):
161 161
 def get_random_function_sql():
162 162
     return "RAND()"
163 163
 
164  
-def get_deferrable_sql():
165  
-    return ""
166  
-
167 164
 def get_fulltext_search_sql(field_name):
168 165
     return 'MATCH (%s) AGAINST (%%s IN BOOLEAN MODE)' % field_name
169 166
 
3  django/db/backends/mysql_old/base.py
@@ -180,9 +180,6 @@ def get_limit_offset_sql(limit, offset=None):
180 180
 def get_random_function_sql():
181 181
     return "RAND()"
182 182
 
183  
-def get_deferrable_sql():
184  
-    return ""
185  
-
186 183
 def get_fulltext_search_sql(field_name):
187 184
     return 'MATCH (%s) AGAINST (%%s IN BOOLEAN MODE)' % field_name
188 185
 
6  django/db/backends/oracle/base.py
@@ -54,6 +54,9 @@ def date_trunc_sql(self, lookup_type, field_name):
54 54
     def datetime_cast_sql(self):
55 55
         return "TO_TIMESTAMP(%s, 'YYYY-MM-DD HH24:MI:SS.FF')"
56 56
 
  57
+    def deferrable_sql(self):
  58
+        return " DEFERRABLE INITIALLY DEFERRED"
  59
+
57 60
 class DatabaseWrapper(BaseDatabaseWrapper):
58 61
     ops = DatabaseOperations()
59 62
 
@@ -183,9 +186,6 @@ def get_limit_offset_sql(limit, offset=None):
183 186
 def get_random_function_sql():
184 187
     return "DBMS_RANDOM.RANDOM"
185 188
 
186  
-def get_deferrable_sql():
187  
-    return " DEFERRABLE INITIALLY DEFERRED"
188  
-
189 189
 def get_fulltext_search_sql(field_name):
190 190
     raise NotImplementedError
191 191
 
6  django/db/backends/postgresql/base.py
@@ -66,6 +66,9 @@ def date_trunc_sql(self, lookup_type, field_name):
66 66
         # http://www.postgresql.org/docs/8.0/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC
67 67
         return "DATE_TRUNC('%s', %s)" % (lookup_type, field_name)
68 68
 
  69
+    def deferrable_sql(self):
  70
+        return " DEFERRABLE INITIALLY DEFERRED"
  71
+
69 72
 class DatabaseWrapper(BaseDatabaseWrapper):
70 73
     ops = DatabaseOperations()
71 74
 
@@ -137,9 +140,6 @@ def get_limit_offset_sql(limit, offset=None):
137 140
 def get_random_function_sql():
138 141
     return "RANDOM()"
139 142
 
140  
-def get_deferrable_sql():
141  
-    return " DEFERRABLE INITIALLY DEFERRED"
142  
-
143 143
 def get_fulltext_search_sql(field_name):
144 144
     raise NotImplementedError
145 145
 
6  django/db/backends/postgresql_psycopg2/base.py
@@ -28,6 +28,9 @@ def date_trunc_sql(self, lookup_type, field_name):
28 28
         # http://www.postgresql.org/docs/8.0/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC
29 29
         return "DATE_TRUNC('%s', %s)" % (lookup_type, field_name)
30 30
 
  31
+    def deferrable_sql(self):
  32
+        return " DEFERRABLE INITIALLY DEFERRED"
  33
+
31 34
 class DatabaseWrapper(BaseDatabaseWrapper):
32 35
     ops = DatabaseOperations()
33 36
 
@@ -91,9 +94,6 @@ def get_limit_offset_sql(limit, offset=None):
91 94
 def get_random_function_sql():
92 95
     return "RANDOM()"
93 96
 
94  
-def get_deferrable_sql():
95  
-    return " DEFERRABLE INITIALLY DEFERRED"
96  
-
97 97
 def get_fulltext_search_sql(field_name):
98 98
     raise NotImplementedError
99 99
 
3  django/db/backends/sqlite3/base.py
@@ -124,9 +124,6 @@ def get_limit_offset_sql(limit, offset=None):
124 124
 def get_random_function_sql():
125 125
     return "RANDOM()"
126 126
 
127  
-def get_deferrable_sql():
128  
-    return ""
129  
-
130 127
 def get_fulltext_search_sql(field_name):
131 128
     raise NotImplementedError
132 129
 

0 notes on commit 8e84d35

Please sign in to comment.
Something went wrong with that request. Please try again.