"but how should one do it instead?"
Tough call. The issue is that they are plugging in metadata (specifically column names) on the fly into a SQL statement. I'm not a big fan of this kind of thing. The sourcedest
variable has two column names that are going to be updated.
Odds are good that there is only one (or a few few) pairs of column names that are actually used. My preference is to do this.
if situation1:
stmt= "INSERT INTO mastertickets (this, that) VALUES (?, ?)"
elif situation2:
stmt= "INSERT INTO mastertickets (foo, bar) VALUES (?, ?)"
else:
raise Exception( "Bad configuration -- with some explanation" )
cursor.execute( stmt, (self.tkt.id, n) )
When there's more than one valid combination of columns for this kind of thing, it indicates that the data model has merged two entities into a single table, which is a common database design problem. Since you're working with a product and a plug-in, there's not much you can do about the data model issues.