I have stored the entry to be inserted into db as dictionary with dictionary keys same as field names. is there any simple command to directly do this?
currently this is the command I use
cursor.execute('INSERT INTO jobs (title, description, country, state, city)
VALUES (%(title)s, %(description)s, %(country)s, %(state)s, %(city)s)', (job_data.get_parsed_dictionary()))
Many times python has so many elegant library methods for all sorts of things. I am hoping there one such command which make it much simpler.
You could generate the column names:
You do need to make sure that the keys in the
.get_parsed_dictionary()result are safe to interpolate into a SQL query (remember your SQL injection attack vectors). If you have a list of possible column names handy, I’d certainly check against that to filter out any stray ‘extra’ keys you may find in thatdict.