diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2007-08-20 00:15:53 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2007-08-20 00:15:53 +0000 |
| commit | aaed6e04eceef98e9ec433e86b80486ada2a668b (patch) | |
| tree | 1af09d368aa36673b6b1768a70ac10f8cb9f0fea /django/db/backends/mysql/base.py | |
| parent | c44fb66551bf2f628648440ebc2010ad1135d9ac (diff) | |
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
Diffstat (limited to 'django/db/backends/mysql/base.py')
| -rw-r--r-- | django/db/backends/mysql/base.py | 53 |
1 files changed, 23 insertions, 30 deletions
diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index 4b4d4eb44a..e09313c585 100644 --- a/django/db/backends/mysql/base.py +++ b/django/db/backends/mysql/base.py @@ -87,6 +87,29 @@ class DatabaseOperations(BaseDatabaseOperations): def random_function_sql(self): return 'RAND()' + def sql_flush(self, style, tables, sequences): + # NB: The generated SQL below is specific to MySQL + # 'TRUNCATE x;', 'TRUNCATE y;', 'TRUNCATE z;'... style SQL statements + # to clear all tables of all data + if tables: + sql = ['SET FOREIGN_KEY_CHECKS = 0;'] + for table in tables: + sql.append('%s %s;' % (style.SQL_KEYWORD('TRUNCATE'), style.SQL_FIELD(quote_name(table)))) + sql.append('SET FOREIGN_KEY_CHECKS = 1;') + + # 'ALTER TABLE table AUTO_INCREMENT = 1;'... style SQL statements + # to reset sequence indices + sql.extend(["%s %s %s %s %s;" % \ + (style.SQL_KEYWORD('ALTER'), + style.SQL_KEYWORD('TABLE'), + style.SQL_TABLE(quote_name(sequence['table'])), + style.SQL_KEYWORD('AUTO_INCREMENT'), + style.SQL_FIELD('= 1'), + ) for sequence in sequences]) + return sql + else: + return [] + class DatabaseWrapper(BaseDatabaseWrapper): ops = DatabaseOperations() @@ -168,36 +191,6 @@ dictfetchall = util.dictfetchall def get_start_transaction_sql(): return "BEGIN;" -def get_sql_flush(style, tables, sequences): - """Return a list of SQL statements required to remove all data from - all tables in the database (without actually removing the tables - themselves) and put the database in an empty 'initial' state - - """ - # NB: The generated SQL below is specific to MySQL - # 'TRUNCATE x;', 'TRUNCATE y;', 'TRUNCATE z;'... style SQL statements - # to clear all tables of all data - if tables: - sql = ['SET FOREIGN_KEY_CHECKS = 0;'] + \ - ['%s %s;' % \ - (style.SQL_KEYWORD('TRUNCATE'), - style.SQL_FIELD(quote_name(table)) - ) for table in tables] + \ - ['SET FOREIGN_KEY_CHECKS = 1;'] - - # 'ALTER TABLE table AUTO_INCREMENT = 1;'... style SQL statements - # to reset sequence indices - sql.extend(["%s %s %s %s %s;" % \ - (style.SQL_KEYWORD('ALTER'), - style.SQL_KEYWORD('TABLE'), - style.SQL_TABLE(quote_name(sequence['table'])), - style.SQL_KEYWORD('AUTO_INCREMENT'), - style.SQL_FIELD('= 1'), - ) for sequence in sequences]) - return sql - else: - return [] - def get_sql_sequence_reset(style, model_list): "Returns a list of the SQL statements to reset sequences for the given models." # No sequence reset required |
