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

Problem with sqlite3 cursor and imbricated for loop

P: n/a
Hi,

I hope this is not already known. But Google wasn't any help. So here begins a
script to explain my problem.

-------------------------
import sqlite3
conn = sqlite3.connect(':memory:')
c = conn.cursor()
c.execute('''create table stocks
(date text, trans text, symbol text,
qty real, price real)''')
c.execute("insert into stocks values ('2006-01-05','BUY','RHAT',100,35.14)")
c.execute("insert into stocks values ('2006-01-06','BUY','RHAT',100,20.0)")
c.execute("insert into stocks values ('2006-01-07','BUY','RHAT',100,15.0)")
c.execute("insert into stocks values ('2006-01-08','BUY','RHAT',100,10.0)")
conn.commit()
c.execute("select * from stocks")
for s in c:
print s[0]
c.execute("select * from stocks where price<20")
for s in c:
print ' '+s[0]
c.close()
-------------------------

It is a adapted copy of the example in the Python documentation. But I was
expecting the output as with MySQL engine but, here, I get only:
2006-01-05
2006-01-07
2006-01-08

It seems the second call to execute modify the first cursor. Is it normal ?
How am I suppose to write this ?

Thanks

Charles
Nov 11 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.