Re: [cx-oracle-users] cursor.rowcount ? not implemented as API specified?
Brought to you by:
atuining
From: Anthony T. <ant...@gm...> - 2015-10-29 01:04:16
|
On Wed, Oct 28, 2015 at 6:35 PM, <ejo...@ea...> 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 |