|
I see how you can print the values in a database table using db:nrows in a For statement, but what if I want just a single entry?
This one works, but doesn’t seem very elegant:
[...]
This one doesn’t:
local sqlite3 = require("lsqlite3")
local db = sqlite3.open("test.db");
db:exec [[
DROP TABLE if exists numbers;
CREATE TABLE numbers(num1,num2,str);
INSERT INTO numbers VALUES(1,11,"ABC");
INSERT INTO numbers VALUES(2,22,"DEF");
INSERT INTO numbers VALUES(3,33,"UVW");
INSERT INTO numbers VALUES(4,44,"XYZ");
]]
local insert_stmt = db:prepare('SELECT * FROM numbers WHERE num1=1')
x = insert_stmt:get_names()
print(x[3])
x = insert_stmt:get_value(0)
print(x[1])
Should I be doing this another way? I thought I would be able to pull queries into a Lua table, but I don’t see a way to do that.