<s> """<STR_LIT>""" <EOL> from django . core . exceptions import FieldError <EOL> from django . db import connections <EOL> from django . db . models . sql . constants import * <EOL> from django . db . models . sql . datastructures import Date <EOL> from django . db . models . sql . expressions import SQLEvaluator <EOL> from django . db . models . sql . query import Query <EOL> from django . db . models . sql . where import AND , Constraint <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> class DeleteQuery ( Query ) : <EOL> """<STR_LIT>""" <EOL> compiler = '<STR_LIT>' <EOL> def do_query ( self , table , where , using ) : <EOL> self . tables = [ table ] <EOL> self . where = where <EOL> self . get_compiler ( using ) . execute_sql ( None ) <EOL> def delete_batch ( self , pk_list , using ) : <EOL> """<STR_LIT>""" <EOL> for offset in range ( <NUM_LIT:0> , len ( pk_list ) , GET_ITERATOR_CHUNK_SIZE ) : <EOL> where = self . where_class ( ) <EOL> field = self . model . _meta . pk <EOL> where . add ( ( Constraint ( None , field . column , field ) , '<STR_LIT>' , <EOL> pk_list [ offset : offset + GET_ITERATOR_CHUNK_SIZE ] ) , AND ) <EOL> self . do_query ( self . model . _meta . db_table , where , using = using ) <EOL> class UpdateQuery ( Query ) : <EOL> """<STR_LIT>""" <EOL> compiler = '<STR_LIT>' <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( UpdateQuery , self ) . __init__ ( * args , ** kwargs ) <EOL> self . _setup_query ( ) <EOL> def _setup_query ( self ) : <EOL> """<STR_LIT>""" <EOL> self . values = [ ] <EOL> self . related_ids = None <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> self . related_updates = { } <EOL> def clone ( self , klass = None , ** kwargs ) : <EOL> return super ( UpdateQuery , self ) . clone ( klass , <EOL> related_updates = self . related_updates . copy ( ) , ** kwargs ) <EOL> def clear_related ( self , related_field , pk_list , using ) : <EOL> """<STR_LIT>""" <EOL> for offset in range ( <NUM_LIT:0> , len ( pk_list ) , GET_ITERATOR_CHUNK_SIZE ) : <EOL> self . where = self . where_class ( ) <EOL> f = self . model . _meta . pk <EOL> self . where . add ( ( Constraint ( None , f . column , f ) , '<STR_LIT>' , <EOL> pk_list [ offset : offset + GET_ITERATOR_CHUNK_SIZE ] ) , <EOL> AND ) <EOL> self . values = [ ( related_field , None , None ) ] <EOL> self . get_compiler ( using ) . execute_sql ( None ) <EOL> def add_update_values ( self , values ) : <EOL> """<STR_LIT>""" <EOL> values_seq = [ ] <EOL> for name , val in values . iteritems ( ) : <EOL> field , model , direct , m2m = self . model . _meta . get_field_by_name ( name ) <EOL> if not direct or m2m : <EOL> raise FieldError ( '<STR_LIT>' % field ) <EOL> if model : <EOL> self . add_related_update ( model , field , val ) <EOL> continue <EOL> values_seq . append ( ( field , model , val ) ) <EOL> return self . add_update_fields ( values_seq ) <EOL> def add_update_fields ( self , values_seq ) : <EOL> """<STR_LIT>""" <EOL> self . values . extend ( values_seq ) <EOL> def add_related_update ( self , model , field , value ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . related_updates [ model ] . append ( ( field , None , value ) ) <EOL> except KeyError : <EOL> self . related_updates [ model ] = [ ( field , None , value ) ] <EOL> def get_related_updates ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . related_updates : <EOL> return [ ] <EOL> result = [ ] <EOL> for model , values in self . related_updates . iteritems ( ) : <EOL> query = UpdateQuery ( model ) <EOL> query . values = values <EOL> if self . related_ids is not None : <EOL> query . add_filter ( ( '<STR_LIT>' , self . related_ids ) ) <EOL> result . append ( query ) <EOL> return result <EOL> class InsertQuery ( Query ) : <EOL> compiler = '<STR_LIT>' <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( InsertQuery , self ) . __init__ ( * args , ** kwargs ) <EOL> self . columns = [ ] <EOL> self . values = [ ] <EOL> self . params = ( ) <EOL> def clone ( self , klass = None , ** kwargs ) : <EOL> extras = { <EOL> '<STR_LIT>' : self . columns [ : ] , <EOL> '<STR_LIT>' : self . values [ : ] , <EOL> '<STR_LIT>' : self . params <EOL> } <EOL> extras . update ( kwargs ) <EOL> return super ( InsertQuery , self ) . clone ( klass , ** extras ) <EOL> def insert_values ( self , insert_values , raw_values = False ) : <EOL> """<STR_LIT>""" <EOL> placeholders , values = [ ] , [ ] <EOL> for field , val in insert_values : <EOL> placeholders . append ( ( field , val ) ) <EOL> self . columns . append ( field . column ) <EOL> values . append ( val ) <EOL> if raw_values : <EOL> self . values . extend ( [ ( None , v ) for v in values ] ) <EOL> else : <EOL> self . params += tuple ( values ) <EOL> self . values . extend ( placeholders ) <EOL> class DateQuery ( Query ) : <EOL> """<STR_LIT>""" <EOL> compiler = '<STR_LIT>' <EOL> def add_date_select ( self , field , lookup_type , order = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> result = self . setup_joins ( [ field . name ] , self . get_meta ( ) , <EOL> self . get_initial_alias ( ) , False ) <EOL> alias = result [ <NUM_LIT:3> ] [ - <NUM_LIT:1> ] <EOL> select = Date ( ( alias , field . column ) , lookup_type ) <EOL> self . select = [ select ] <EOL> self . select_fields = [ None ] <EOL> self . select_related = False <EOL> self . set_extra_mask ( [ ] ) <EOL> self . distinct = True <EOL> self . order_by = order == '<STR_LIT>' and [ <NUM_LIT:1> ] or [ - <NUM_LIT:1> ] <EOL> class AggregateQuery ( Query ) : <EOL> """<STR_LIT>""" <EOL> compiler = '<STR_LIT>' <EOL> def add_subquery ( self , query , using ) : <EOL> self . subquery , self . sub_params = query . get_compiler ( using ) . as_sql ( with_col_aliases = True ) </s>
