|
From: Billy G. A. <Bil...@mu...> - 2002-04-11 16:27:46
|
Martin Dengler wrote:
> Hi Guys,
>
> i got a problem with cursor.rowcount. After a select-stmt is executed and
> there is definitly a result, cursor.rowcount always has the value -1 ? Is thi
> s
> not implemented yet ?
>
> my setup:
> WIN ME, postgre v.7.1.3, ActivePython v.2.1.212, PgSQL v. 1.4
>
> any ideas ?
By default, PgSQL uses PostgreSQL Portals (i.e. cursors). As a result of
this, PgSQL doesn't know how many rows resulted from the query until they
are fetched. (Note: rowcount will be set to the number of rows returned by
the fectchXXX() method. If you fecthone(), rowcount will be 1.)
There are a couple of ways to get the number of rows returned by a query:
1. Do a fetchall(). rowcount will then be set to the number of rows
retrieved.
2. Set PgSQL.noPostgresCursor to 1. This will prevent PgSQL from using
PostgreSQL Portals (which will result in the entire result set being
read into memory). Rowcount will be set to the number of rows
retrieved.
3. Execute a "select count(*) ..." to get the number of rows.
4. Re-evaluate why you need to know the number of rows before processing
the results.
___________________________________________________________________________
____ | Billy G. Allie | Domain....: Bil...@mu...
| /| | 7436 Hartwell | MSN.......: B_G...@em...
|-/-|----- | Dearborn, MI 48126|
|/ |LLIE | (313) 582-1540 |
|