Suner Evren
Suner Evren

Reputation: 63

Python and MySQL Insert query

I have a question regarding insert query and python mysql connection. I guess that I need to commit after every insert query made

Is there a different way to do that? I mean a fast way like one in php.

Second this also is same for update query I guess ?

Another problem here is that once you commit your query connection is closed, assume that I have a different insert queries and every time i prepare it I need to insert it to the table. How can I achieve that with python. I am using MySQLdb Library

Thanks for your answers.

Upvotes: 0

Views: 145

Answers (1)

Robert Christie
Robert Christie

Reputation: 20705

You don't need to commit after each insert. You can perform many operations and commit on completion.

The executemany method of the DBAPI allows you to perform many inserts/updates in a single roundtrip

There is no link between committing a transaction and disconnecting from the database. See the Connection objects methods for the details of the commit and close methods

Upvotes: 2

Related Questions