[Tutor] unable to insert data into database

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Sat Feb 18 21:00:38 CET 2006


> I'm Tiago, from Brazil, I'm new to this list and, err, I'm getting into
> python.

Hi Tiago,

Welcome aboard!


> I'm very interested on the mysql module, and this thread sounds
> interesting.  I've tried pretty much the same code from the original
> code, and I don't need to commit changes. All I have is a
> cursor.close(), and it works ok. So, I think it have a sort of
> auto-commit.

Yes, older versions of MySQLdb had autocommit behavior, because MySQL at
some distant, medieval epoch did not support transactions.  MySQL finally
does with InnoDB tables, and so the MySQLdb module was changed to support
that transaction feature.


> But I was wondering if it's the same behavior for all database engines,
> as I've read somewhere on the mysql reference that Innodb tables need a
> commit command. And it could even be an explanation to the different
> behavior observed by Servando: if you create different sorts of tables
> on windows, mac and linux, you'll have different behaviors...

Yes, it's probably that problem.  Either his tables are MyISAM in some
places and not in others, or he has an old version of MySQLdb installed in
one place and not in another.  There are at least two possible ways of
seeing what he's getting.

Although his Python program is the same, the environment around his
program is different, and so he has to account for these free-floating
conditions.  He should be using conn.commit()  for the code to really
work, according to the Python DB API.


> I hope you'll understand my poor english...

Don't worry!  You write excellent English.



More information about the Tutor mailing list