Re: cursor.rowcount not functioning as expected

<[email protected]> Tue, 3 Nov 2015 11:18:54 -0700 (GMT-07:00)
Newsgroups gmane.comp.python.db.cx-oracle
Message-ID <24061620.1446574735236.JavaMail.root@wamui-junio.atl.sa.earthlink.net>
Thanks for your reply, Amaury...

The README file distributed with cx_Oracle states:

cx_Oracle is a Python extension module that allows access to Oracle and

conforms to the Python database API 2.0 specifications with a number of

additions. The method cursor.nextset() and the time data type are not

supported by Oracle and are therefore not implemented.

Maybe there are sound efficiency reasons why cursor.rowcount doesn't give correct number

until you have fetched from the cursor - I don't know the nitty-gritty technical details

inside the cx_Oracle C code, but I can obviously count records after I've fetched them all.

At the very least, this should be documented as a deviation from the published

"Python database API 2.0".

A module that implements the API can't rightly claim to be conforming to it if it does things differently.

I would not call this behavior for cursor.rowcount an "addition".

How are other modules that handle cursor.rowcount as documented in PEP 249 dealing with the issue?

Other DBs give them access to meta-information that Oracle doesn't?

Do they run a separate select COUNT(*)?

I think it would probably be better to do whatever has got to be done to conform with PEP 249, but

Anthony and others may feel otherwise so, I will just respectfully submit this issue for review by the

implementors.

Thanks,

Erik Johnson

-----Original Message-----
From: Amaury Forgeot d'Arc

Sent: Nov 3, 2015 10:01 AM

To: [email protected], cx-oracle-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org

Subject: Re: [cx-oracle-users] cursor.rowcount not functioning as expected

Hi,

2015-11-03 17:43 GMT+01:00 <[email protected] >:

I haven't seen any messages on this list for several days.

I'm not sure if things are just quiet or I am having issues with the list server.

No, it's just a quiet list. But your question is perfectly on-topic.

My apologies if this is duplicate - I never saw any response, so I am sending it again.

(If this message was already received and there have been responses then I am indeed

having mail list issues and I am not sure how to resolve that - please copy any other

responses directly to me.)

I am starting to use cx_Oracle and happy to have it so, thanks Anthony for sharing your work.

Maybe I am not understanding something about the documentation of cursor.rowcount

The 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 ).

On the other hand, cxOracle docs say:

"This read-only attribute specifies the number of rows that have currently been fetched from the cursor (for select statements)..."

http://cx-oracle.readthedocs.org/en/latest/cursor.html#Cursor.rowcount

This is how Oracle works, there is no way to retrieve the number of rows upfront,

unless you run a "select count(*)" query.

I have a cursor variable in the interpreter as 'cur':

>>> 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 cur.rowcount should return 389 in the first call above.

Is that not the right interpretation?

Thanks,

Erik Johnson

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

_______________________________________________

cx-oracle-users mailing list

cx-oracle-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org

https://lists.sourceforge.net/lists/listinfo/cx-oracle-users

--

Amaury Forgeot d'Arc

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

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