Combine raw SQL with model.save() in one transaction?

48 views
Skip to first unread message

Constantin Christmann

unread,
Apr 2, 2008, 9:01:57 AM4/2/08
to django...@googlegroups.com
Is it possible to combine raw SQL statements with Django's convenient
model.save() in one transaction?

I use MySQL/InnoDB and need to place some raw SQL inside a transaction
block:

cursor = connection.cursor()
cursor.execute("""
START TRANSACTION;
UPDATE ...
""")
...
model.save()
...
cursor.execute("COMMIT;")

As you can see I have some other database manipulations (saving a
model/form) that should be part of this transaction too.
I use the TransactionMiddleware to get the transactions tyed to the HTTP
request but I don't know how to integrate that with the raw SQL.
Or is this just not possible and I have to write raw SQL for all code
belonging to the transaction above.

Regards,
Constantin

Reply all
Reply to author
Forward
0 new messages