cursor.rowcount always -1 in sqlite3 in python3k

From the documentation:

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

This includes SELECT statements
because we cannot determine the number
of rows a query produced until all
rows were fetched.

That means all SELECT statements won’t have a rowcount. The behaviour you’re observing is documented.

EDIT: Documentation doesn’t say anywhere that rowcount will be updated after you do a fetchall() so it is just wrong to assume that.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)