a multi-thread issue concerning execute()
"Bruce Who" <[email protected]>
| Newsgroups | gmane.comp.python.db.pysqlite.user |
|---|---|
| Message-ID | <[email protected]> |
Hi, all
In a multi-thread application, more than one threads access the same
sqlite database via individual connections. we have following code:
# in sone thread
cur=conn.cursor()
cur.execute("insert into testtable(id, name) select max(id)+1, ? from
testtable", (name,))
cur.execute("select max(id) from testtable")
# id of the record which has just been added
new_record_id = cur.fetchone()[0]
in other threads, they have the same code, so I wonder if
new_record_id is always right? If not, how to make it right? Should we
use a lock?
Bruce