Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Refactored get_sql_flush() to DatabaseOperations.sql_flush(). Refs #5106

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5963 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit aaed6e04eceef98e9ec433e86b80486ada2a668b 1 parent c44fb66
Adrian Holovaty authored August 20, 2007
6  django/core/management/sql.py
@@ -178,9 +178,9 @@ def sql_reset(app, style):
178 178
     return sql_delete(app, style) + sql_all(app, style)
179 179
 
180 180
 def sql_flush(style):
181  
-    "Returns a list of the SQL statements used to flush the database"
182  
-    from django.db import backend
183  
-    statements = backend.get_sql_flush(style, table_list(), sequence_list())
  181
+    "Returns a list of the SQL statements used to flush the database."
  182
+    from django.db import connection
  183
+    statements = connection.ops.sql_flush(style, table_list(), sequence_list())
184 184
     return statements
185 185
 
186 186
 def sql_custom(app):
11  django/db/backends/__init__.py
@@ -139,3 +139,14 @@ def random_function_sql(self):
139 139
         Returns a SQL expression that returns a random value.
140 140
         """
141 141
         return 'RANDOM()'
  142
+
  143
+    def sql_flush(self, style, tables, sequences):
  144
+        """
  145
+        Returns a list of SQL statements required to remove all data from
  146
+        the given database tables (without actually removing the tables
  147
+        themselves).
  148
+
  149
+        The `style` argument is a Style object as returned by either
  150
+        color_style() or no_style() in django.core.management.color.
  151
