pysqlite multiple connections
Tertius Cronje
tcronj at yahoo.co.uk
Wed May 7 18:24:48 EDT 2003
Gerhard, thank you so much.
This gives me a few more options to consider.
The application I want to use it for will probably not be used by more
than 10 users. I'll have to build some extra logic into the code to
enable single use of a cursor. I was looking for some simple code
examples but without any luck.
One example that caught my attention is the round-up project but I have
not yet managed decipher the code.
Regards
Tertius
>
> Anyway, here's something that might work better for you:
>
> #v+
> import sqlite
>
> cnct1 = sqlite.connect(db="/tmp/db", autocommit=True)
> cnct1.db.sqlite_busy_timeout(5000)
> crsr1 = cnct1.cursor()
> print "cnct1:", cnct1
> print "crsr1:", crsr1
>
> cnct2 = sqlite.connect(db="/tmp/db", autocommit=True)
> cnct1.db.sqlite_busy_timeout(5000)
> crsr2 = cnct2.cursor()
> print "cnct2:", cnct2
> print "crsr2:", crsr2
> #v-
>
> This will
>
> a) open the connection in autocommit mode. You don't have any
> transactions, then. This might be ok for simple use cases, but for many
> real-life db apps, transactions are a must.
>
> b) If two connections try to hold the lock at the same time (with
> autocommit=True, this can really only happen in a
> multi-process/multi-thread environment), the SQLite engine immediately
> throws an error by default. You can change this behaviour, though. The
> low-level call sqlite_busy_timeout sets the interval how long SQLite
> will try to grab the lock before giving up.
>
> We've received a patch today for adding the timeout as an optional
> parameter to the module-level connect function. This patch makes sense
> to me and I'll apply it to CVS soon.
>
> -- Gerhard
>
More information about the Python-list
mailing list