Re: a multi-thread issue concerning execute()

Ed Pasma <[email protected]>
Newsgroups gmane.comp.python.db.pysqlite.user
Message-ID <[email protected]>
Christian Boos wrote:

> 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
Hello Christian / Bruce, any table has a rowid column, it don't need  
to be the primary key. I mean:

cur.execute ("select id from testtable where rowid=?", (cur.lastrowid))

Regards, Edzard
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.