How do you return an array from a sqlite database in lua?
I have this sameple code here:
function getMoveName()
tempMoveName = {}
for row in db:nrows("SELECT * FROM movetable") do
tempMoveName = row.movename .. " " .. row.totalcubicfeet .. " " .. row.totalitem .. "\n"
end
return tempMoveName
end
which will return the content of the database and then print the content with this line of code:
local displaymovenames = mydatabase.getMoveName()
print ( displaymovenames )
however it only returns the last data and not all of the contents of it.
What you are doing is for every row, you just store the row data in the variable tempMoveName and hence overwriting the previous value.
You need to add the rowData to the table tempMoveName.
EDIT
To access the table elements you have to do the following
note that
#tempMoveNamegives the length of the table(i.e no. of elements in the table)P.S if you are going to do a lot of coding in Lua, I’d suggest you get a grip on the basics of Tables, cos table is the main datatype of Lua. Arrays, lists, dictionaries, classes and almost everything are implemented via tables. Here is a tutorial for a start!