cx_Oracle, is anything selected?

Damjan gdamjan at gmail.com
Tue Nov 1 08:12:05 EST 2005


>> Is there a way to see if the SELECT in cx_Oracle didn't return anything?
>> I want to optimize the situation when the number of selected rows is
>> zero. Is select count(*) the only option, seems inefficient?
> 
> I don't understand your problem - if your select doesn't return
> anything, the fetch* methods on the cursor will tell you if there is any
> data to expect at all. Additionally there is teh rowcount-property that
> holds the number of rows the last execute* yielded.

This is a simplification of the program

c = db.cursor()
while 1:
    c.execute('select ....')
    smtp = SMTP(MAIL_HOST, 25, 'localhost')
    for address, subject, body in c:
        smtp.sendmail(....)
    smtp.quit()
    time.sleep(60)

now if the select doesn't return any rows, there's no need to connect to the
mail server. I'd like to avoid that unnecessary step.

c.rowcount will not give me the number of rows selected, it will only give
me the number of rows already fetched.


-- 
damjan



More information about the Python-list mailing list