#NEWLINE# def as_sql( self ) : #NEWLINE# #INDENT# '\n        Creates the SQL for this query. Returns the SQL string and list of\n        parameters.\n        ' #NEWLINE# from django.db.models.base import Model #NEWLINE# self . pre_sql_setup ( ) #NEWLINE# if ( not self . query . values ) : #NEWLINE# #INDENT# return ( '' , ( ) ) #NEWLINE# #UNINDENT# table = self . query . tables [ 0 ] #NEWLINE# qn = self . quote_name_unless_alias #NEWLINE# result = [ ( 'UPDATE %s' % qn ( table ) ) ] #NEWLINE# result . append ( 'SET' ) #NEWLINE# ( values , update_params ) = ( [ ] , [ ] ) #NEWLINE# for ( field , model , val ) in self . query . values : #NEWLINE# #INDENT# if hasattr ( val , 'prepare_database_save' ) : #NEWLINE# #INDENT# val = val . prepare_database_save ( field ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# val = field . get_db_prep_save ( val , connection = self . connection ) #NEWLINE# #UNINDENT# if hasattr ( field , 'get_placeholder' ) : #NEWLINE# #INDENT# placeholder = field . get_placeholder ( val , self . connection ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# placeholder = '%s' #NEWLINE# #UNINDENT# if hasattr ( val , 'evaluate' ) : #NEWLINE# #INDENT# val = SQLEvaluator ( val , self . query , allow_joins = False ) #NEWLINE# #UNINDENT# name = field . column #NEWLINE# if hasattr ( val , 'as_sql' ) : #NEWLINE# #INDENT# ( sql , params ) = val . as_sql ( qn , self . connection ) #NEWLINE# values . append ( ( '%s = %s' % ( qn ( name ) , sql ) ) ) #NEWLINE# update_params . extend ( params ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( val is not None ) : #NEWLINE# #INDENT# values . append ( ( '%s = %s' % ( qn ( name ) , placeholder ) ) ) #NEWLINE# update_params . append ( val ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# values . append ( ( '%s = NULL' % qn ( name ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( not values ) : #NEWLINE# #INDENT# return ( '' , ( ) ) #NEWLINE# #UNINDENT# result . append ( ', ' . join ( values ) ) #NEWLINE# ( where , params ) = self . query . where . as_sql ( qn = qn , connection = self . connection ) #NEWLINE# if where : #NEWLINE# #INDENT# result . append ( ( 'WHERE %s' % where ) ) #NEWLINE# #UNINDENT# return ( ' ' . join ( result ) , tuple ( ( update_params + params ) ) )