|
Re: Getting the time during a transaction: msg#00016python.db.pysqlite.user
Hi Gerhard. Ah well, that completely explains this. Many thanks, it did not assume an issue with rowcount so used it as I had previously. On another note, do you have any favorite way of faking a sequence in SQLite. I am using sequence in postgres to keep track of the commit_order of transactions. ie create sequence commit_seq; I am already autoincrementing my transaction id in SQLite by doing create table ztransaction ( tid integer primary key, packed boolean not null default false, commit_order integer not null unique, ..more fields ); My commit_seq in postgres is used to give me the next value for my commit_order field for my table. So I'd normally be doing this: insert into ztransaction (tid, commit_order, username, description, extension) values (%s, (select nextval('commit_seq')), %s, %s, %s) My thought is to use something like single field table and alter the value of it. I guess I could also make a pysqlite function that would just return the next value of the current value. I may just have to be explicit about putting it in begin and end to do both statements in a single transaction to be sure the value doesn't change perhaps. In any case, any ideas here would also be a help. Regards, David Regards, David Gerhard Häring wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > David Pratt wrote: >> Hi Tim. It was a surprise to me as well! The thing that screwed me up >> was assert cursor.rowcount. Hmm, it should be 1 since I am getting a >> result from .fetchone but is reporting -1. I incorrectly assumed I was >> getting nothing from my select statement. Any idea about this? Why is it >> not giving me a rowcount of 1 so my assertion is correct? [...] > > The pysqlite docs say why: > http://initd.org/pub/software/pysqlite/doc/usage-guide.html > > """ > rowcount attribute > > Although pysqlite's Cursors implement this attribute, the database engine's > own support for the determination of "rows affected"/"rows selected" is quirky. > > For SELECT statements, rowcount is always -1 because pysqlite cannot > determine the number of rows a query produced until all rows were fetched. > > For DELETE statements, SQLite reports rowcount as 0 if you make a DELETE > FROM table without any condition. > > For executemany statements, pysqlite sums up the number of modifications > into rowcount. > > As required by the Python DB API Spec, the rowcount attribute "is -1 in > case no executeXX() has been performed on the cursor or the rowcount of the > last operation is not determinable by the interface". > """ > > - -- Gerhard > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.1 (GNU/Linux) > Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org > > iD8DBQFEVn7VdIO4ozGCH14RAv51AJ4o11JEDa3O+tC1bTcPs0VU/JkiFACgkbZn > yr9GIOFkluoX3daVjTC9/pM= > =2JLw > -----END PGP SIGNATURE----- > |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Emulating a sequence: 00016, Tim Golden |
|---|---|
| Next by Date: | Re: Emulating a sequence: 00016, David Pratt |
| Previous by Thread: | Re: Getting the time during a transactioni: 00016, Tim Golden |
| Next by Thread: | Emulating a sequence: 00016, David Pratt |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | Mail Home | sitemap | FAQ | advertise |