Problem with sqlite3 cursor and imbricated for loop

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Charles V.

    Problem with sqlite3 cursor and imbricated for loop

    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('''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]
    c.execute("sele ct * 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
Working...