Re: a multi-thread issue concerning execute()
Christian Boos <[email protected]>
| Newsgroups | gmane.comp.python.db.pysqlite.user |
|---|---|
| Message-ID | <[email protected]> |
Bruce Who wrote:
> 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")
>
If the 'id' column was defined as "integer PRIMARY KEY", you can at this
point call:
cur.lastrowid
Of course, the insert has to be adapted, and should simply be:
cur.execute("insert into testtable(name) values (?)", (name,))
-- Christian