Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Problem With Insert with MySQLdb

Reply
Thread Tools

Re: Problem With Insert with MySQLdb

 
 
=?ISO-8859-1?Q?Gerhard_H=E4ring?=
Guest
Posts: n/a
 
      10-31-2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

David Mitchell wrote:
> Hello,
>
> 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
> MySQL database.
>
> 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.

HTH,

- -- Gerhard
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDZWBndIO4ozGCH14RAuuKAJ9MiUn39dfd0FMclnYBFk XufN/wzwCdG7s4
6Bxj6HdyBbAz7u5O5tu0m7E=
=FXrV
-----END PGP SIGNATURE-----
 
Reply With Quote
 
 
 
 
Sibylle Koczian
Guest
Posts: n/a
 
      10-31-2005
Gerhard Häring schrieb:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> David Mitchell wrote:
>
>>Hello,
>>
>>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
>>MySQL database.
>>
>>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.
D-86135 Augsburg
e-mail : http://www.velocityreviews.com/forums/(E-Mail Removed)-Augsburg.DE
 
Reply With Quote
 
 
 
 
Dennis Lee Bieber
Guest
Posts: n/a
 
      10-31-2005
On Mon, 31 Oct 2005 11:27:12 +0100, Sibylle Koczian
<(E-Mail Removed)-Augsburg.de> declaimed the following in
comp.lang.python:

>
> 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.


The more recent installers set the config file to default of
InnoDB...
--
> ================================================== ============ <
> http://www.velocityreviews.com/forums/(E-Mail Removed) | Wulfraed Dennis Lee Bieber KD6MOG <
> (E-Mail Removed) | Bestiaria Support Staff <
> ================================================== ============ <
> Home Page: <http://www.dm.net/~wulfraed/> <
> Overflow Page: <http://wlfraed.home.netcom.com/> <

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQLdb insert HTML code error Anatoli Hristov Python 0 12-11-2012 12:04 AM
Insert Multiple Records Using One Insert Statemen with MySQLdb module anton.ranieri.it@gmail.com Python 1 12-06-2008 12:47 PM
RE: MySQLdb insert fails on one table Sells, Fred Python 0 06-01-2007 05:16 PM
MySQLdb insert fails on one table Sells, Fred Python 0 06-01-2007 03:48 PM
Problem With Insert with MySQLdb David Mitchell Python 3 11-01-2005 10:33 AM



Advertisments