By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,660 Members | 1,105 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,660 IT Pros & Developers. It's quick & easy.

cx_Oracle, is anything selected?

P: n/a
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?

--
damjan
Oct 31 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Damjan wrote:
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.

Diez
Nov 1 '05 #2

P: n/a
>> 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
Nov 1 '05 #3

P: n/a
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

Nov 1 '05 #4

P: n/a
Damjan wrote:
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. [...]


Well, something like:

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

-- Gerhard

Nov 1 '05 #5

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


I worry about being banned from the server.

--
damjan
Nov 1 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.