It is perfectly allowed to open multiple cursors against a single connection.
You can only execute one statement per cursor at a time, but you can have
multiple cursors running from the same connection:
cr1 = cn.cursor()
cr2 = cn.cursor()
cr1.execute('select ...')
while True:
row = cr1.fetchone()
if not row:
break
...
cr2.execute('INSERT ...')
for example. If you are inserting into one of the tables used in the outer
select, simply make sure that select has an order by with a + in front of one
of the column names to avoid side effects (ie, changes made to the database by
the insert are visible to all statements/cursors on that connection even before
those changes are committed).
> -----Original Message-----
> From: [email protected] [mailto:sqlite-users-
> [email protected]] On Behalf Of Joseph L. Casale
> Sent: Wednesday, 17 July, 2013 13:41
> To: General Discussion of SQLite Database
> Subject: Re: [sqlite] Guidance with Python and nested cursors
>
>
> ________________________________________
> From: [email protected] on behalf of Petite Abeille
> Sent: Wednesday, July 17, 2013 1:25 PM
> To: General Discussion of SQLite Database
> Subject: Re: [sqlite] Guidance with Python and nested cursors
>
> On Jul 17, 2013, at 9:07 PM, Joseph L. Casale
> <[email protected]> wrote:
>
> >> I am using Python to query a table for all its rows, for each row,
> I query related rows from a
> >> second table, then perform some processing and insert in to a third
> table.
> >>
> >> What is the technically correct approach for this?
> >
> >From the above outline, one SQL statement:
>
> Hi,
> Problem is I need to perform some Python processing of the data, then
> insert.
>
> Thanks!
> jlc
> _______________________________________________
> sqlite-users mailing list
> [email protected]
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users