Garry's Mod Wiki

sql.QueryValue

sql.QueryValue

string sql.QueryValue( string query )

Description

Performs the query like sql.QueryRow, but returns the first value found.

Arguments

1 string query
The input query.

Returns

1 string
The returned value.

Example

Functions that are examples of saving and creating information into the database.

function CreateTable() sql.Query( "CREATE TABLE IF NOT EXISTS player_data ( SteamID TEXT, Money INTEGER )" ) end function SavePlayerToDataBase( ply, Money ) local data = sql.Query( "SELECT * FROM player_data WHERE SteamID = " .. sql.SQLStr( ply:SteamID() ) .. ";") if ( data ) then sql.Query( "UPDATE player_data SET Money = " .. Money .. " WHERE SteamID = " .. sql.SQLStr( ply:SteamID() ) .. ";" ) else sql.Query( "INSERT INTO player_data ( SteamID, Money ) VALUES( " .. sql.SQLStr( ply:SteamID() ) .. ", " .. Money .. " )" ) end end function LoadPlayerToDataBase( ply ) local val = sql.QueryValue( "SELECT Money FROM player_data WHERE SteamID = " .. sql.SQLStr( ply:SteamID() ) .. ";" ) return val end

Special Pages


Wikis

?

Render Time: 131ms

DB GetPage 109
Generate Html 4
SaveChanges (1) 9
Render Body 0
Render Sidebar 6