Re: modify cycles
"Eric S. Johansson" <[email protected]>
| Newsgroups | gmane.comp.python.db.pysqlite.user |
|---|---|
| Message-ID | <[email protected]> |
Martin Jenkins wrote:
> I suspect you are falling foul of pysqlite's habit of starting
> transactions for you. You can control this by setting a connection
> variable called isolation_level to None (it defaults to '') as the
> Python 2.5 session below shows.
yup. makes sense. I wonder why someone didn't make a method
implementing a transaction bounded method? haven't tested this yet but
it seems ok. feel free to use it if it helps anyone.
def transaction(connection, fcn, *args):
old_isolation = connection.isolation_level
connection.isolation_level=None
c=connection.cursor()
c.execute("begin")
fcn(c,*args)
c.execute("end")
c.close()
connection.commit()
connection.isolation_level = old_isolation
fcn takes the cursor as first arg and the rest follow from transaction's
arguments. I do hope cursor's aren't too expensive. if they are, I can
add a state return value preserving the last used cursor but at that
point, it should be an object. fyi, this seems to work w/psqlite2 from
ubuntu 6.06
--- eric
--
Speech-recognition in use. It makes mistakes, I correct some.