Problem With Insert with MySQLdb
Sibylle.Koczian at Bibliothek.Uni-Augsburg.de
Mon Oct 31 11:27:12 CET 2005
Gerhard Häring schrieb:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> David Mitchell wrote:
>>I am a complete beginner with Python. I've managed to get mod_python up and
>>running with Apache2 and I'm trying to a simple insert into a table in a
>>I'm using the MySQLdb library for connectivity. I can read from the database
>>no problem, but when I do an insert, the value never gets added to the
>>database, even though there is no error, and the SQL is fine (I print out
>>the SQL statement in the function). When I copy and paste the sql from my
>>browser and insert directly into MySQL, it works fine.
>>[...] Am I doing something obviously incorrect here?
> It appears you forgot to call .commit() on the connection to commit your
> transaction. From what you tell, it also looks like the MySQL
> commandline tool defaults to autocommit (i. e. each statement is wrapped
> in an implicit BEGIN ... COMMIT.
> If you have no idea what a transaction is or what the heck the BEGIN,
> COMMIT or ROLLBACK commands are for (corresponding to .commit() and
> .rollback() methods of the DB-API2 connection object, BEGIN is issued
> implicitly), then the MySQL documentation will probably answer that.
What sort of table do you use? MyISAM isn't transaction oriented, and
that's the standard. So that most probably isn't the problem.
Dr. Sibylle Koczian
Universitaetsbibliothek, Abt. Naturwiss.
e-mail : Sibylle.Koczian at Bibliothek.Uni-Augsburg.DE
More information about the Python-list