Re: a multi-thread issue concerning execute()
"Bruce Who" <[email protected]>
| Newsgroups | gmane.comp.python.db.pysqlite.user |
|---|---|
| Message-ID | <[email protected]> |
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 > _______________________________________________ > pysqlite mailing list > pysqlite-IAPFreCvJWPBWskQ1e/[email protected] > http://lists.initd.org/mailman/listinfo/pysqlite >