+        """
  152
+        raise NotImplementedError()
13  django/db/backends/ado_mssql/base.py
@@ -109,19 +109,6 @@ def get_start_transaction_sql():
109 109
 def get_tablespace_sql(tablespace, inline=False):
110 110
     return "ON %s" % quote_name(tablespace)
111 111
 
112  
-def get_sql_flush(style, tables, sequences):
113  
-    """Return a list of SQL statements required to remove all data from
114  
-    all tables in the database (without actually removing the tables
115  
-    themselves) and put the database in an empty 'initial' state
116  
-    """
117  
-    # Return a list of 'TRUNCATE x;', 'TRUNCATE y;', 'TRUNCATE z;'... style SQL statements
118  
-    # TODO - SQL not actually tested against ADO MSSQL yet!
119  
-    # TODO - autoincrement indices reset required? See other get_sql_flush() implementations
120  
-    sql_list = ['%s %s;' % \
121  
-                (style.SQL_KEYWORD('TRUNCATE'),
122  
-                 style.SQL_FIELD(quote_name(table))
123  
-                 )  for table in tables]
124  
-
125 112
 def get_sql_sequence_reset(style, model_list):
126 113
     "Returns a list of the SQL statements to reset sequences for the given models."
127 114
     # No sequence reset required
1  django/db/backends/dummy/base.py
@@ -44,7 +44,6 @@ def close(self):
44 44
 dictfetchmany = complain
45 45
 dictfetchall = complain
46 46
 get_start_transaction_sql = complain
47  
-get_sql_flush = complain
48 47
 get_sql_sequence_reset = complain
49 48
 
50 49
 OPERATOR_MAPPING = {}
53  django/db/backends/mysql/base.py
@@ -87,6 +87,29 @@ def limit_offset_sql(self, limit, offset=None):
87 87
     def random_function_sql(self):
88 88
         return 'RAND()'
89 89
 
  90
+    def sql_flush(self, style, tables, sequences):
  91
+        # NB: The generated SQL below is specific to MySQL
  92
+        # 'TRUNCATE x;', 'TRUNCATE y;', 'TRUNCATE z;'... style SQL statements
  93
+        # to clear all tables of all data
  94
+        if tables:
  95
+            sql = ['SET FOREIGN_KEY_CHECKS = 0;']
  96
+            for table in tables:
  97
+                sql.append('%s %s;' % (style.SQL_KEYWORD('TRUNCATE'), style.SQL_FIELD(quote_name(table))))
  98
+            sql.append('SET FOREIGN_KEY_CHECKS = 1;')
  99
+
  100
+            # 'ALTER TABLE table AUTO_INCREMENT = 1;'... style SQL statements
  101
+            # to reset sequence indices
  102
+            sql.extend(["%s %s %s %s %s;" % \
  103
+                (style.SQL_KEYWORD('ALTER'),
  104
+                 style.SQL_KEYWORD('TABLE'),
  105
+                 style.SQL_TABLE(quote_name(sequence['table'])),
  106
+                 style.SQL_KEYWORD('AUTO_INCREMENT'),
  107
+                 style.SQL_FIELD('= 1'),
  108
+                ) for sequence in sequences])
  109
+            return sql
  110
+        else:
  111
+            return []
  112
+
90 113
 class DatabaseWrapper(BaseDatabaseWrapper):
91 114
     ops = DatabaseOperations()
92 115
 
@@ -168,36 +191,6 @@ def quote_name(name):
168 191
 def get_start_transaction_sql():
169 192
     return "BEGIN;"
170 193
 
171  
-def get_sql_flush(style, tables, sequences):
172  
-    """Return a list of SQL statements required to remove all data from
173  
-    all tables in the database (without actually removing the tables
174  
-    themselves) and put the database in an empty 'initial' state
175  
-
176  
-    """
177  
-    # NB: The generated SQL below is specific to MySQL
178  
-    # 'TRUNCATE x;', 'TRUNCATE y;', 'TRUNCATE z;'... style SQL statements
179  
-    # to clear all tables of all data
180  
-    if tables:
181  
-        sql = ['SET FOREIGN_KEY_CHECKS = 0;'] + \
182  
-              ['%s %s;' % \
183  
-                (style.SQL_KEYWORD('TRUNCATE'),
184  
-                 style.SQL_FIELD(quote_name(table))
185  
-                )  for table in tables] + \
186  
-              ['SET FOREIGN_KEY_CHECKS = 1;']
187  
-
188  
-        # 'ALTER TABLE table AUTO_INCREMENT = 1;'... style SQL statements
189  
-        # to reset sequence indices
190  
-        sql.extend(["%s %s %s %s %s;" % \
191  
-            (style.SQL_KEYWORD('ALTER'),
192  
-             style.SQL_KEYWORD('TABLE'),
193  
-             style.SQL_TABLE(quote_name(sequence['table'])),
194  
-             style.SQL_KEYWORD('AUTO_INCREMENT'),
195  
-             style.SQL_FIELD('= 1'),
196  
-            ) for sequence in sequences])
197  
-        return sql
198  
-    else:
199  
-        return []
200  
-
201 194
 def get_sql_sequence_reset(style, model_list):
202 195
     "Returns a list of the SQL statements to reset sequences for the given models."
203 196
     # No sequence reset required
53  django/db/backends/mysql_old/base.py
@@ -97,6 +97,29 @@ def limit_offset_sql(self, limit, offset=None):
97 97
     def random_function_sql(self):
98 98
         return 'RAND()'
99 99
 
  100
+    def sql_flush(self, style, tables, sequences):
  101
+        # NB: The generated SQL below is specific to MySQL
  102
+        # 'TRUNCATE x;', 'TRUNCATE y;', 'TRUNCATE z;'... style SQL statements
  103
+        # to clear all tables of all data
  104
+        if tables:
  105
+            sql = ['SET FOREIGN_KEY_CHECKS = 0;']
  106
+            for table in tables:
  107
+                sql.append('%s %s;' % (style.SQL_KEYWORD('TRUNCATE'), style.SQL_FIELD(quote_name(table))))
  108
+            sql.append('SET FOREIGN_KEY_CHECKS = 1;')
  109
+
  110
+            # 'ALTER TABLE table AUTO_INCREMENT = 1;'... style SQL statements
  111
+            # to reset sequence indices
  112
+            sql.extend(["%s %s %s %s %s;" % \
  113
+                (style.SQL_KEYWORD('ALTER'),
  114
+                 style.SQL_KEYWORD('TABLE'),
  115
+                 style.SQL_TABLE(quote_name(sequence['table'])),
  116
+                 style.SQL_KEYWORD('AUTO_INCREMENT'),
  117
+                 style.SQL_FIELD('= 1'),
  118
+                ) for sequence in sequences])
  119
+            return sql
  120
+        else:
  121
+            return []
  122
+
100 123
 class DatabaseWrapper(BaseDatabaseWrapper):
101 124
     ops = DatabaseOperations()
102 125
 
@@ -187,36 +210,6 @@ def quote_name(name):
187 210
 def get_start_transaction_sql():
188 211
     return "BEGIN;"
189 212
 
190  
-def get_sql_flush(style, tables, sequences):
191  
-    """Return a list of SQL statements required to remove all data from
192  
-    all tables in the database (without actually removing the tables
193  
-    themselves) and put the database in an empty 'initial' state
194  
-
195  
-    """
196  
-    # NB: The generated SQL below is specific to MySQL
197  
-    # 'TRUNCATE x;', 'TRUNCATE y;', 'TRUNCATE z;'... style SQL statements
198  
-    # to clear all tables of all data
199  
-    if tables:
200  
-        sql = ['SET FOREIGN_KEY_CHECKS = 0;'] + \
201  
-              ['%s %s;' % \
202  
-                (style.SQL_KEYWORD('TRUNCATE'),
203  
-                 style.SQL_FIELD(quote_name(table))
204  
-                )  for table in tables] + \
205  
-              ['SET FOREIGN_KEY_CHECKS = 1;']
206  
-
207  
-        # 'ALTER TABLE table AUTO_INCREMENT = 1;'... style SQL statements
208  
-        # to reset sequence indices
209  
-        sql.extend(["%s %s %s %s %s;" % \
210  
-            (style.SQL_KEYWORD('ALTER'),
211  
-             style.SQL_KEYWORD('TABLE'),
212  
-             style.SQL_TABLE(quote_name(sequence['table'])),
213  
-             style.SQL_KEYWORD('AUTO_INCREMENT'),
214  
-             style.SQL_FIELD('= 1'),
215  
-            ) for sequence in sequences])
216  
-        return sql
217  
-    else:
218  
-        return []
219  
-
220 213
 def get_sql_sequence_reset(style, model_list):
221 214
     "Returns a list of the SQL statements to reset sequences for the given models."
222 215
     # No sequence reset required
49  django/db/backends/oracle/base.py
@@ -73,6 +73,28 @@ def max_name_length(self):
73 73
     def random_function_sql(self):
74 74
         return "DBMS_RANDOM.RANDOM"
75 75
 
  76
+    def sql_flush(self, style, tables, sequences):
  77
+        # Return a list of 'TRUNCATE x;', 'TRUNCATE y;',
  78
+        # 'TRUNCATE z;'... style SQL statements
  79
+        if tables:
  80
+            # Oracle does support TRUNCATE, but it seems to get us into
  81
+            # FK referential trouble, whereas DELETE FROM table works.
  82
+            sql = ['%s %s %s;' % \
  83
+                    (style.SQL_KEYWORD('DELETE'),
  84
+                     style.SQL_KEYWORD('FROM'),
  85
+                     style.SQL_FIELD(quote_name(table))
  86
+                     ) for table in tables]
  87
+            # Since we've just deleted all the rows, running our sequence
  88
+            # ALTER code will reset the sequence to 0.
  89
+            for sequence_info in sequences:
  90
+                table_name = sequence_info['table']
  91
+                seq_name = get_sequence_name(table_name)
  92
+                query = _get_sequence_reset_sql() % {'sequence':seq_name, 'table':quote_name(table_name)}
  93
+                sql.append(query)
  94
+            return sql
  95
+        else:
  96
+            return []
  97
+
76 98
 class DatabaseWrapper(BaseDatabaseWrapper):
77 99
     ops = DatabaseOperations()
78 100
 
@@ -218,33 +240,6 @@ def _get_sequence_reset_sql():
218 240
         END;
219 241
         /"""
