mysql - Trouble passing in variable for column name in mySQLDB for python -


i using python's mysqldb pass in variables update set statement. of variables being passed in work except 1 updating field put variables in. have no idea why happening. appreciate if explain me , give me possible solution. below type out code talking about. commented out line works (although updates single field) , uncommented line trying utilize go through every field

for y in range(1,col_count):     field = 'field' + str(y)     print field     #cur.execute("update sqldatabase set field1= %s file_name = %s ,                    #slides_name = %s;",(temp_list[y],filename,temp_list[0]))     cur.execute("update sqldatabase set %s= %s file_name = %s ,       slides_name = %s;",(field,temp_list[y],filename,temp_list[0])) 

parameter placeholders can used insert column names, not table names etc. (see the docs). perhaps try this:

cmd = 'update sqldatabase set ' + field + ' = %s file_name'\       ' = %s , slides_name = %s;' cur.execute(cmd, (temp_list[y],filename,temp_list[0])) 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -