Raised This Month: $ Target: $400
 0% 

MYSQL - weird bug


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Schwabba
Senior Member
Join Date: Apr 2008
Old 06-16-2011 , 07:25   MYSQL - weird bug
Reply With Quote #1

Hi, since i use MySql i have a bug on every plugin i use with MySql, i never found the problem.. till now!

The more players are on the server, the more often it happens. Currently there are 18/18 players on the server from ~12am till 1am and it happens like 2-3 times every day, so it's not much, but still annoying.

I store the money in the database and give it to them when they rejoin the server.

The database-structure looks like:

steamid - name - money - more but not important

But sometimes it happens that there are more entries for the same steamid and the money for the steamid is 0 or just the half.

Example correct:

STEAM_1:123 - Schwabba - 1000000

Examples wrong:

STEAM_1:123 - Schwabba - 500000
STEAM_1:123 - Schwabba - -500000

or:

STEAM_1:123 - Schwabba - 500000
STEAM_1:123 - Schwabba - 500000

or:

STEAM_1:123 - Schwabba - 500000
STEAM_1:123 - Schwabba - 0

or:

STEAM_1:123 - Schwabba - 0
STEAM_1:123 - Schwabba - 0

Sometimes there are 10 entries for the same player.

PHP Code:
public Load_MySql(id)
{
    if(
g_sql_ready)
    {
        if(
g_SqlTuple == Empty_Handle)
        {
            
set_fail_state(g_Error)
        }

        new 
szSteamId[32], szTemp[512]
        
get_user_authid(idszSteamIdcharsmax(szSteamId))

        new 
Data[1]
        
Data[0] = id

        format
(szTemp,charsmax(szTemp),"SELECT * FROM `furienmoney` WHERE (`furienmoney`.`steamid` = '%s')"szSteamId)
        
SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1)
    }
}

public 
register_client(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    if(
FailState == TQUERY_CONNECT_FAILED)
    {
        
log_amx("Load - Could not connect to SQL database.  [%d] %s"ErrcodeError)
    }
    else if(
FailState == TQUERY_QUERY_FAILED)
    {
        
log_amx("Load Query failed. [%d] %s"ErrcodeError)
    }
    new 
id
    id 
Data[0]
    if(
SQL_NumResults(Query) < 1// The bug have to be here
    
{
        new 
szSteamId[32], szName[32], szQuotedName[64]
        
get_user_authid(idszSteamIdcharsmax(szSteamId)) // get user's steamid
        
get_user_name(idszName31// get user's name
        
SQL_QuoteString(g_SqlConnectionszQuotedName63szName)

        
//  if its still pending we can't do anything with it
        
if (equal(szSteamId,"ID_PENDING"))
        {
            return 
PLUGIN_HANDLED
        
}
            
        new 
szTemp[512]
        new 
time get_systime()
        
// now we will insert the values into our table.
        
format(szTemp,charsmax(szTemp),"INSERT INTO `furienmoney` ( `steamid` , `name` , `money`) VALUES ('%s','%s','0');",
        
szSteamIdszQuotedNametimetime)
        
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)

        
Save_MySql(id)
    } 
    else 
    {
    
// if there are results found
        
iMoney[id]        = SQL_ReadResult(Query2)
        
iMoney2[id]        = SQL_ReadResult(Query2)
        new 
szLogname[32], szLogauth[32];
        
get_user_name(idszLognamecharsmax(szLogname));
        
get_user_authid(idszLogauthcharsmax(szLogauth));
        
log_to_file("Moneylog.txt""Loaded %i$ of %s (%s)."iMoney[id], szLognameszLogauth)
        
set_task(0.2,"give_money"id)
    }
    
g_loaded[id] = true
    
return PLUGIN_HANDLED
}

public 
Save_MySql(id)
{
    if(
g_loaded[id] && iStart[id])
    {
        new 
szSteamId[32], szTemp[512], szName[32], szQuotedName[64], money
        get_user_authid
(idszSteamIdcharsmax(szSteamId))
        
get_user_name(idszName31)
        
SQL_QuoteString(g_SqlConnectionszQuotedName63szName)
        
money iMoney[id] - iMoney2[id]
        
format(szTemp,charsmax(szTemp),"UPDATE `furienmoney` SET `name` = '%s', `money` = `money` +%i  WHERE `furienmoney`.`steamid` = '%s';",szQuotedName,money,szSteamId)
        
iMoney2[id] = iMoney[id]
        new 
szLogname[32], szLogauth[32];
        
get_user_name(idszLognamecharsmax(szLogname));
        
get_user_authid(idszLogauthcharsmax(szLogauth));
        
log_to_file("Moneylog.txt""Changed money of %s (%s) to %i$."szLognameszLogauthiMoney[id])
    }


Someone know how that happens?

Last edited by Schwabba; 06-16-2011 at 07:29.
Schwabba is offline
 



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:30.


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