get mysql variable faster
#1

I have a question.
How can I get a mysql variable from a mysql field faster?

I like to do a mysql save system, so switch to mysql and I have around 400 variables which will save & load in player's file.
my loading:

pawn Код:
...
    new Query[128];
    format( Query, sizeof( Query ), "SELECT * FROM `users` WHERE `ID` = %d",FieldID[playerid]);
    mysql_query(Query);
    mysql_store_result();
    if(mysql_num_rows() == 1)
    {
        new line[900],id,pname[MAX_PLAYER_NAME],pass[20],ip[16],money, score,kills,deaths,alevel;
        if(mysql_fetch_row(line))
        {
            sscanf(line, "p<|>dsssddddd", id,pname,pass,ip,money,score,kills,deaths,alevel); //Splits the line with sscanf
            GivePlayerCash(playerid,money);
            printf("Money: %d",money);
           
            SetPlayerScore(playerid,score);
            printf("Score: %d",score);
           
            PlayerInfo[playerid][pAdmin] = alevel;
            printf("Level: %d",alevel);
        }
}
...
but with ~400 variables it will be too long..
I use strickenkid's mysql plugin.

these things I only used to test and worked..
Reply
#2

pawn Код:
"SELECT * FROM `users` WHERE `ID` = %d"
instead...
pawn Код:
"SELECT `variable`, `string`, `float` FROM `users` WHERE `ID` = %d"
Also may I add that you should potentially look at having an index/unique field for the ID, so that searching is a lot quicker (but you probably already do).
Reply
#3

I mean loading, not reading xD
Reply
#4

Well do you have a unique field for the ID or an index?
Reply
#5

yes, and also auto_increment.
Reply
#6

Then there's not much you can do I think, sorry.
Reply
#7

sorry I don't understand.
I only like to see a better issue to load my varaiables (kills, deaths, ranks, achievements etc.) instead doing that on a big string, with sscanf etc.
Reply
#8

Try using LIMIT. It'll limit the selected rows, should make the query faster in some cases.

Код:
SELECT * FROM `users` WHERE `ID` = %d LIMIT 1;
Edit: Sorry, I didn't understand what you meant. I thought you wanted to optimize the MySQL query you had there.

There ain't any other ways than writing all the variables. Macros might make the code a bit shorter and easier to read, though.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)