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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -