Check out the following lines of Python 2.6 code I found:
key = 'hire_date'
update_dict['key'] = update_dict[key] #added e.g. {..., 'key': '12/31/1999'}
if key == 'hire_date':
query_string = "UPDATE employee SET " + key + "= CAST(%(key)s AS DATE) WHERE emp_id = '" + emp.employee + "'"
I've tested this code, and it works. It successfully updates the employee's hire_date field in the database to whatever date 'key''s value in the dictionary is.
I was in the middle of parameterizing it when I noticed the %(key)s somehow manages to get the value of the dictionary at 'key'. How does it do that? I always thought you had to add % dictionaryOrTupleOrWhatever after the string for this to work.
execute(query_string, update_dict)