#NEWLINE# def as_sql( self , compiler , connection , template = None , case_joiner = None , **extra_context ) : #NEWLINE# #INDENT# connection . ops . check_expression_support ( self ) #NEWLINE# if ( not self . cases ) : #NEWLINE# #INDENT# return compiler . compile ( self . default ) #NEWLINE# #UNINDENT# template_params = self . extra . copy ( ) #NEWLINE# template_params . update ( extra_context ) #NEWLINE# case_parts = [ ] #NEWLINE# sql_params = [ ] #NEWLINE# for case in self . cases : #NEWLINE# #INDENT# ( case_sql , case_params ) = compiler . compile ( case ) #NEWLINE# case_parts . append ( case_sql ) #NEWLINE# sql_params . extend ( case_params ) #NEWLINE# #UNINDENT# case_joiner = ( case_joiner or self . case_joiner ) #NEWLINE# template_params [ 'cases' ] = case_joiner . join ( case_parts ) #NEWLINE# ( default_sql , default_params ) = compiler . compile ( self . default ) #NEWLINE# template_params [ 'default' ] = default_sql #NEWLINE# sql_params . extend ( default_params ) #NEWLINE# template = ( template or template_params . get ( 'template' , self . template ) ) #NEWLINE# sql = ( template % template_params ) #NEWLINE# if ( self . _output_field_or_none is not None ) : #NEWLINE# #INDENT# sql = ( connection . ops . unification_cast_sql ( self . output_field ) % sql ) #NEWLINE# #UNINDENT# return ( sql , sql_params )