sql.Query

From GMod Wiki

Revision as of 11:24, 14 August 2010 by DarKSunrise (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Function
Syntax sql.Query( String query )
Where is this used?
Description:
Queries the SQLite database.
Returns: Table
Part of Library: Sql
Realm: NewerShared.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Sql.Query]Sql.Query [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Examples

DescriptionThis was taken from ratings.lua in sandbox.
Used onNewerShared.png
Code
/*---------------------------------------------------------
   Name: Update the player's networkvars based on the DB
---------------------------------------------------------*/
local function UpdatePlayerRatings( ply )
	local result = sql.Query( "SELECT rating, count(*) as cnt FROM ratings WHERE target = "..ply:UniqueID().." GROUP BY rating " )
 
	if ( !result ) then return end
 
	for id, row in pairs( result ) do
		ply:SetNetworkedInt( "Rating."..ValidRatings[ tonumber( row['rating'] ) ], tonumber( row['cnt'] ) )
	end
end
OutputN/A


Additional Notes

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox