pysql lite transactions question

Stormbringer andreif at mail.dntis.ro
Sun Dec 21 10:52:37 CET 2003


Hi,

Could anyone shed some light on transactions using pysqlite when
autocommit is off ?

I am using Python 2.3 with latest pysqlite and after I do a
       m_connection = sqlite.connect(name, autocommit=0)
and
       m_cursor = self.m_connection.cursor()

and then looks like it starts a transaction automaticaly, because if I
issue a
       m_cursor.execute('BEGIN TRANSACTION')
it says that nested transactions are not permitted.

But : if I issue an 'END TRANSACTION' and then a 'BEGIN TRANSACTION'
and do the usual db operations and in the end I do a 'END TRANSACTION'
I get this :

Exception _sqlite.DatabaseError: 'cannot rollback - no transaction is
active' in <bound method Connection.__del__ of <sqlite.main.Connection
instance at 0x0086D288>> ignored

The program works as expected, i.e. seems like this exception is
ignored, but I must do something wrong or not properly as this
exception appear.

I also tried to send a 'COMMIT' after my 'BEGIN TRANSACTION' and I get
      _sqlite.DatabaseError: cannot commit - no transaction is active
which does strike me as odd.

My reasons of trying to use transactions is that it seems to make
sense in what I do, i.e. I try to populate a database and if I get an
error halfway I want to cancel the whole chain of operations. Plus I
noticed the speed is much greater if I put autocommit to off.

Any ideas ?

Thanks in Advance,
Andrei




More information about the Python-list mailing list