#NEWLINE# def sql_flush( self , style , tables , sequences ) : #NEWLINE# #INDENT# '\n        Returns a list of SQL statements required to remove all data from\n        the given database tables (without actually removing the tables\n        themselves).\n\n        The `style` argument is a Style object as returned by either\n        color_style() or no_style() in django.core.management.color.\n        ' #NEWLINE# if tables : #NEWLINE# #INDENT# from django.db import connection #NEWLINE# cursor = connection . cursor ( ) #NEWLINE# seqs = [ ] #NEWLINE# for seq in sequences : #NEWLINE# #INDENT# cursor . execute ( ( 'SELECT COUNT(*) FROM %s' % self . quote_name ( seq [ 'table' ] ) ) ) #NEWLINE# rowcnt = cursor . fetchone ( ) [ 0 ] #NEWLINE# elem = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# if rowcnt : #NEWLINE# #INDENT# elem [ 'start_id' ] = 0 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# elem [ 'start_id' ] = 1 #NEWLINE# #UNINDENT# elem . update ( seq ) #NEWLINE# seqs . append ( elem ) #NEWLINE# #UNINDENT# cursor . execute ( "SELECT TABLE_NAME, CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_TYPE not in ('PRIMARY KEY','UNIQUE')" ) #NEWLINE# fks = cursor . fetchall ( ) #NEWLINE# sql_list = [ ( 'ALTER TABLE %s NOCHECK CONSTRAINT %s;' % ( self . quote_name ( fk [ 0 ] ) , self . quote_name ( fk [ 1 ] ) ) ) for fk in fks ] #NEWLINE# sql_list . extend ( [ ( '%s %s %s;' % ( style . SQL_KEYWORD ( 'DELETE' ) , style . SQL_KEYWORD ( 'FROM' ) , style . SQL_FIELD ( self . quote_name ( table ) ) ) ) for table in tables ] ) #NEWLINE# sql_list . extend ( [ ( '%s %s (%s, %s, %s) %s %s;' % ( style . SQL_KEYWORD ( 'DBCC' ) , style . SQL_KEYWORD ( 'CHECKIDENT' ) , style . SQL_FIELD ( self . quote_name ( seq [ 'table' ] ) ) , style . SQL_KEYWORD ( 'RESEED' ) , style . SQL_FIELD ( ( '%d' % seq [ 'start_id' ] ) ) , style . SQL_KEYWORD ( 'WITH' ) , style . SQL_KEYWORD ( 'NO_INFOMSGS' ) ) ) for seq in seqs ] ) #NEWLINE# sql_list . extend ( [ ( 'ALTER TABLE %s CHECK CONSTRAINT %s;' % ( self . quote_name ( fk [ 0 ] ) , self . quote_name ( fk [ 1 ] ) ) ) for fk in fks ] ) #NEWLINE# return sql_list #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return [ ]