MySQL / Enumerator issue
#1

Hey, so I have been dealing with this issue for a pretty long time.
So basically, after restarting the server, infos do save in the MySQL Database but not on the enumerator. Here's an example:

My /stats looks like this before restarting:


And here's how it looks after restarting:


pawn Code:
format(string, sizeof(string), "{FFFFFF}Clan: {FF0000}[%s] - {FFFFFF}Clan Rank: {FF0000}[%d]", ClanInfo[PlayerInfo[giveplayerid][user_clan]][ClanName]
pawn Code:
format(ClanInfo[clanid][ClanName], 32, "%s", clanname);
^^ I call this when the clan gets created.

Here's how I save my data:

pawn Code:
SaveClan(clanid)
{
    new query[200];
    mysql_format(Database, query, sizeof(query), "UPDATE `clans` SET `ClanName` = '%e', `ClanLeader` = '%e', `ClanColor` = '%i', `ColorSet` = '%i', `ClanKills` = '%i', `ClanDeaths` = '%i', `ClanOfficial` = '%i' WHERE `ClanID` = '%i'",
    ClanInfo[clanid][ClanName], ClanInfo[clanid][ClanLeader], ClanInfo[clanid][ClanColor], ClanInfo[clanid][ColorSet], ClanInfo[clanid][ClanKills], ClanInfo[clanid][ClanDeaths], ClanInfo[clanid][ClanOfficial], clanid);
    mysql_query(Database, query);
    return 1;
}
And the enumerator:

pawn Code:
enum ClanData
{
    ClanID,
    ClanName[32],
    ClanLeader[24],
    ClanColor,
    ColorSet,
    ClanKills,
    ClanDeaths,
    ClanOfficial
};
new ClanInfo[MAX_CLANS][ClanData];
Loading clans:

pawn Code:
forward LoadClans();
public LoadClans()
{
    new query[150];

    mysql_format(Database, query, sizeof(query), "SELECT * FROM `clans`");
    mysql_tquery(Database, query, "OnClansLoad");
    return 1;
}

forward OnClansLoad();
public OnClansLoad()
{
    if(cache_num_rows())
    {
        for(new i = 0; i < cache_num_rows(); i ++)
        {
            cache_get_value_name_int(i, "ClanID", ClanInfo[i][ClanID]);
            cache_get_value_name(i, "ClanName", ClanInfo[i][ClanName]);
            cache_get_value_name(i, "ClanLeader", ClanInfo[i][ClanLeader]);
            cache_get_value_name_int(i, "ClanColor", ClanInfo[i][ClanColor]);
            cache_get_value_name_int(i, "ColorSet", ClanInfo[i][ColorSet]);
            cache_get_value_name_int(i, "ClanKills", ClanInfo[i][ClanKills]);
            cache_get_value_name_int(i, "ClanDeaths", ClanInfo[i][ClanDeaths]);
            cache_get_value_name_int(i, "ClanOfficial", ClanInfo[i][ClanOfficial]);
        }
        printf("[SERVER]: %d clans were loaded from the MySQL Database.", cache_num_rows());
    }
    else printf("[SERVER]: No clans were loaded from the MySQL Database.");
}
Under OnGameModeInit:

pawn Code:
LoadClans();
OnGameModeExit

pawn Code:
for (new i = 0; i < MAX_CLANS; i ++)
{
     SaveClan(i);
}
Still can't seem to fix it, some help would be really appreciated!
Reply
#2

Are you saving:
pawn Code:
PlayerInfo[giveplayerid][user_clan]
Debug your code and print the value of it before then after the load.
Reply
#3

Quote:
Originally Posted by TheToretto
View Post
Are you saving:
pawn Code:
PlayerInfo[giveplayerid][user_clan]
Debug your code and print the value of it before then after the load.
Yeah, I am. I already tried that and it worked. It came up as 16 which is the actual ClanID.
Reply
#4

Often problems can be solved by re-writing your code.

This code is cleanly rewritten and doesn't fetch the row count over and over for looping. The query buffer length is 30 characters max, but you used 150. Although, the problem is not visible in the code you've presented, but why save everything when it is most probably not changed? Just save the data when it's changed, like if an admin (or clan leader) renames, then it saves the clan name only and doesn't otherwise.

PHP Code:
#define MAX_CLAN_NAME_LEN    (32)

forward LoadClans();
public 
LoadClans() {

    new
        
query[45];

    
mysql_format(Databasequerysizeof query"SELECT * FROM `clans` LIMIT %i"MAX_CLANS);
    
mysql_tquery(Databasequery"OnClansLoad");
    return 
1;
}

forward OnClansLoad();
public 
OnClansLoad() {

    new
        
rows;

    
cache_get_row_count(rows);

    if(!
rows)
        
printf("[SERVER]: No clans were loaded from the MySQL Database.");

    for(new 
0!= rows++) {

        
cache_get_value_name_int(i"ClanID"ClanInfo[i][ClanID]);
        
cache_get_value_name(i"ClanName"ClanInfo[i][ClanName]);
        
cache_get_value_name(i"ClanLeader"ClanInfo[i][ClanLeader]);
        
cache_get_value_name_int(i"ClanColor"ClanInfo[i][ClanColor]);
        
cache_get_value_name_int(i"ColorSet"ClanInfo[i][ColorSet]);
        
cache_get_value_name_int(i"ClanKills"ClanInfo[i][ClanKills]);
        
cache_get_value_name_int(i"ClanDeaths"ClanInfo[i][ClanDeaths]);
        
cache_get_value_name_int(i"ClanOfficial"ClanInfo[i][ClanOfficial]);
    }
    
    
printf("[SERVER]: %d clans were loaded from the MySQL Database."rows);

Reply
#5

cache_get_field_content(i, "ClanName", ClanInfo[i][ClanName], Database, 130);
Reply
#6

Quote:
Originally Posted by rockys
View Post
cache_get_field_content(i, "ClanName", ClanInfo[i][ClanName], Database, 130);
No idea why you're posting that, that's an old native from one of the old MySQL versions.

@Logic those are just comments that doesn't help, but he is actually looping through the rows, and your code is pretty much the same, except the fact that you created a variable that stores the count of rows.


@willbedie All I can ask you to do is debug, as the loading/saving are both done correctly, check if the variables you're trying to access are those on which you loaded earlier the values, can you also check the mysql errors logs also? Because one column not created in the database could fuck the whole thing.
Reply
#7

Quote:
Originally Posted by TheToretto
View Post
No idea why you're posting that, that's an old native from one of the old MySQL versions.

@Logic those are just comments that doesn't help, but he is actually looping through the rows, and your code is pretty much the same, except the fact that you created a variable that stores the count of rows.


@willbedie All I can ask you to do is debug, as the loading/saving are both done correctly, check if the variables you're trying to access are those on which you loaded earlier the values, can you also check the mysql errors logs also? Because one column not created in the database could fuck the whole thing.
mysql logs and every other log are empty and have nothing to do with this. I just noticed everything having to do with MySQL works, it's the enumerators who don't return the correct values/strings, and I'm pretty sure it's them who are not saving after the restart.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)