logo       

Re: Getting the time during a transaction: msg#00014

python.db.pysqlite.user

Subject: Re: Getting the time during a transaction

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?


Another of those quirks, I'm afraid. If you haven't already,
read the usage guide of the pysqlite website:

http://initd.org/pub/software/pysqlite/doc/usage-guide.html

and in particular the section on extensions and caveats:

http://initd.org/pub/software/pysqlite/doc/usage-guide.html#extensions-and-caveats

Search the page for "rowcount attribute" and you find:

"""
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.
"""

which I think answers your question. BTW, it obviously depends
what your plan is, but I've been programming databases professionally
for over 15 years and I can't remember the last time I catually had
to use rowcount (or its equivalent). Could be a shortcoming on my part,
obviously, but I wonder whether there's some other way you might
achieve what you're trying to do.

TJG


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise