lua-ljsqlite3 icon indicating copy to clipboard operation
lua-ljsqlite3 copied to clipboard

Rows iterator

Open mnemnion opened this issue 6 years ago • 0 comments

for row in stmt:rows() do

stmt:rows() is an iterator function like pairs or ipairs, performing one :step() at a time until all rows are returned. It clearbinds and resets the prepared statement.

local conn = sql.open("")
conn:exec[[
CREATE TABLE t(id TEXT, num REAL);
INSERT INTO t VALUES('myid1', 200);
INSERT INTO t VALUES('myid2', 400);
]]
local stmt = conn:prepare("SELECT * FROM t")
for row in stmt:rows() do
  print(unpack(row))
end

--> myid1 200
--> myid2 400

mnemnion avatar Oct 04 '18 21:10 mnemnion