cx_Oracle, is anything selected?

Diez B. Roggisch deets at web.de
Tue Nov 1 08:23:34 EST 2005


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

then lazy-initialize the smpt object inside the loop. Or use c.fetchone
for the first entry, and loop over the remaining results.

Apart from that: what harm does the connection to the smpt do? If it
works - keep it that way.

Regards,

Diez




More information about the Python-list mailing list