View Single Post
Author Message
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 06-20-2021 , 16:52   Clarify docs: What is multiple result set for SQL_LockDatabase()?
Reply With Quote #1

Hi,

can you clarify, please, this statement from docs:

Quote:
If your query returns multiple result sets, for example, a procedure call on MySQL that returns results, you must lock both the query and the entire fetch operation. SourceMod is only able to fetch one result set at a time, and all result sets must be cleared before a new query is started.
Can you show / explain example of such multiple result set?

Sample from docs:

PHP Code:
bool GetByAge_Query(Database dbint age)
{
    
char query[100];
    
FormatEx(querysizeof(query), "SELECT name FROM users WHERE age = %d"age);
 
    
SQL_LockDatabase(db);
 
    
DBResultSet hQuery SQL_Query(dbquery);
    if (
hQuery == null)
    {
        
SQL_UnlockDatabase(db);
        return 
false;
    }
 
    
SQL_UnlockDatabase(db);
 
    
PrintResults(hQuery);
 
    
delete hQuery;
 
    return 
true;
}

void PrintResults(Handle query)
{
    
/* Even if we have just one row, you must call SQL_FetchRow() first */
    
char name[MAX_NAME_LENGTH];
    while (
SQL_FetchRow(query))
    {
        
SQL_FetchString(query0namesizeof(name));
        
PrintToServer("Name \"%s\" was found."name);
    }

Do I correctly understand, if SQL_Query returns more than one row (such a way several calls to SQL_FetchRow will be required), in such case I should also move SQL_UnlockDatabase below the PrintResults?
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]

Last edited by Dragokas; 06-21-2021 at 12:48.
Dragokas is offline