Re: a multi-thread issue concerning execute()
Ed Pasma <[email protected]>
| Newsgroups | gmane.comp.python.db.pysqlite.user |
|---|---|
| Message-ID | <[email protected]> |
Yes, unlike Oracle this rowid never changes, it may also be set on insert. And, like Christian wrote, if you define an integer primary key column, it is an alias for the rowid, so you can even give it a meaningful name. Bruce Who wrote: > Hi, > > does it mean that this rowid can be used as a primary key so that we > need not set a id column for tables? e.g., every row is associated > with a rowid which will never be changed? > > On 10/18/06, Ed Pasma <[email protected]> wrote: >> >> 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