MySQL Forums
Forum List  »  Connector/Python

Problem with Python/MySQL
Posted by: Eoin Healy
Date: September 16, 2009 06:53AM

I have a table with 4 columns using an auto incrementing primary key and 3 strings.

The below code is what I'm using in python to add a row.

cursor = conn.cursor()
cursor.execute('INSERT INTO details (subject, due, description) VALUES("%s", "%s", "%s")' % (subject, due, description))
cursor.close
conn.close

This appears to run fine in Python, no errors come up but when I check if its been entered into the table, it does not appear. However, If I manually go an add an entry, the auto increment has skipped a value for every time I ran the program?
+----+-----------+--------+----------------------------+
| id | subject   | due    | description                |
+----+-----------+--------+----------------------------+
|  1 | C00000    | 000000 | abc                        |
|  2 | c11111    | 111111 | abc                        |
|  7 | c11111    | 111111 | abc                        |
| 10 | c11111    | 111111 | abc                        |
+----+-----------+--------+----------------------------+
4 rows in set (0.00 sec)
Adding a print statement for the same code that is executed and then copying it directly into the mysql command line works correctly. Example of printout below.

INSERT INTO details (subject, due, description) VALUES("ABCDEFG", "211111", Do something")

Using Python 2.6.2 and Server version: 5.1.37-community MySQL Community Server (GPL)

Options: ReplyQuote


Subject
Written By
Posted
Problem with Python/MySQL
September 16, 2009 06:53AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.