220 242
 
221  
-def get_sql_flush(style, tables, sequences):
222  
-    """Return a list of SQL statements required to remove all data from
223  
-    all tables in the database (without actually removing the tables
224  
-    themselves) and put the database in an empty 'initial' state
225  
-    """
226  
-    # Return a list of 'TRUNCATE x;', 'TRUNCATE y;',
227  
-    # 'TRUNCATE z;'... style SQL statements
228  
-    if tables:
229  
-        # Oracle does support TRUNCATE, but it seems to get us into
230  
-        # FK referential trouble, whereas DELETE FROM table works.
231  
-        sql = ['%s %s %s;' % \
232  
-                (style.SQL_KEYWORD('DELETE'),
233  
-                 style.SQL_KEYWORD('FROM'),
234  
-                 style.SQL_FIELD(quote_name(table))
235  
-                 ) for table in tables]
236  
-        # Since we've just deleted all the rows, running our sequence
237  
-        # ALTER code will reset the sequence to 0.
238  
-        for sequence_info in sequences:
239  
-            table_name = sequence_info['table']
240  
-            seq_name = get_sequence_name(table_name)
241  
-            query = _get_sequence_reset_sql() % {'sequence':seq_name,
242  
-                                                 'table':quote_name(table_name)}
243  
-            sql.append(query)
244  
-        return sql
245  
-    else:
246  
-        return []
247  
-
248 243
 def get_sequence_name(table):
