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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.