I want to insert a row in a table of a database from a python script. The column fiels values are saved in variables of different formats: strings, integers, and floats. I search in forums, I tried differente options but no one is working
I tried this options:
cursor.execute('INSERT INTO table(device, number1, number2) VALUES (%s,%d,%f)',(device_var,number1_var, number2_var))
I also tried:
cursor.execute('INSERT INTO table(device, number1, number2) VALUES ({0},{1},{2})',(device_var,number1_var, number2_var))
And
cursor.execute('INSERT INTO table(device, number1, number2) VALUES ({0},{1},{2})'.format (device_var,number1_var, number2_var))
ERROR:OperationalError: (1054, "Unknown column 'device_var_content' in 'field list'")
I aslo tried this to see if there is a problem in the table but this works OK:
cursor.execute('INSERT INTO table(device, number1, number2) VALUES ("dev1",1,2.4)'
Thanks for your time
SOLVED:
cursor.execute('INSERT INTO table(device, number1, number2) VALUES ("{}",{},{})'.format (string_var,number1_var, number2_var))
Thanks for your help, your answers give me the way where keep looking.