249 244
     name_length = DatabaseOperations().max_name_length() - 3
250 245
     return '%s_SQ' % util.truncate_name(table, name_length).upper()
107  django/db/backends/postgresql/base.py
@@ -73,6 +73,57 @@ def last_insert_id(self, cursor, table_name, pk_name):
73 73
         cursor.execute("SELECT CURRVAL('\"%s_%s_seq\"')" % (table_name, pk_name))
74 74
         return cursor.fetchone()[0]
75 75
 
  76
+    def sql_flush(self, style, tables, sequences):
  77
+        if tables:
  78
+            if postgres_version[0] >= 8 and postgres_version[1] >= 1:
  79
+                # Postgres 8.1+ can do 'TRUNCATE x, y, z...;'. In fact, it *has to*
  80
+                # in order to be able to truncate tables referenced by a foreign
  81
+                # key in any other table. The result is a single SQL TRUNCATE
  82
+                # statement.
  83
+                sql = ['%s %s;' % \
  84
+                    (style.SQL_KEYWORD('TRUNCATE'),
  85
+                     style.SQL_FIELD(', '.join([quote_name(table) for table in tables]))
  86
+                )]
  87
+            else:
  88
+                # Older versions of Postgres can't do TRUNCATE in a single call, so
  89
+                # they must use a simple delete.
  90
+                sql = ['%s %s %s;' % \
  91
+                        (style.SQL_KEYWORD('DELETE'),
  92
+                         style.SQL_KEYWORD('FROM'),
  93
+                         style.SQL_FIELD(quote_name(table))
  94
+                         ) for table in tables]
  95
+
  96
+            # 'ALTER SEQUENCE sequence_name RESTART WITH 1;'... style SQL statements
  97
+            # to reset sequence indices
  98
+            for sequence_info in sequences:
  99
+                table_name = sequence_info['table']
  100
+                column_name = sequence_info['column']
  101
+                if column_name and len(column_name)>0:
  102
+                    # sequence name in this case will be <table>_<column>_seq
  103
+                    sql.append("%s %s %s %s %s %s;" % \
  104
+                        (style.SQL_KEYWORD('ALTER'),
  105
+                        style.SQL_KEYWORD('SEQUENCE'),
  106
+                        style.SQL_FIELD(quote_name('%s_%s_seq' % (table_name, column_name))),
  107
+                        style.SQL_KEYWORD('RESTART'),
  108
+                        style.SQL_KEYWORD('WITH'),
  109
+                        style.SQL_FIELD('1')
  110
+                        )
  111
+                    )
  112
+                else:
  113
+                    # sequence name in this case will be <table>_id_seq
  114
+                    sql.append("%s %s %s %s %s %s;" % \
  115
+                        (style.SQL_KEYWORD('ALTER'),
  116
+                         style.SQL_KEYWORD('SEQUENCE'),
  117
+                         style.SQL_FIELD(quote_name('%s_id_seq' % table_name)),
  118
+                         style.SQL_KEYWORD('RESTART'),
  119
+                         style.SQL_KEYWORD('WITH'),
  120
+                         style.SQL_FIELD('1')
  121
+                         )
  122
+                    )
  123
+            return sql
  124
+        else:
  125
+            return []
  126
+
76 127
 class DatabaseWrapper(BaseDatabaseWrapper):
77 128
     ops = DatabaseOperations()
78 129
 
@@ -134,62 +185,6 @@ def dictfetchall(cursor):
134 185
 def get_start_transaction_sql():
135 186
     return "BEGIN;"
136 187
 
137  
-def get_sql_flush(style, tables, sequences):
138  
-    """Return a list of SQL statements required to remove all data from
139  
-    all tables in the database (without actually removing the tables
140  
-    themselves) and put the database in an empty 'initial' state
141  
-
142  
-    """
143  
-    if tables:
144  
-        if postgres_version[0] >= 8 and postgres_version[1] >= 1:
145  
-            # Postgres 8.1+ can do 'TRUNCATE x, y, z...;'. In fact, it *has to*
146  
-            # in order to be able to truncate tables referenced by a foreign
147  
-            # key in any other table. The result is a single SQL TRUNCATE
148  
-            # statement.
149  
-            sql = ['%s %s;' % \
150  
-                (style.SQL_KEYWORD('TRUNCATE'),
151  
-                 style.SQL_FIELD(', '.join([quote_name(table) for table in tables]))
152  
-            )]
153  
-        else:
154  
-            # Older versions of Postgres can't do TRUNCATE in a single call, so
155  
-            # they must use a simple delete.
156  
-            sql = ['%s %s %s;' % \
157  
-                    (style.SQL_KEYWORD('DELETE'),
158  
-                     style.SQL_KEYWORD('FROM'),
159  
-                     style.SQL_FIELD(quote_name(table))
160  
-                     ) for table in tables]
161  
-
162  
-        # 'ALTER SEQUENCE sequence_name RESTART WITH 1;'... style SQL statements
163  
-        # to reset sequence indices
164  
-        for sequence_info in sequences:
165  
-            table_name = sequence_info['table']
166  
-            column_name = sequence_info['column']
167  
-            if column_name and len(column_name)>0:
168  
-                # sequence name in this case will be <table>_<column>_seq
169  
-                sql.append("%s %s %s %s %s %s;" % \
170  
-                    (style.SQL_KEYWORD('ALTER'),
171  
-                    style.SQL_KEYWORD('SEQUENCE'),
172  
-                    style.SQL_FIELD(quote_name('%s_%s_seq' % (table_name, column_name))),
173  
-                    style.SQL_KEYWORD('RESTART'),
174  
-                    style.SQL_KEYWORD('WITH'),
175  
-                    style.SQL_FIELD('1')
176  
-                    )
177  
-                )
178  
-            else:
179  
-                # sequence name in this case will be <table>_id_seq
180  
-                sql.append("%s %s %s %s %s %s;" % \
181  
-                    (style.SQL_KEYWORD('ALTER'),
182  
-                     style.SQL_KEYWORD('SEQUENCE'),
183  
-                     style.SQL_FIELD(quote_name('%s_id_seq' % table_name)),
184  
-                     style.SQL_KEYWORD('RESTART'),
185  
-                     style.SQL_KEYWORD('WITH'),
186  
-                     style.SQL_FIELD('1')
187  
-                     )
188  
-                )
189  
-        return sql
190  
-    else:
191  
-        return []
192  
-
193 188
 def get_sql_sequence_reset(style, model_list):
194 189
     "Returns a list of the SQL statements to reset sequences for the given models."
195 190
     from django.db import models
103  django/db/backends/postgresql_psycopg2/base.py
@@ -35,6 +35,57 @@ def last_insert_id(self, cursor, table_name, pk_name):
35 35
         cursor.execute("SELECT CURRVAL('\"%s_%s_seq\"')" % (table_name, pk_name))
36 36
         return cursor.fetchone()[0]
37 37
 
  38
+    def sql_flush(self, style, tables, sequences):
  39
+        if tables:
  40
+            if postgres_version[0] >= 8 and postgres_version[1] >= 1:
  41
+                # Postgres 8.1+ can do 'TRUNCATE x, y, z...;'. In fact, it *has to*
  42
+                # in order to be able to truncate tables referenced by a foreign
  43
+                # key in any other table. The result is a single SQL TRUNCATE
  44
+                # statement.
  45
+                sql = ['%s %s;' % \
  46
+                    (style.SQL_KEYWORD('TRUNCATE'),
  47
+                     style.SQL_FIELD(', '.join([quote_name(table) for table in tables]))
  48
+                )]
  49
+            else:
  50
+                # Older versions of Postgres can't do TRUNCATE in a single call, so
  51
+                # they must use a simple delete.
  52
+                sql = ['%s %s %s;' % \
  53
+                        (style.SQL_KEYWORD('DELETE'),
  54
+                         style.SQL_KEYWORD('FROM'),
  55
+                         style.SQL_FIELD(quote_name(table))
  56
+                         ) for table in tables]
  57
+
  58
+            # 'ALTER SEQUENCE sequence_name RESTART WITH 1;'... style SQL statements
  59
+            # to reset sequence indices
  60
+            for sequence_info in sequences:
  61
+                table_name = sequence_info['table']
  62
+                column_name = sequence_info['column']
  63
+                if column_name and len(column_name)>0:
  64
+                    # sequence name in this case will be <table>_<column>_seq
  65
+                    sql.append("%s %s %s %s %s %s;" % \
  66
+                        (style.SQL_KEYWORD('ALTER'),
  67
+                        style.SQL_KEYWORD('SEQUENCE'),
  68
+                        style.SQL_FIELD(quote_name('%s_%s_seq' % (table_name, column_name))),
  69
+                        style.SQL_KEYWORD('RESTART'),
  70
+                        style.SQL_KEYWORD('WITH'),
  71
+                        style.SQL_FIELD('1')
  72
+                        )
  73
+                    )
  74
+                else:
  75
+                    # sequence name in this case will be <table>_id_seq
  76
+                    sql.append("%s %s %s %s %s %s;" % \
  77
+                        (style.SQL_KEYWORD('ALTER'),
  78
+                         style.SQL_KEYWORD('SEQUENCE'),
  79
+                         style.SQL_FIELD(quote_name('%s_id_seq' % table_name)),
  80
+                         style.SQL_KEYWORD('RESTART'),
  81
+                         style.SQL_KEYWORD('WITH'),
  82
+                         style.SQL_FIELD('1')
  83
+                         )
  84
+                    )
  85
+            return sql
  86
+        else:
  87
+            return []
  88
+
38 89
 class DatabaseWrapper(BaseDatabaseWrapper):
39 90
     ops = DatabaseOperations()
40 91
 
@@ -88,58 +139,6 @@ def quote_name(name):
88 139
 def get_start_transaction_sql():
89 140
     return "BEGIN;"
90 141
 
