Ticket #382: south-sqlite-quote-field-names-2.patch

File south-sqlite-quote-field-names-2.patch, 1.1 KB (added by Alexander Clausen <alex@…>, 4 years ago)
  • south/db/sqlite3.py

    diff -r c2f9a062d54f south/db/sqlite3.py
    a b  
    8585        # Make a list of all the fields to select 
    8686        cursor = self._get_connection().cursor() 
    8787        q_fields = [column_info[0] for column_info in self._get_connection().introspection.get_table_description(cursor, dst)] 
    88         # Make sure renames are done correctly 
     88        new_to_old = {} 
    8989        for old, new in field_renames.items(): 
    90             q_fields[q_fields.index(new)] = "%s AS %s" % (old, self.quote_name(new)) 
     90            new_to_old[new] = old 
     91        q_fields_new = [] 
     92        for field in q_fields: 
     93            if field in new_to_old: 
     94                # Make sure renames are done correctly 
     95                q_fields_new.append("%s AS %s" % (self.quote_name(new_to_old[field]), self.quote_name(field))) 
     96            else: 
     97                q_fields_new.append(self.quote_name(field)) 
     98        q_fields = q_fields_new 
    9199        # Copy over the data 
    92100        self.execute("INSERT INTO %s SELECT %s FROM %s;" % ( 
    93101            self.quote_name(dst),