[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Cleaning up iterators
- From: Doug Currie <doug.currie@...>
- Date: Tue, 26 Jul 2011 16:18:43 -0400
On Jul 26, 2011, at 3:10 PM, Antonio Vieiro wrote:
> I'm thinking of using iterator to iterate over the results of a SQL query, something like:
>
> for row in result("SELECT id,name FROM USER") do
> if row.id == 3 then break end
> end
>
> but I need to "clean-up" the iterator when it finishes (i.e. after the loop) or whenever I have a "break" or a "return" statement.
LuaSQLite3 (lsqlite3) remembers whether an iterator is created from SQL statement text or from a cursor. If created from text, it is reclaimed when the iteration terminates normally, or upon gc if the iteration terminates abnormally. For cursors (also known as compiled statements or VMs), the iterator is retained so it may be re-wound (or re-bound and re-wound) and re-used.
See db_do_next_row and svm->temp in
http://lua.sqlite.org/index.cgi/artifact/6cffe40718ef1d538a63ad8459caad19d8794717
e