Charles V. wrote:
Maybe introduce a second cursor?
import sqlite3
conn = sqlite3.connect (':memory:')
c = conn.cursor()
d = conn.cursor() # second cursor
c.execute('''cr eate table stocks
(date text, trans text, symbol text,
qty real, price real)''')
c.execute("inse rt into stocks values ('2006-01-05','BUY','RHAT ',100,35.14)")
c.execute("inse rt into stocks values ('2006-01-06','BUY','RHAT ',100,20.0)")
c.execute("inse rt into stocks values ('2006-01-07','BUY','RHAT ',100,15.0)")
c.execute("inse rt into stocks values ('2006-01-08','BUY','RHAT ',100,10.0)")
conn.commit()
c.execute("sele ct * from stocks")
for s in c:
print s[0]
d.execute("sele ct * from stocks where price<20") # use the second cursor
for s in d:
print ' '+s[0]
c.close()
Outputs:
2006-01-05
2006-01-07
2006-01-08
2006-01-06
2006-01-07
2006-01-08
2006-01-07
2006-01-07
2006-01-08
2006-01-08
2006-01-07
2006-01-08
--
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Vallopillil
It seems the second call to execute modify the first cursor. Is it normal ?
How am I suppose to write this ?
How am I suppose to write this ?
import sqlite3
conn = sqlite3.connect (':memory:')
c = conn.cursor()
d = conn.cursor() # second cursor
c.execute('''cr eate table stocks
(date text, trans text, symbol text,
qty real, price real)''')
c.execute("inse rt into stocks values ('2006-01-05','BUY','RHAT ',100,35.14)")
c.execute("inse rt into stocks values ('2006-01-06','BUY','RHAT ',100,20.0)")
c.execute("inse rt into stocks values ('2006-01-07','BUY','RHAT ',100,15.0)")
c.execute("inse rt into stocks values ('2006-01-08','BUY','RHAT ',100,10.0)")
conn.commit()
c.execute("sele ct * from stocks")
for s in c:
print s[0]
d.execute("sele ct * from stocks where price<20") # use the second cursor
for s in d:
print ' '+s[0]
c.close()
Outputs:
2006-01-05
2006-01-07
2006-01-08
2006-01-06
2006-01-07
2006-01-08
2006-01-07
2006-01-07
2006-01-08
2006-01-08
2006-01-07
2006-01-08
--
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Vallopillil