MySQLdb: commit before cursor close, or after?
Frank Aune
Frank.Aune at broadpark.no
Mon Feb 4 13:53:44 EST 2008
On Monday 04 February 2008 19:14:13 John Nagle wrote:
> I'm getting some wierd commit-related behavior from MySQLdb. I'm
> using InnoDB, so transactions really matter.
>
> I'm currently doing
>
> cursor = db.cursor()
> cursor.execute(...)
> cursor.close()
> db.commit()
>
> Is that the correct order, or should I call "db.commit()" before
> "cursor.close()"? Does anyone know for sure? The MySQLdb documentation
> ("http://mysql-python.sourceforge.net/MySQLdb.html") doesn't
> say. There are some discussions of this in blogs, but nobody
> really seems to know.
>
> John Nagle
No, you obviously need to commit your changes before closing the cursor. I'm
surprised if your code above even works if adding content to the db.
Regards,
Frank
More information about the Python-list
mailing list