Raised This Month: $32 Target: $400
 8% 

SQL_FastQuery causing rollback


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
notMe2
Member
Join Date: Feb 2014
Old 02-28-2015 , 11:09   SQL_FastQuery causing rollback
Reply With Quote #1

When on game and i try to use SQL_FastQuery its "freezes" the server while the query isnt finished. Its a rlly short query (just a update), and when i remove it, the server comes back to normal. There is a way to thread it? i saw on rankme, SQL_FastQuery is used all the time and there is no problem

thanks in advance
notMe2 is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 02-28-2015 , 11:11   Re: SQL_FastQuery causing rollback
Reply With Quote #2

I can't think of a single instance where i wouldn't use threading. It's explained on this wiki page.
__________________

Last edited by Impact123; 02-28-2015 at 11:14.
Impact123 is offline
notMe2
Member
Join Date: Feb 2014
Old 02-28-2015 , 11:17   Re: SQL_FastQuery causing rollback
Reply With Quote #3

Quote:
Originally Posted by Impact123 View Post
I can't think of a single instance where i wouldn't use threading. It's explained on this wiki page.
hm, there is just a a theoretical explanation, can you show me a code or something?
notMe2 is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 02-28-2015 , 11:30   Re: SQL_FastQuery causing rollback
Reply With Quote #4

Quote:
Originally Posted by notMe2 View Post
hm, there is just a a theoretical explanation, can you show me a code or something?
How to connect to db -> https://wiki.alliedmods.net/SQL_%28S...9#Connecting_2 (SQL_TConnect)

How to send a query -> https://wiki.alliedmods.net/SQL_%28S...ng%29#Querying (SQL_TQuery)
KissLick is offline
notMe2
Member
Join Date: Feb 2014
Old 02-28-2015 , 11:39   Re: SQL_FastQuery causing rollback
Reply With Quote #5

Quote:
Originally Posted by KissLick View Post
i'm already using it, and its freezing the server.

example:

the original code from rankMe is (on function SalvarPlayer):
Code:
SQL_TQuery(g_hStatsDb,SQL_SaveCallback,query,client,DBPrio_High); //the call

public SQL_SaveCallback(Handle:owner, Handle:hndl, const String:error[], any:client)
{
    new String:query2[150];
    if(hndl == INVALID_HANDLE)
    {
        LogError("[RankMe] Save Player Fail: %s", error);
        return;
    }
    
    /**
        Start the forward OnPlayerSaved
    */
    new Action:fResult;
    Call_StartForward(g_fwdOnPlayerSaved);
    Call_PushCell(client);
    new fError = Call_Finish(fResult);
    
    if (fError != SP_ERROR_NONE)
    {
        ThrowNativeError(fError, "Forward failed");
    }
        
}
my code:
Code:
SQL_TQuery(g_hStatsDb,SQL_SaveCallback,query,client,DBPrio_High); //the call

public SQL_SaveCallback(Handle:owner, Handle:hndl, const String:error[], any:client)
{
    new String:query2[150];
    if(hndl == INVALID_HANDLE)
    {
        LogError("[RankMe] Save Player Fail: %s", error);
        return;
    }
    
    Format(query2,sizeof(query2),"UPDATE `player_inventory` SET `iPoints` = %i WHERE `player_inventory`.`steamID` = '%s' AND `iPoints` is NULL;",g_aStats[client][SCORE],g_aClientSteam[client]);
    SQL_FastQuery(g_hStatsDb,query2);
    
    Format(query2,sizeof(query2),"UPDATE `player_inventory` SET `iPoints` = `iPoints` + %i WHERE `player_inventory`.`steamID` = '%s';",(g_aStats[client][SCORE] - g_aStartedScore[client]),g_aClientSteam[client]);
    SQL_FastQuery(g_hStatsDb,query2);

    /**
        Start the forward OnPlayerSaved
    */
    new Action:fResult;
    Call_StartForward(g_fwdOnPlayerSaved);
    Call_PushCell(client);
    new fError = Call_Finish(fResult);
    
    if (fError != SP_ERROR_NONE)
    {
        ThrowNativeError(fError, "Forward failed");
    }
        
}
freezes everytime the function is called

Last edited by notMe2; 02-28-2015 at 12:01.
notMe2 is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 02-28-2015 , 12:57   Re: SQL_FastQuery causing rollback
Reply With Quote #6

Quote:
Originally Posted by Impact123 View Post
I can't think of a single instance where i wouldn't use threading. [...]
Think harder.
__________________
Santa or Satan?

