Re: cursor.rowcount ? not implemented as API specified?

Anthony Tuininga <[email protected]> Wed, 28 Oct 2015 19:04:09 -0600
Newsgroups gmane.comp.python.db.cx-oracle
Message-ID <CAE1XR-5z8vGDLNMgEhgqdD=8TmvGdWP-_-M+rtsF2Q2=c1XOVA@mail.gmail.com>
On Wed, Oct 28, 2015 at 6:35 PM, <[email protected]> wrote:

>
> Sorry, I guess my message earlier today was sort of duplicate - I've got a
> bit of lag here.
> I have gone back to the list subscription page and changed my option to
> not digest, but I still seem to be getting daily digests?
>
> Anyway, I am starting to use cx_Oracle...
>
> Am I not understanding something?  Documentation at
> https://www.python.org/dev/peps/pep-0249/#cursor-attributes says:
>
> .rowcount
> This read-only attribute specifies the number of rows that the last
> .execute*() produced (for DQL statements like SELECT ) or affected (for DML
> statements like UPDATE or INSERT ).
>
>
> I have a variable in the interpreter 'cur' as my cursor...
>
> >>> cur.execute('select * from isotope')
> <__builtin__.OracleCursor on <cx_Oracle.Connection to some_user@some_sid>>
> >>> cur.rowcount
> 0
> >>> recs = cur.fetchall()
> >>> recs[0]
> ('Co-55', 'Cobalt 55', None, None)
> >>> len(recs)
> 389
> >>> cur.rowcount
> 389
>
> I think I should have access to 389 as cur.rowcount prior to doing any
> fetching from the cursor.
> Is that not the right interpretation?
>

No. Queries do not calculate the total number of rows until *after* they
are all fetched. So if cx_Oracle was to do so, every query would result in
all of the rows being fetched into memory just so that the rowcount could
be set. That would be a poor use of memory! Instead, the value is updated
as rows are fetched. You can see that by doing the following:

cursor.execute(sql)
print(cursor.rowcount)
for row in cursor:
    print(cursor.rowcount)

Anthony

------------------------------------------------------------------------------

_______________________________________________
cx-oracle-users mailing list
cx-oracle-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/cx-oracle-users