Problem with sqlite3 cursor and imbricated for loop

C

Charles V.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top