Re: Problem With Insert with MySQLdb

Discussion in 'Python' started by =?ISO-8859-1?Q?Gerhard_H=E4ring?=, Oct 31, 2005.

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

    iD8DBQFDZWBndIO4ozGCH14RAuuKAJ9MiUn39dfd0FMclnYBFkXufN/wzwCdG7s4
    6Bxj6HdyBbAz7u5O5tu0m7E=
    =FXrV
    -----END PGP SIGNATURE-----
    =?ISO-8859-1?Q?Gerhard_H=E4ring?=, Oct 31, 2005
    #1
    1. Advertising

  2. 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 : -Augsburg.DE
    Sibylle Koczian, Oct 31, 2005
    #2
    1. Advertising

  3. On Mon, 31 Oct 2005 11:27:12 +0100, Sibylle Koczian
    <-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...
    --
    > ============================================================== <
    > | Wulfraed Dennis Lee Bieber KD6MOG <
    > | Bestiaria Support Staff <
    > ============================================================== <
    > Home Page: <http://www.dm.net/~wulfraed/> <
    > Overflow Page: <http://wlfraed.home.netcom.com/> <
    Dennis Lee Bieber, Oct 31, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Mitchell

    Problem With Insert with MySQLdb

    David Mitchell, Oct 30, 2005, in forum: Python
    Replies:
    3
    Views:
    407
    Magnus Lycka
    Nov 1, 2005
  2. Sells, Fred

    MySQLdb insert fails on one table

    Sells, Fred, Jun 1, 2007, in forum: Python
    Replies:
    0
    Views:
    272
    Sells, Fred
    Jun 1, 2007
  3. Sells, Fred

    RE: MySQLdb insert fails on one table

    Sells, Fred, Jun 1, 2007, in forum: Python
    Replies:
    0
    Views:
    384
    Sells, Fred
    Jun 1, 2007
  4. Replies:
    1
    Views:
    1,777
    Albert Hopkins
    Dec 6, 2008
  5. Anatoli Hristov

    MySQLdb insert HTML code error

    Anatoli Hristov, Dec 11, 2012, in forum: Python
    Replies:
    0
    Views:
    135
    Anatoli Hristov
    Dec 11, 2012
Loading...

Share This Page