0

Using Python 3 and sqlite, I perform a query that gives me results I want to iterate over. But, as part of what I want to do in the iteration, I want to perform a second query. But, when I do the second query, the results from the first query are destroyed by the second query and my script stops iterating over the first query because there is nothing left from the first query to iterate over (hoping this makes sense!). Is it possible to have 2 or more query results in the same script unaffected by each other? Or, what is a good/best way to resolve this issue?

Here's an example of what I mean:

    curs.execute('SELECT number1, number2, FROM numbers WHERE ID = 3')
    for row in curs:
        do this (whatever?)
        do this (whatever?)
        curs.execute('UPDATE table1 SET ID = "foo" WHERE state = "bar"')
        conn.commit()
Jeff F
  • 975
  • 4
  • 14
  • 24

1 Answers1

0

Not an expert but they should have unique names.

WhyEnBe
  • 295
  • 7
  • 22
  • Not sure how to do that. Tried adding a 2nd cursor; get an error. Tried creating 2 query variables; get an error. – Jeff F May 22 '15 at 18:42
  • In that case take a look at [this](http://stackoverflow.com/questions/13237788/using-multiple-cursors-in-a-nested-loop-in-sqlite3-from-python-2-7) – WhyEnBe May 22 '15 at 18:49
  • Thanks for the link, Yaakov. Basically, what I want to do is not able to be easily done. For others that come here looking for an answer, I suggest looking at the link, too. – Jeff F May 22 '15 at 21:18