Watch out when you're paying people for private requests! Most stuff already exists and you can hardly assess the quality of what you'll get, and if it's worth the money.

Last edited by Dr. Greg House; 02-28-2015 at 12:57.
Dr. Greg House is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 02-28-2015 , 15:50   Re: SQL_FastQuery causing rollback
Reply With Quote #7

Is your database on localhost? I got these problems with SQLite on localhost, I switched to mysql on different server and everythings works fine.

EDIT: i see not every your SQL query is threaded.. (SQL_FastQuery(g_hStatsDb,query2);) - make it threaded too, just use empty callback.

Last edited by KissLick; 02-28-2015 at 15:52.
KissLick is offline
notMe2
Member
Join Date: Feb 2014
Old 02-28-2015 , 23:45   Re: SQL_FastQuery causing rollback
Reply With Quote #8

OnClientPutInServer
Quote:
Originally Posted by KissLick View Post
Is your database on localhost? I got these problems with SQLite on localhost, I switched to mysql on different server and everythings works fine.

EDIT: i see not every your SQL query is threaded.. (SQL_FastQuery(g_hStatsDb,query2);) - make it threaded too, just use empty callback.
just thread them too, its not freezing, but now i'm with other problem:

I'm with a big array, smt like array[maxplayers][72], and its set when the players connect to server (OnClientPutInServer), some people are getting crashed and the game simple closes. any ideas why this happens?

and call some querys on thread (not every time) is crashing the client too

--

Maybe this crash is related to call two threaded querys at the same time?

Code:
SQL_TQuery(g_hStatsDb,SQL_LoadPlayerCallback2,sQuery,client,DBPrio_High);
SQL_TQuery(g_hStatsDb,SQL_LoadPlayerCallback,query,client);

Last edited by notMe2; 03-01-2015 at 01:08.
notMe2 is offline
neatek
AlliedModders Donor
Join Date: Jul 2010
Location: Russia
Old 03-01-2015 , 04:20   Re: SQL_FastQuery causing rollback
Reply With Quote #9

I dont know how TQuery can crash your server... but i dont recommend using OnClientPutInServer instead of OnClientPostAdminCheck.
Quote:
Originally Posted by notMe2 View Post
SQL_TQuery(g_hStatsDb,SQL_LoadPlayerCallback2 ,sQuery,client,DBPrio_High);
SQL_TQuery(g_hStatsDb,SQL_LoadPlayerCallback, query,client);
happens... omfg. You can put second query in first callback of query!

PHP Code:
public SomeThing()

    
// first our query
    
SQL_TQuery(g_hStatsDb,FIRST_SQL_QUERY_CALLBACK,sQuery,client,DBPrio_High);
}

// callback for first query
public FIRST_SQL_QUERY_CALLBACK(Handle:ownerHandle:hndl, const String:error[], any:client)
{
    
SQL_TQuery(g_hStatsDb,SECOND_SQL_QUERY_CALLBACK,query,client); // second query
}

// callback for second query
public SECOND_SQL_QUERY_CALLBACK(Handle:ownerHandle:hndl, const String:error[], any:client)
{
    
// o_o

Looks like a PHP scripter...
__________________

Last edited by neatek; 03-01-2015 at 04:20.
neatek is offline
notMe2
Member
Join Date: Feb 2014
Old 03-01-2015 , 05:08   Re: SQL_FastQuery causing rollback
Reply With Quote #10

Quote:
Originally Posted by neatek View Post
I dont know how TQuery can crash your server... but i dont recommend using OnClientPutInServer instead of OnClientPostAdminCheck.

happens... omfg. You can put second query in first callback of query!

PHP Code:
public SomeThing()

    
// first our query
    
SQL_TQuery(g_hStatsDb,FIRST_SQL_QUERY_CALLBACK,sQuery,client,DBPrio_High);
}

// callback for first query
public FIRST_SQL_QUERY_CALLBACK(Handle:ownerHandle:hndl, const String:error[], any:client)
{
    
SQL_TQuery(g_hStatsDb,SECOND_SQL_QUERY_CALLBACK,query,client); // second query
}

// callback for second query
public SECOND_SQL_QUERY_CALLBACK(Handle:ownerHandle:hndl, const String:error[], any:client)
{
    
// o_o

Looks like a PHP scripter...
yeah haha, i done that right before you post it, and it seems to not crash anymore... well, i'll update in case of new events

---

Well, when the server has 5+ players the client still crashes, even with this method

Last edited by notMe2; 03-01-2015 at 06:13.
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 23:10.


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