I have code like this:
print "company_id = %d" % company_id
...
db.cursor.execute("insert into person (company_id, first, last, type) values (%d, '%s', '%s', %d);", (company_id, name[0], name[1], type))
I get the following output:
company_id = 1
Traceback (most recent call last):
...
File "./GetPeople.py", line 125, in insertPerson
db.cursor.execute("insert into person (company_id, first, last, type) values (%d, '%s', '%s', %d);",
Why can it print out the first line but it gives an error for the db.cursor.execute()
call?
The single quotes around the %s placeholders are incorrect and the %d isn't used as per the docs. Change
db.cursor.execute("insert into person (company_id, first, last, type) values (%d, '%s', '%s', %d);", (company_id, name[0], name[1], type))
to
db.cursor.execute("insert into person (company_id, first, last, type) values (%s, %s, %s, %s);", (company_id, name[0], name[1], type))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With