SQLite Question

My Table:
table:
ROWS | map | pos
#1 | gm_construct | 10 15 0
#2 | gm_flatgrass | 35 21 44
#3 | gm_construct | 55 12 24



value = sql.QueryValue("SELECT pos FROM table WHERE map = '"..game.GetMap().."'")


So if the server is currently running on gm_construct will value be a table containing the pos from #1 and #3? Or will it just take a random rown betwin #1 and #3?

It will select the pos values from both row 1 and 3 and put them into a table. You could read from them by doing this:



for k, v in pairs( value ) do
 print( v["pos"] )
end


[editline]20th December 2013[/editline]

basically it creates a multi-columned table. Effectively what a multi-columned table is, is a table where each value within the table is another table, and you read it as such.

Ok thanks!

I actually just tried that and it does not create a table but get the string of the first value found, how can I make it generate a table?

Hello french comrade
You need to use sql.QueryRow instead
[LUA]
local value = sql.QueryRow(“SELECT pos FROM table WHERE map = '”…game.GetMap()…"’")
PrintTable(value)
[/lua]

(not sure if that works though)

You can use a visual editor to assist you in writing SQL queries. For SQLite, I recommend using SQLite Administrator. Then just open up garrysmod/sv.db or cl.db.

[lua]function leaderboards.Setup()
if ( !sql.TableExists( “playerlbdata” ) ) then
local query = [[CREATE TABLE playerlbdata (
SteamID INTEGER NOT NULL PRIMARY KEY,
Name TEXT,
InnocentKills INTEGER DEFAULT 0,
TraitorKills INTEGER DEFAULT 0,
BombKills INTEGER DEFAULT 0,
KnifeKills INTEGER DEFAULT 0,
HeadShots INTEGER DEFAULT 0,
TTTWinLoseRatio NUMERIC DEFAULT 1,
TimePlayed INTEGER DEFAULT 0,
DistanceTravelled INTEGER DEFAULT 0,
TotalMessages INTEGER DEFAULT 0,
TotalMicTime INTEGER DEFAULT 0
);]]

    sql.Query( query )
end

end[/lua]

Run once setup scripts are better.

It still returns the first value found for some reasons.
But it actually answered a question I was going to ask to get stuff from my angles column.

Basically what I would like to have is tables in a table.
Like this:



Found = {
    {String (Pos), String (Angles)}
    {String (Pos), String (Angles)}
}


After looking around I figured out that I should be using:



value = sql.Query("Your SELECT Query")


To get a proper table of all results found.