#NEWLINE# def __change_db_version( self , version , migration_file_name , sql_up , sql_down , up = True , execution_log = None , label_version = None ) : #NEWLINE# #INDENT# if up : #NEWLINE# #INDENT# if ( not label_version ) : #NEWLINE# #INDENT# label_version = 'NULL' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# label_version = ( '"%s"' % str ( label_version ) ) #NEWLINE# #UNINDENT# sql = ( 'insert into %s (version, label, name, sql_up, sql_down) values ("%s", %s, "%s", "%s", "%s");' % ( self . __version_table , str ( version ) , label_version , migration_file_name , sql_up . replace ( '"' , '\\"' ) , sql_down . replace ( '"' , '\\"' ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# sql = ( 'delete from %s where version = "%s";' % ( self . __version_table , str ( version ) ) ) #NEWLINE# #UNINDENT# db = self . __mysql_connect ( ) #NEWLINE# cursor = db . cursor ( ) #NEWLINE# cursor . _defer_warnings = True #NEWLINE# try : #NEWLINE# #INDENT# cursor . execute ( sql . encode ( self . __mysql_script_encoding ) ) #NEWLINE# cursor . close ( ) #NEWLINE# db . commit ( ) #NEWLINE# if execution_log : #NEWLINE# #INDENT# execution_log ( ( 'migration %s registered\n' % migration_file_name ) ) #NEWLINE# #UNINDENT# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# db . rollback ( ) #NEWLINE# raise MigrationException ( ( 'error logging migration: %s' % e ) , sql_up ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# db . close ( )