Re: [cx-oracle-users] cursor.rowcount not functioning as expected
Brought to you by:
atuining
From: <ejo...@ea...> - 2015-11-03 18:19:07
|
<head><style>body{font-family: Geneva,Arial,Helvetica,sans-serif;font-size:9pt;background-color: #ffffff;color: black;}</style></head><body id="compText"><div><br></div>Thanks for your reply, Amaury...<div><br></div><div>The README file distributed with cx_Oracle states:</div><div><br></div><div><div><span style="font-size: 9pt;">cx_Oracle is a Python extension module that allows access to Oracle and</span></div><div>conforms to the Python database API 2.0 specifications with a number of</div><div>additions. The method cursor.nextset() and the time data type are not</div><div>supported by Oracle and are therefore not implemented.</div><div><br></div><div><br></div><div>Maybe there are sound efficiency reasons why cursor.rowcount doesn't give correct number</div><div>until you have fetched from the cursor - I don't know the nitty-gritty technical details</div><div>inside the cx_Oracle C code, but I can obviously count records after I've fetched them all.</div><div>At the very least, this should be documented as a deviation from the published</div><div>"Python database API 2.0".</div><div><br></div><div>A module that implements the API can't rightly claim to be conforming <span style="font-size: 9pt;">to it if it does things differently.</span></div><div><span style="font-size: 9pt;">I would not call this behavior for cursor.rowcount an "addition".</span></div><div><br></div><div>How are other modules that handle cursor.rowcount as documented in PEP 249 dealing with the issue?</div><div>Other DBs give them access to meta-information that Oracle doesn't?</div><div>Do they run a separate select COUNT(*)?</div><div><br></div><div>I think it would probably be better to do whatever has got to be done to conform with PEP 249, but </div><div>Anthony and others may feel otherwise so, I will just respectfully submit this issue for review by the</div><div>implementors.</div><div><br></div><div>Thanks,</div><div>Erik Johnson</div><div><br></div><blockquote style="padding-left: 5px; margin-left: 0px; border-left: #0000ff 2px solid; font-weight: normal; font-style: normal; text-decoration: none; font-size: 10pt; font-family: arial,sans-serif; color: black;">-----Original Message----- <br>From: Amaury Forgeot d'Arc <ama...@gm...> <br>Sent: Nov 3, 2015 10:01 AM <br>To: ejo...@ea..., cx-...@li... <br>Subject: Re: [cx-oracle-users] cursor.rowcount not functioning as expected <br><br><div dir="ltr">Hi,<div class="gmail_extra"><br><div class="gmail_quote">2015-11-03 17:43 GMT+01:00 <span dir="ltr"><<a target="_blank" href="mailto:ejo...@ea...">ejo...@ea...</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br> I haven't seen any messages on this list for several days.<br> I'm not sure if things are just quiet or I am having issues with the list server.<br></blockquote><div><br></div><div>No, it's just a quiet list. But your question is perfectly on-topic.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> My apologies if this is duplicate - I never saw any response, so I am sending it again.<br> (If this message was already received and there have been responses then I am indeed<br> having mail list issues and I am not sure how to resolve that - please copy any other<br> responses directly to me.)<br> <br> I am starting to use cx_Oracle and happy to have it so, thanks Anthony for sharing your work.<br> <br> Maybe I am not understanding something about the documentation of cursor.rowcount<br> The documentation at:<br> <br> <a target="_blank" href="https://www.python.org/dev/peps/pep-0249/#cursor-attributes" rel="noreferrer">https://www.python.org/dev/peps/pep-0249/#cursor-attributes</a> says:<br> <br> .rowcount<br> 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 ).<br></blockquote><div><br></div><div>On the other hand, cxOracle docs say:</div><div>"This read-only attribute specifies the number of rows that have currently been fetched from the cursor (for select statements)..."<br></div><div><a target="_blank" href="http://cx-oracle.readthedocs.org/en/latest/cursor.html#Cursor.rowcount">http://cx-oracle.readthedocs.org/en/latest/cursor.html#Cursor.rowcount</a><br></div><div><br></div><div>This is how Oracle works, there is no way to retrieve the number of rows upfront,</div><div>unless you run a "select count(*)" query.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> <br> I have a cursor variable in the interpreter as 'cur':<br> <br> >>> cur.execute('select * from isotope')<br> <__builtin__.OracleCursor on <cx_Oracle.Connection to some_user@some_sid>><br> >>> cur.rowcount<br> 0<br> >>> recs = cur.fetchall()<br> >>> recs[0]<br> ('Co-55', 'Cobalt 55', None, None)<br> >>> len(recs)<br> 389<br> >>> cur.rowcount<br> 389<br> <br> I think cur.rowcount should return 389 in the first call above.<br> Is that not the right interpretation?<br> <br> Thanks,<br> Erik Johnson<br> <br> ------------------------------------------------------------------------------<br> _______________________________________________<br> cx-oracle-users mailing list<br> <a target="_blank" href="mailto:cx-...@li...">cx-...@li...</a><br> <a target="_blank" href="https://lists.sourceforge.net/lists/listinfo/cx-oracle-users" rel="noreferrer">https://lists.sourceforge.net/lists/listinfo/cx-oracle-users</a><br> </blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Amaury Forgeot d'Arc</div> </div></div> </ama...@gm...></blockquote></div></body> |