91  
-def get_sql_flush(style, tables, sequences):
92  
-    """Return a list of SQL statements required to remove all data from
93  
-    all tables in the database (without actually removing the tables
94  
-    themselves) and put the database in an empty 'initial' state
95  
-    """
96  
-    if tables:
97  
-        if postgres_version[0] >= 8 and postgres_version[1] >= 1:
98  
-            # Postgres 8.1+ can do 'TRUNCATE x, y, z...;'. In fact, it *has to* in order to be able to
99  
-            # truncate tables referenced by a foreign key in any other table. The result is a
100  
-            # single SQL TRUNCATE statement
101  
-            sql = ['%s %s;' % \
102  
-                    (style.SQL_KEYWORD('TRUNCATE'),
103  
-                     style.SQL_FIELD(', '.join([quote_name(table) for table in tables]))
104  
-                    )]
105  
-        else:
106  
-            sql = ['%s %s %s;' % \
107  
-                    (style.SQL_KEYWORD('DELETE'),
108  
-                     style.SQL_KEYWORD('FROM'),
109  
-                     style.SQL_FIELD(quote_name(table))
110  
-                     ) for table in tables]
111  
-
112  
-        # 'ALTER SEQUENCE sequence_name RESTART WITH 1;'... style SQL statements
113  
-        # to reset sequence indices
114  
-        for sequence in sequences:
115  
-            table_name = sequence['table']
116  
-            column_name = sequence['column']
117  
-            if column_name and len(column_name) > 0:
118  
-                # sequence name in this case will be <table>_<column>_seq
119  
-                sql.append("%s %s %s %s %s %s;" % \
120  
-                    (style.SQL_KEYWORD('ALTER'),
121  
-                     style.SQL_KEYWORD('SEQUENCE'),
122  
-                     style.SQL_FIELD(quote_name('%s_%s_seq' % (table_name, column_name))),
123  
-                     style.SQL_KEYWORD('RESTART'),
124  
-                     style.SQL_KEYWORD('WITH'),
125  
-                     style.SQL_FIELD('1')
126  
-                     )
127  
-                )
128  
-            else:
129  
-                # sequence name in this case will be <table>_id_seq
130  
-                sql.append("%s %s %s %s %s %s;" % \
131  
-                    (style.SQL_KEYWORD('ALTER'),
132  
-                     style.SQL_KEYWORD('SEQUENCE'),
133  
-                     style.SQL_FIELD(quote_name('%s_id_seq' % table_name)),
134  
-                     style.SQL_KEYWORD('RESTART'),
135  
-                     style.SQL_KEYWORD('WITH'),
136  
-                     style.SQL_FIELD('1')
137  
-                     )
138  
-                )
139  
-        return sql
140  
-    else:
141  
-        return []
142  
-
143 142
 def get_sql_sequence_reset(style, model_list):
144 143
     "Returns a list of the SQL statements to reset sequences for the given models."
145 144
     from django.db import models
31  django/db/backends/sqlite3/base.py
@@ -51,6 +51,19 @@ def drop_foreignkey_sql(self):
51 51
     def pk_default_value(self):
52 52
         return 'NULL'
53 53
 
  54
+    def sql_flush(self, style, tables, sequences):
  55
+        # NB: The generated SQL below is specific to SQLite
  56
+        # Note: The DELETE FROM... SQL generated below works for SQLite databases
  57
+        # because constraints don't exist
  58
+        sql = ['%s %s %s;' % \
  59
+                (style.SQL_KEYWORD('DELETE'),
  60
+                 style.SQL_KEYWORD('FROM'),
  61
+                 style.SQL_FIELD(quote_name(table))
  62
+                 ) for table in tables]
  63
+        # Note: No requirement for reset of auto-incremented indices (cf. other
  64
+        # sql_flush() implementations). Just return SQL at this point
  65
+        return sql
  66
+
54 67
 class DatabaseWrapper(BaseDatabaseWrapper):
55 68
     ops = DatabaseOperations()
56 69
 
@@ -121,24 +134,6 @@ def _sqlite_extract(lookup_type, dt):
121 134
 def get_start_transaction_sql():
122 135
     return "BEGIN;"
123 136
 
124  
-def get_sql_flush(style, tables, sequences):
125  
-    """
126  
-    Return a list of SQL statements required to remove all data from
127  
-    all tables in the database (without actually removing the tables
128  
-    themselves) and put the database in an empty 'initial' state
129  
-    """
130  
-    # NB: The generated SQL below is specific to SQLite
131  
-    # Note: The DELETE FROM... SQL generated below works for SQLite databases
132  
-    # because constraints don't exist
133  
-    sql = ['%s %s %s;' % \
134  
-            (style.SQL_KEYWORD('DELETE'),
135  
-             style.SQL_KEYWORD('FROM'),
136  
-             style.SQL_FIELD(quote_name(table))
137  
-             ) for table in tables]
138  
-    # Note: No requirement for reset of auto-incremented indices (cf. other
139  
-    # get_sql_flush() implementations). Just return SQL at this point
140  
-    return sql
141  
-
142 137
 def get_sql_sequence_reset(style, model_list):
143 138
     "Returns a list of the SQL statements to reset sequences for the given models."
144 139
     # No sequence reset required

0 notes on commit aaed6e0

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