Hi, I'm not very familiar with Lua's SQL interface(or SQL for that matter), but I was wondering if there was a way to get a value from a row/column without having to iterate over a table to store it into a variable? Similar to accessing a value directly in a table i.e. myvalue = table['atable']['btable']['something']?
At the moment i'm using nrows. It seems to me, that if I knew what I was looking for, using nrows would be inefficient to put things into variables with.
Thanks.
The whole idea of SQL is to store large amounts of data (eg. a telephone directory) and then get small bits back (eg. the phone number for "Marcopolo") by doing a SELECT statement that limits the amount that is returned.
If you narrow down your search enough (eg. if you look up a player, the player names are unique, and you search by player name) then you should only ever need to get one row.
I think what I really meant to ask was how I would go about putting the result of a select statement into a variable without dealing with a table?
At the moment I do this:
for a in db:nrows([[SELECT timestamp FROM trade WHERE area = ']]..currentzone..[[']]) do
last_update=a["timestamp"]
end
Is this the only way to put a single field of information into a variable? Do all results from a select statement end up being a table?
Well, you *can* - I'm not sure it's worth the effort.
http://www.gammon.com.au/scripts/doc.php?general=lua_sqlite3
You can: