Adam Hayward wrote:
> Hello there.
>
> (first post to group)
>
> I've been having a problem with an incorrect rowcount for ResultProxies
> using Sqlite databases. Regardless of how many rows in the resultset, it
> gives me a rowcount of "-1". Best demonstrated with an example:
>
> Is this a bug? Am I doing something wrong?

the general purpose of cursor.rowcount in DBAPI is to return the number of
rows affected by an INSERT, UPDATE, or DELETE statement.  While the DBAPI
spec apparently unfortunately states it can also apply to the number of
rows from a SELECT statement, this is usually not the case in reality.  
In particular it usually requires the DBAPI to fully fetch all rows
unconditionally, a generally undesirable behavior that a lot of DBAPIs
still do by default (though newer DBAPIs are doing this less).

In practice, a SELECT statement could represent millions of rows.   If the
RDBMS has not applied any GROUP BY or ORDER BY criterion to the rows, it
doesn't even know how many rows it will find before it starts returning
them.

To get the total number of rows from a SELECT in a platform agnostic way,
either execute a "select count(*)" with your criterion, or just fetch the
whole result.   Its not feasable for SQLAlchemy to force all results into
a buffer just so this attribute could be available since its extremely
inefficient.


-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to