<s> from datetime import datetime <EOL> from django . db import connection as con <EOL> import sqlparse <EOL> def track_sql ( ) : <EOL> global start_time <EOL> global query_count <EOL> start_time = datetime . now ( ) <EOL> query_count = len ( con . queries ) <EOL> def print_sql ( show_queries = True ) : <EOL> print "<STR_LIT>" % ( datetime . now ( ) - start_time ) <EOL> print "<STR_LIT>" % sum ( [ float ( query [ '<STR_LIT:time>' ] ) for query in con . queries [ query_count : ] ] ) <EOL> print "<STR_LIT>" % ( len ( con . queries ) - query_count ) <EOL> if show_queries : <EOL> for query in con . queries [ query_count : ] : <EOL> print "<STR_LIT>" % query [ '<STR_LIT:time>' ] <EOL> print sqlparse . format ( query [ '<STR_LIT>' ] , reindent = True , keyword_case = '<STR_LIT>' ) <EOL> def pg_multicolumn_index ( model , column_names , cursor = None ) : <EOL> """<STR_LIT>""" <EOL> cursor = cursor or con . cursor ( ) <EOL> db_table = model . _meta . db_table <EOL> db_column_names = [ model . _meta . get_field ( column_name ) . column for column_name in column_names ] <EOL> db_index = "<STR_LIT>" % ( db_table , '<STR_LIT:_>' . join ( db_column_names ) ) <EOL> cursor . execute ( <EOL> "<STR_LIT>" + db_index + "<STR_LIT>" + <EOL> "<STR_LIT>" + db_table + "<STR_LIT>" % ( '<STR_LIT:U+002C>' . join ( db_column_names ) ) ) <EOL> cursor . execute ( "<STR_LIT>" ) <EOL> def pg_bulk_update ( model , filter_name , update_name , <EOL> filter_column_data , update_column_data , cursor = None ) : <EOL> """<STR_LIT>""" <EOL> cursor = cursor or con . cursor ( ) <EOL> db_table = model . _meta . db_table <EOL> model_filter = model . _meta . get_field ( filter_name ) . column <EOL> model_update = model . _meta . get_field ( update_name ) . column <EOL> if type ( filter_column_data ) is tuple : <EOL> filter_column_data = list ( filter_column_data ) <EOL> if type ( update_column_data ) is tuple : <EOL> update_column_data = list ( update_column_data ) <EOL> cursor . execute ( <EOL> "<STR_LIT>" + db_table + <EOL> "<STR_LIT>" + model_update + "<STR_LIT>" + <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" + model_filter + "<STR_LIT>" , [ filter_column_data , <EOL> update_column_data ] ) <EOL> cursor . execute ( "<STR_LIT>" ) </s>
