|
On Sep 9, 2016 8:04 PM, "Leinen, Rick" <RLeinen@leviton.com> wrote:
> I’m confused with stmt:step(). What does it do? I read about it and did a couple of experiments, but it still doesn’t make sense.
>
> Also, I don’t see sqlite3.ROW listed at http://lua.sqlite.org/index.cgi/doc/tip/doc/lsqlite3.wiki. Should I be looking elsewhere?
You can think of step() as executing the select and returning one row. The "core" Sqlite3 API for selecting data is designed to be used roughly this way:
stmt = db:prepare('SELECT ...')
-- optionally stmt:bind* to set '?' values
while stmt:step() == sqlite3.ROW do
-- A single row of resulting data has been processed.
-- Access column data using stmt:get_*
end
stmt:finalize() -- if you won't use stmt again
-- or
stmt:reset() -- if you want to re-run stmt again
There are several Lua-style iterators in the API that simplify this for you, some without you needing to 'prepare' a statement beforehand, such as db:rows().