[Tutor] sqlite3 Question

Prasad, Ramit ramit.prasad at jpmorgan.com
Wed Jun 6 21:36:35 CEST 2012


> 
> 1. import sqlite3
> 2. conn=sqlite3.connect("mydb2.db")
> 3. c=conn.cursor()
> 4. c.execute('create table family (Id integer primary key, name text, age
> integer)')
> 5. c.execute("insert into family values (1,'elham',32)")
> 6. c.execute('select * from family')
> 7. conn.commit()
> 8. for i in c:
> 9.     print(i)
> 
> Why is it that if I call the for statement in the shell it doesn't print the
> information more than once? I've found this to be true in other situations
> where cursor carries the data only once. So, how can i manipulate/use the data
> if I can only access it once? I have tried applying useing x=list(c), but it
> doesn't seem to work!

The cursor only remembers the last action so you need to get the results 
before reusing the cursor. If you want to keep the data in memory you can use 
    data = c.fetchall()# or c.fetchmany(num) or c.fetchone()


Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--

This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  


More information about the Tutor mailing list