Re: [pysqlite] [APSW] "SQLError: cannot rollback - no transaction is active"

Roger Binns <[email protected]> Fri, 28 Nov 2008 21:30:15 -0800
Newsgroups gmane.comp.python.db.pysqlite.user
Message-ID <[email protected]>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Fred wrote:
> So I can just remove the ROLLBACK line,

You can delete the "try" and remove the whole "except" section.  Python
exits on unhandled exceptions anyway, and the automatic cleanups will
end up doing the rollback anyway.  Basically your except block does what
Python does anyway, but does it way worse (swallows exceptions, causes
it own etc).

> I 
> just want to make sure the database is left in a clean state before 
> ending the script.

The database is always clean.  That is the point of an ACID compliant
database.  You can even pull the power out at any point.

> Right, but 1) this script is for personal use, not running on some 
> web site, 

You will generally find that useful scripts and programs expand beyond
what you originally envisioned.  IIRC you were getting your data from
the web (Amazon) which means that you have no control over the data.

> 2) the problem with the "?" construct is that I can't 
> display the actual SQL statement on the screen to check what it looks like.

That makes no sense whatsoever!  You are certainly worse at SQL parsing
than the computer.  If you use bindings you can be absolutely sure of
what is going in.  I also fail to see why they can't be printed.  If the
execute looks like this:

  sql="... some sql ..."
  bindings=[1,"two"]
  cursor.execute(sql, bindings)

Then this works:

  print sql, bindings

Additionally if you are using APSW you can just install execution and
row tracers on the cursor.

http://apsw.googlecode.com/svn/publish/example.html#example-exectrace
http://apsw.googlecode.com/svn/publish/cursor.html#apsw.Cursor.setexectrace

The next APSW release will even let you automatically trace without
having to change your code.

Roger
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkkw02IACgkQmOOfHg372QSrpwCgrHgSz/Ms91z/dxSRyri+qMWu
NZQAoKAimBTzNWjvd0t45EmYKJ9yfxxw
=lx0M
-----END PGP SIGNATURE-----