ExecuteSQLUpdate: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 22: Line 22:
===Returns===
===Returns===
The function returns a ''boolean'' which is ''true'' on success, and ''false'' on failure.
The function returns a ''boolean'' which is ''true'' on success, and ''false'' on failure.
==Example==
This example keeps track of the largest number of players playing at once on the server and announces each time the record has been broken.
<syntaxhighlight lang="lua">
-- Trigger our function every time a player joins
addEventHandler ( "onPlayerJoin", getRootElement(), "maxPlayerCounter" )
function maxPlayerCounter ( )
    getRegistryValue ( res, "myscript_stats", "mostplayers", "", 1 ) -- get the mostPlayers result from our global stats row
    mostPlayers = getRegistryRowValue ( res, 0 ) -- get the actual mostPlayers value from the result-object
    playerCount = getPlayerCount() -- get the number of players now
    if ( mostPlayers == false or playerCount > mostPlayers ) -- see if there was a previous record and if there was, see if we've broken it
        outputChatBox ( "New player count record: " .. playerCount .. " players!" ) -- display a message in the chat box
        setRegistryValue ( "myscript_stats", "mostplayers = " .. playerCount ) -- store our new record
    end
end
</syntaxhighlight>


==See Also==
==See Also==
{{Registry_functions}}
{{Registry_functions}}

Revision as of 00:49, 23 September 2006

This function sets one or more rows in the registry. Since the registry is powered by a SQLite database, this function automatically executes an UPDATE query with the appropriate parameters.

The registry is stored globally and can be read from and written to by all scripts in sessions. This is useful if you want to store data for your script.

The actual SQL query that is executed will be the following:

UPDATE <table> SET <set> WHERE <conditions>

Syntax

bool setRegistryQuery ( string table, string set, [ string conditions ] )

Required Arguments

  • table: The table you want to modify.
  • set: The query you want to execute on that table. The default SQL syntax is used, which means that the = is used to set a value and the ' is used to specify a value (e.g. test = 'hi' ). The , is used as a delimiter for multiple queries.

Optional Arguments

  • conditions: The conditions that need to be met before a specific row is changed.

Returns

The function returns a boolean which is true on success, and false on failure.

See Also