472,122 Members | 1,576 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,122 software developers and data experts.

[pysqlite] pysqlite2.dbapi2.OperationalError: cannot commit transaction - SQL statements in progress

I've troubles to let my app take off using pysqlite.

What I wonder most for now is that "pysqlite2.dbapi2.OperationalError:
cannot commit transaction - SQL statements in progress" when I do this:

t = time.time()
n = len(self)
while len(self):
del self[0]
self.commit()
print "%d items deleted in %.3f secs. " % (n, time.time() - t)

self is of class DbTable which lets db tables be used like ordinary Python
objects (after an idea of Scott Scriven):

def __len__(self):
self._query_("select count(*) from %s %s" % (self._name,
self._whereClause))
r = int(self._dbc.fetchone()[0])
return r

and

def __delitem__(self, i):
'''Enables you to remove rows this way: del movies[58]
'''
q = "select %s from %s %s %s limit %s, 1" % (self._nameOfIdCol,
self._name, self._whereClause, self._orderClause, i)
self._query_(q)
rid = self._dbc.fetchone()[0]
q = "delete from %s where %s='%s'" % (self._name, self._nameOfIdCol,
rid)
self._query_(q)
return

So it boils down to SELECT and DELETE statements called in a loop. After
that a commit is made.

What does pysqlite try to tell me here?
Kind regards
Franz GEIGER
PS.: I use pysqlite 2.0.1 on Python 2.3.4
Jul 19 '05 #1
1 2701
On Wed, May 18, 2005 at 09:41:39PM +0200, F. GEIGER wrote:
I've troubles to let my app take off using pysqlite.

What I wonder most for now is that "pysqlite2.dbapi2.OperationalError:
cannot commit transaction - SQL statements in progress" when I do this:

Urgh! I would have preferred simplified demo code. But after a little
thinking, I guessed right.
[...]


pysqlite 2 currently has problems doing .commit() .rollback() on the
connection object after a cur.execute("select ...") in a few cases.

I know why and I will fix it in 2.0.2 (originally only MacOS X fixes
planned) or if it takes longer to test, in 2.0.3.

Current workarounds:

- don't commit/rollback after SELECT. It doesn't make much sense anyway.
.commit()/.rollback() after your DML statements instead
(INSERT/UPDATE/DELETE).

- Use fetchall()[0] for fetching single rows instead of fetchone() for
queries like your SELECT COUNT.

-- Gerhard
--
Gerhard Häring - gh@ghaering.de - Python, web & database development

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

iD8DBQFCjFjddIO4ozGCH14RAkqpAJ4m2Q3fh/Ta4pFm/v6mw45qBvJI/ACaA/2e
RHYiscfmDQTSWV6HZ+QSfZ4=
=HOgy
-----END PGP SIGNATURE-----

Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by bapolis | last post: by
6 posts views Thread by Rob Cowie | last post: by
1 post views Thread by Michael Husmann | last post: by
8 posts views Thread by rdrink | last post: by
14 posts views Thread by Nader Emami | last post: by
5 posts views Thread by =?ISO-8859-1?Q?Gerhard_H=E4ring?= | last post: by
4 posts views Thread by Astley Le Jasper | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.