Menu

make transactions with Mysqldb

gregouze
2007-09-07
2012-09-19
  • gregouze

    gregouze - 2007-09-07

    Hello everybody,

    I'm trying to use transactions through MySQLDB
    Could someone show me how to?

    An example of my script:

    !/usr/bin/env python

    import MySQLdb,blabla....

    connectionObject = MySQLdb.connect(blabla....)
    c = connectionObject.cursor();

    c.execute("""drop table image""");

    connectionObject.rollback();
    connectionObject.close();

    and the image table is dropped, even if i use the rollback method...

    Perhaps it does this because my table is not TYPE=InnoDB and transaction works only with InnoDB engine.
    i specify this type bu creating my image table like this

    CREATE TABLE image (
    blabla.....
    blabla.....
    blabla.....
    blabla.....
    )TYPE=InnoDB;

    Is it the right thing to do to make InnoDB table?

    Please Help me!

     
    • Kyle VanderBeek

      Kyle VanderBeek - 2007-10-13

      barton_c: Autocommit is off by default in MySQLdb (as mandated by PEP 249).

      gregastrophysic: Don't expect data definition statements (like ALTER or DROP) to be transactional. They just don't make much sense in a transactional context (since transactions are generally about rows and data, not meta-data). That said, you answer is here:

      http://dev.mysql.com/doc/refman/5.0/en/drop-table.html

      DROP TABLE commits the current active transaction unless you're dealing with temporary tables.

       
    • Barton Cline

      Barton Cline - 2007-09-08

      c.execute("""set autocommit = 0""") before anything else.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.