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

Multiple queries (or queries queue)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
notMe2
Member
Join Date: Feb 2014
Old 10-07-2016 , 10:51   Multiple queries (or queries queue)
Reply With Quote #1

I'm trying to execute the code bellow, but the only the first query executes:
Code:
for(int i = 0; i <= MAXPLAYERS; i++)
{
    if(!isValidClient(i))
        continue;

    //query build

    SQL_TQuery(hDb, T_CommomQuery, sQuery, _, DBPrio_Normal); 
}
Any ideas why?
notMe2 is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 10-07-2016 , 11:21   Re: Multiple queries (or queries queue)
Reply With Quote #2

not sure why exactly, but initialize the loop like this:
Code:
for(int i = 1; i <= MaxClients; i++)
client indexes start from 1 and looping until MAXPLAYERS is bad because it's a constant value (i think of 55); looping up to MaxClients is better because that's the biggest number that could be an entity index with your maxplayer setting
__________________
retired
shavit is offline
notMe2
Member
Join Date: Feb 2014
Old 10-07-2016 , 13:05   Re: Multiple queries (or queries queue)
Reply With Quote #3

Quote:
Originally Posted by shavit View Post
not sure why exactly, but initialize the loop like this:
Code:
for(int i = 1; i <= MaxClients; i++)
client indexes start from 1 and looping until MAXPLAYERS is bad because it's a constant value (i think of 55); looping up to MaxClients is better because that's the biggest number that could be an entity index with your maxplayer setting
Hey shavit, thanks for your tips.

The usual game is only 5 vs. 5, i don't think that the size of loop is the problem. The problem is that only the first query is executed, the other 9 (in case of 5vs5) are ignored.
notMe2 is offline
Kryptanyte
Junior Member
Join Date: Dec 2015
Old 10-07-2016 , 15:02   Re: Multiple queries (or queries queue)
Reply With Quote #4

I'm not sure if I'm right about this but starting a query inside the for loop will break it (end the for loop) and wait for the query to respond.

You could try using transactions instead of doing each query individually - Transactions take several queries and execute them sequentially then pass results back to callbacks.

See this for more information: https://sm.alliedmods.net/new-api/dbi/Database/Execute

eg:
Code:
Transaction th_Queries = null;
th_Queries = SQL_CreateTransaction();
     
for(int i = 1; i < MaxClients; i++)
    SQL_AddQuery(th_Queries, /*Put your query here*/, /*Put your query data (if any) here*/);

SQL_Execute(hDb, th_Queries, SQL_QuerySuccess_Callback, SQL_QueryFailed_Callback);
Also don't think you can do threaded transaction queries so you will need to lock your database I would assume since you have to for regular queries, I'm not very familiar with threaded queries so if someone wants to correct me if I'm wrong please feel free
Kryptanyte is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 10-08-2016 , 01:23   Re: Multiple queries (or queries queue)
Reply With Quote #5

Also if you plan on passing a client id through the transaction make sure you convert it to userid then convert it back to index when the callback is called.
Transactions are the best way to catch all players instead of doing one by one.
I have an example of using two different queries to get player settings etc in my build mod:
Spoiler
Mitchell is offline
notMe2
Member
Join Date: Feb 2014
Old 10-10-2016 , 10:52   Re: Multiple queries (or queries queue)
Reply With Quote #6

Thanks guys! both Mitchell and Kryptanyte solutions worked for me
notMe2 is offline
Reply



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 03:40.


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