DbFree: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Server function}}
{{Server function}}
{{New feature/item|3.0120|1.2|3328|  
{{New feature/item|3.0110|1.1|3328|  
'''Available only in MTA SA 1.1.1 r3328 and onwards'''
'''Available only in MTA SA 1.1.1 r3328 and onwards'''
}}
}}

Revision as of 14:52, 7 December 2011

Available only in MTA SA 1.1.1 r3328 and onwards 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 )

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

Requirements

Minimum server version 1.1.1-9.03328
Minimum client version n/a

Note: Using this feature requires the resource to have the above minimum version declared in the meta.xml <min_mta_version> section. e.g. <min_mta_version server="1.1.1-9.03328" />

See Also