DbFree: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "__NOTOC__ {{Server function}} {{New feature|3.0120|1.2| '''Available only in MTA SA 1.1.1 r3328 and onwards''' }} This function frees a database query handle. ==Syntax== <syntaxhighlight lang="lua"...")
 
(Remove obsolete Requirements section)
 
(8 intermediate revisions by 6 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Server function}}
{{Server function}}
{{New feature|3.0120|1.2|
This function frees a database query handle. dbFree only needs to be used if a result has not been obtained with [[dbPoll]]
'''Available only in MTA SA 1.1.1 r3328 and onwards'''
}}
This function frees a database query handle.


==Syntax==  
==Syntax==  
Line 10: Line 7:
bool dbFree ( handle queryHandle )
bool dbFree ( handle queryHandle )
</syntaxhighlight>
</syntaxhighlight>
 
{{OOP||queryHandle:free}}
===Required Arguments===
===Required Arguments===
*'''queryHandle:''' A query handle previously returned from [[dbQuery]]
*'''queryHandle:''' A query handle previously returned from [[dbQuery]]
Line 18: Line 15:


==Example==
==Example==
This example frees a database query handle
=====These examples show when dbFree should be used:=====
<div style="margin-left:20px">
Required because [[dbPoll]] was not called:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local qh = dbQuery( connection, "SELECT * FROM table_name" )
dbFree ( qh )
dbFree ( qh )
</syntaxhighlight>
</syntaxhighlight>
Required because [[dbPoll]] was not called:
<syntaxhighlight lang="lua">
function aaa()
    dbQuery( myCallback, connection, "SELECT * FROM table_name" )
end
function myCallback(qh)
    dbFree ( qh )
end
</syntaxhighlight>
Required because [[dbPoll]] is called, but the result was not ready and no more attempts will be made:
<syntaxhighlight lang="lua">
local qh = dbQuery( connection, "SELECT * FROM table_name" )
local result = dbPoll( qh, 10 )    -- Get result with a timeout of 10ms
if result == nil then
    result = dbPoll( qh, 10 )      -- Try again to get result with a timeout of 10ms
    if result == nil then
        dbFree( qh )                -- Give up
    end
end
</syntaxhighlight>
</div><br>
=====These examples show when dbFree should NOT be used:=====
<div style="margin-left:20px">
Not required because [[dbPoll]] was called with a -1 timeout:
<syntaxhighlight lang="lua">
local qh = dbQuery( connection, "SELECT * FROM table_name" )
local result = dbPoll( qh, -1 )    -- Wait until result has been gotten
</syntaxhighlight>
Not required because [[dbPoll]] was called from the callback:
<syntaxhighlight lang="lua">
function aaa()
    dbQuery( myCallback, connection, "SELECT * FROM table_name" )
end


==Requirements==
function myCallback(qh)
{{Requirements|1.1.1-9.03328|n/a}}
    local result = dbPoll( qh, 0 )  -- Timeout doesn't matter here because the result will always be ready
end
</syntaxhighlight>
</div>


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

Latest revision as of 15:35, 7 November 2024

This function frees a database query handle. dbFree only needs to be used if a result has not been obtained with dbPoll

Syntax

bool dbFree ( handle queryHandle )

OOP Syntax Help! I don't understand this!

Method: queryHandle:free(...)


Required Arguments

  • queryHandle: A query handle previously returned from dbQuery

Returns

Returns true if the handle was successfully freed, false otherwise.

Example

These examples show when dbFree should be used:

Required because dbPoll was not called:

local qh = dbQuery( connection, "SELECT * FROM table_name" )
dbFree ( qh )

Required because dbPoll was not called:

function aaa()
    dbQuery( myCallback, connection, "SELECT * FROM table_name" )
end

function myCallback(qh)
    dbFree ( qh )
end

Required because dbPoll is called, but the result was not ready and no more attempts will be made:

local qh = dbQuery( connection, "SELECT * FROM table_name" )
local result = dbPoll( qh, 10 )     -- Get result with a timeout of 10ms
if result == nil then
    result = dbPoll( qh, 10 )       -- Try again to get result with a timeout of 10ms
    if result == nil then
        dbFree( qh )                -- Give up
    end
end


These examples show when dbFree should NOT be used:

Not required because dbPoll was called with a -1 timeout:

local qh = dbQuery( connection, "SELECT * FROM table_name" )
local result = dbPoll( qh, -1 )    -- Wait until result has been gotten

Not required because dbPoll was called from the callback:

function aaa()
    dbQuery( myCallback, connection, "SELECT * FROM table_name" )
end

function myCallback(qh)
    local result = dbPoll( qh, 0 )  -- Timeout doesn't matter here because the result will always be ready
end

See Also