From: Peter W. <pw-...@te...> - 2003-04-23 04:49:56
|
On Tuesday, April 22, 2003, at 01:16 PM, Ian Bicking wrote: > I might have missed something, though. Is there any unresolved issues > that should be dealt with before 0.4? > I've been doing some more work with SQLite and come up with the following that might be useful to have. class SQLiteConnection(DBAPI): def __init__(self, dsn, autoCommit=1, **kw): assert sqlite, 'sqlite module cannot be found' self.dsn = dsn # full path to sqlite-db-file if not autoCommit and not kw.has_key('pool'): # Pooling doesn't work with transactions... kw['pool'] = 0 # use only one connection for sqlite - supports multiple cursors per connection self._conn = sqlite.connect(self.dsn) DBAPI.__init__(self, **kw) def makeConnection(self): return self._conn The autoCommit=1 and the pooling conditional is just copied directly from PostgresConnection, SQLite supports transactions so I presume that for the same reasons this is needed. I changed how it deals with getting a connection so that code like the following will work without needing to turn the results into lists, really any code where you have database access inside loops like this not just deletes. users = User.select('all') for i in users: for ul in u.userLocations: ul.destroySelf() SQLite + Python only supports one connection at a time. In my understanding the select loop should be able to run in a different connection to the delete as SQLite only locks when changing the db. I'm trying to find out exactly where the oddness is happening. Can you see any problems with doing this? -- peter w. |