#NEWLINE# def _collect_update_commands( base_mapper , uowtransaction , table , states_to_update ) : #NEWLINE# #INDENT# 'Identify sets of values to use in UPDATE statements for a\n    list of states.\n\n    This function works intricately with the history system\n    to determine exactly what values should be updated\n    as well as how the row should be matched within an UPDATE\n    statement.  Includes some tricky scenarios where the primary\n    key of an object might have been changed.\n\n    ' #NEWLINE# update = [ ] #NEWLINE# for ( state , state_dict , mapper , connection , has_identity , instance_key , row_switch ) in states_to_update : #NEWLINE# #INDENT# if ( table not in mapper . _pks_by_table ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# pks = mapper . _pks_by_table [ table ] #NEWLINE# params = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# value_params = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# hasdata = hasnull = False #NEWLINE# for col in mapper . _cols_by_table [ table ] : #NEWLINE# #INDENT# if ( col is mapper . version_id_col ) : #NEWLINE# #INDENT# params [ col . _label ] = mapper . _get_committed_state_attr_by_column ( ( row_switch or state ) , ( ( row_switch and row_switch . dict ) or state_dict ) , col ) #NEWLINE# prop = mapper . _columntoproperty [ mapper ] #NEWLINE# history = state . manager [ prop . key ] . impl . get_history ( state , state_dict , attributes . PASSIVE_NO_INITIALIZE ) #NEWLINE# if history . added : #NEWLINE# #INDENT# params [ col . key ] = history . added [ 0 ] #NEWLINE# hasdata = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( mapper . version_id_generator is not False ) : #NEWLINE# #INDENT# val = mapper . version_id_generator ( params [ col . _label ] ) #NEWLINE# params [ col . key ] = val #NEWLINE# for prop in mapper . _columntoproperty . values ( ) : #NEWLINE# #INDENT# history = state . manager [ prop . key ] . impl . get_history ( state , state_dict , attributes . PASSIVE_NO_INITIALIZE ) #NEWLINE# if history . added : #NEWLINE# #INDENT# hasdata = True #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# prop = mapper . _columntoproperty [ col ] #NEWLINE# history = state . manager [ prop . key ] . impl . get_history ( state , state_dict , attributes . PASSIVE_NO_INITIALIZE ) #NEWLINE# if history . added : #NEWLINE# #INDENT# if isinstance ( history . added [ 0 ] , sql . ClauseElement ) : #NEWLINE# #INDENT# value_params [ col ] = history . added [ 0 ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# value = history . added [ 0 ] #NEWLINE# params [ col . key ] = value #NEWLINE# #UNINDENT# if ( col in pks ) : #NEWLINE# #INDENT# if ( history . deleted and ( not row_switch ) ) : #NEWLINE# #INDENT# if ( ( 'pk_cascaded' , state , col ) in uowtransaction . attributes ) : #NEWLINE# #INDENT# value = history . added [ 0 ] #NEWLINE# params [ col . _label ] = value #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# value = history . deleted [ 0 ] #NEWLINE# params [ col . _label ] = value #NEWLINE# #UNINDENT# hasdata = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# del params [ col . key ] #NEWLINE# value = history . added [ 0 ] #NEWLINE# params [ col . _label ] = value #NEWLINE# #UNINDENT# if ( value is None ) : #NEWLINE# #INDENT# hasnull = True #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# hasdata = True #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( col in pks ) : #NEWLINE# #INDENT# value = state . manager [ prop . key ] . impl . get ( state , state_dict ) #NEWLINE# if ( value is None ) : #NEWLINE# #INDENT# hasnull = True #NEWLINE# #UNINDENT# params [ col . _label ] = value #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( row_switch and ( history . unchanged == [ None ] ) ) : #NEWLINE# #INDENT# params [ col . key ] = None #NEWLINE# hasdata = True #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if hasdata : #NEWLINE# #INDENT# if hasnull : #NEWLINE# #INDENT# raise orm_exc . FlushError ( "Can't update table using NULL for primary key value" ) #NEWLINE# #UNINDENT# update . append ( ( state , state_dict , params , mapper , connection , value_params ) ) #NEWLINE# #UNINDENT# #UNINDENT# return update