In the following code, I intended that nothing will be inserted into
the table because the transaction fails and is rolled back. What
actually happens is that the first insert is not rolled back because
it s committed by itself.
What is the correct way to achieve my goal?
TIA

from sqlalchemy import *
db=create_engine('mysql://<user>:<pw>@localhost/<db>')
cn= db.connect()
cn.execute("DROP TABLE IF EXISTS test")
cn.execute("CREATE TABLE test (`id` bigint(20) NOT NULL , PRIMARY KEY
(`id`))
 
ENGINE=InnoDB")
db.echo=True

md=BoundMetaData(db)
t=Table('test', md, autoload = True)

trans = cn.begin()
try:
    insert(t).execute(id=332)
    insert(t).execute(id=332)
    trans.commit()
except:
    trans.rollback()
    raise


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to