python - substitute array values for mysql insert statement -
i trying execute insert statement mysql list of array values..but didn't work..
my "array" list has required values
insert_statement = "insert db (hostname,serial_number,cpu,memory,eth0_ip,eth1_ip,hardware_type,datacenter,operating_system) values ('%s','%s','%s','%s','%s','%s','%s','%s','%s') % (array[0], array[1], array[2], array[3], array[4], array[5], array[6], array[7], array[8])" cur.execute(insert_statement)
i tried
insert_statement = "insert db (hostname,serial_number,cpu,memory,eth0_ip,eth1_ip,hardware_type,datacenter,operating_system) values ('%s','%s','%s','%s','%s','%s','%s','%s','%s') , array" cur.executemany(insert_statement)
both erroring out "sql statement errors".
with mysqldb should work (if array consists of 9 elements):
insert_statement = "insert db (hostname,serial_number,cpu,memory,eth0_ip,eth1_ip,hardware_type,datacenter,operating_system) values (%s,%s,%s,%s,%s,%s,%s,%s,%s)" cur.execute(insert_statement, array)
Comments
Post a Comment