Raised This Month: $12 Target: $400
 3% 

Solved Clarify docs: What is multiple result set for SQL_LockDatabase()?


Post New Thread Reply   
 
Thread Tools Display Modes
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
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 06-21-2021 , 03:46   Re: Clarify docs: What is multiple result set for SQL_LockDatabase()?
Reply With Quote #2

Each SQL query can return one or more result sets that each contain zero or more rows.

Only procedure calls can return multiple result sets with SM (as it says in the doc you quoted, since it doesn’t support using a semicolon to run multiple queries), so 99% of code doesn’t need to care about them and only needs to iterate over the rows of the first result set which is loaded automatically (as your code is doing).

There are separate MoreResults and FetchResult for additionally iterating over result sets.
__________________
asherkin is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 06-21-2021 , 12:47   Re: Clarify docs: What is multiple result set for SQL_LockDatabase()?
Reply With Quote #3

Good to know. Thanks for the explanation!
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:57.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode