SQL lite loading number 48 from nowhere
#1

Hello, I was making SQL lite admin system, then i noticed that i had somekind wierd bug that it returns me number 48 from nothing...
a bits of code:
pawn Код:
//under on filtserscript init
database = db_open("AdminSys.db");
    db_query(database, "CREATE TABLE IF NOT EXISTS `USERS` (`NAME`, `PASSWORD`, `IP`, `SCORE`, `CASH`, `ADMIN`,`VIP`)");
//registring
format(Query, sizeof(Query), "INSERT INTO `USERS` (`NAME`, `PASSWORD`, `IP`, `SCORE`, `CASH`, `ADMIN`, `VIP`) VALUES('%s','%s','%s', '%i', '%i', '0', '0')", DB_Escape(name), DB_Escape(pass), DB_Escape(ip),GetPlayerScore(playerid),GetPlayerMoney(playerid));
                    db_query(database, Query);
//loging in

pawn Код:
format(Query, sizeof(Query), "SELECT * FROM `USERS` WHERE `NAME` = '%s' COLLATE NOCASE AND `PASSWORD` = '%s'", DB_Escape(name), DB_Escape(pass));
                Result = db_query(database, Query);
                if(db_num_rows(Result))
                {
                    SendClientMessage(playerid,0xFFFFFFAA,""COL_GREEN"You are not registred, Please register! /register");
                    db_get_field_assoc(Result, "ADMIN", pInfo[playerid][pAdmin], 30);
                    db_get_field_assoc(Result, "VIP", pInfo[playerid][pVip], 30);
                    db_get_field_assoc(Result, "CASH", pInfo[playerid][pCash], 30);
                    db_get_field_assoc(Result, "SCORE", pInfo[playerid][pScore], 30);
                    pInfo[playerid][pLogged] = 1;
                    if(pInfo[playerid][pAdmin] >= 1)
                    {
                        switch(pInfo[playerid][pAdmin])
                        {
                            case 1: aRank = ARANK1;
                            case 2: aRank = ARANK2;
                            case 3: aRank = ARANK3;
                            case 4: aRank = ARANK4;
                            case 5: aRank = ARANK5;
                            case 6: aRank = ARANK6;
                            case 7: aRank = ARANK7;
                        }
                        format(string, sizeof(string), ""COL_GREEN"You have been successfully logged in, "COL_BLUE"Level: %i (Rank: %s)", pInfo[playerid][pAdmin],aRank);
                        SendClientMessage(playerid,0xFFFFFFAA,string);
                        ResetPlayerMoney(playerid);
                        GivePlayerMoney(playerid,pInfo[playerid][pCash]);
                        SetPlayerScore(playerid,pInfo[playerid][pScore]);
                        } else if(pInfo[playerid][pAdmin] == 0 && pInfo[playerid][pVip] >= 1)
                        {
                            switch(pInfo[playerid][pVip])
                            {
                                case 1: vRank = VRANK1;
                                case 2: vRank = VRANK2;
                                case 3: vRank = VRANK3;
                            }
                            format(string, sizeof(string), ""COL_GREEN"You have been successfully logged in, "COL_BLUE"Vip Level: %i (Rank: %s)", pInfo[playerid][pVip],vRank);
                            SendClientMessage(playerid,0xFFFFFFAA,string);
                            ResetPlayerMoney(playerid);
                            GivePlayerMoney(playerid,pInfo[playerid][pCash]);
                            SetPlayerScore(playerid,pInfo[playerid][pScore]);
                        } else if(pInfo[playerid][pAdmin] == 0 && pInfo[playerid][pVip] == 0)
                        {
                            format(string, sizeof(string), ""COL_GREEN"You have been successfully logged in,");
                            SendClientMessage(playerid,0xFFFFFFAA,string);
                            ResetPlayerMoney(playerid);
                            GivePlayerMoney(playerid,pInfo[playerid][pCash]);
                            SetPlayerScore(playerid,pInfo[playerid][pScore]);
                        }
//and saving on OnPlayerDisconnect
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    pInfo[playerid][pLogged] = 0;
    pInfo[playerid][pRegistred] = 0;
    new Query[ 300 ],DBResult: Result,name[ MAX_PLAYER_NAME ],ip[16];
    GetPlayerName(playerid, name, sizeof(name));
    GetPlayerIp(playerid, ip, sizeof(ip));
    format(Query, sizeof(Query), "SELECT `NAME` FROM `USERS` WHERE `NAME` = '%s' COLLATE NOCASE", DB_Escape(name));
    Result = db_query(database, Query);
    if(db_num_rows(Result))
    {
        format(Query,sizeof(Query),"UPDATE `USERS` SET SCORE = '%d', CASH = '%d', ADMIN = '%d', VIP = '%d' WHERE `NAME` = '%s' COLLATE NOCASE",GetPlayerScore(playerid),GetPlayerMoney(playerid),pInfo[playerid][pAdmin],pInfo[playerid][pVip]);
        db_query(database, Query);
    }
    return 1;
}

More info:
The issue comes when i try to login...
I haven't messed with integers but still why does it set my VIP level to 48 if i haven't even messed with it before.
I only set it to 0 before...
Thanks for help...
Reply
#2

You should know that db_get_field_assoc() returns a string, the code you have here:

pawn Код:
db_get_field_assoc(Result, "ADMIN", pInfo[playerid][pAdmin], 30);
                    db_get_field_assoc(Result, "VIP", pInfo[playerid][pVip], 30);
                    db_get_field_assoc(Result, "CASH", pInfo[playerid][pCash], 30);
                    db_get_field_assoc(Result, "SCORE", pInfo[playerid][pScore], 30);
most likely consists of integers, the best thing to do is to create a temporary string that you can use to unload your data, then use strval to convert it back in to an integer.

pawn Код:
new szUnload[30];

db_get_field_assoc(Result, "ADMIN", szUnload, sizeof(szUnload));
pInfo[playerid][pAdmin] = strval(szUnload);

db_get_field_assoc(Result, "VIP", szUnload, sizeof(szUnload));
pInfo[playerid][pVip] = strval(szUnload);

db_get_field_assoc(Result, "CASH", szUnload, sizeof(szUnload));
pInfo[playerid][pCash] = strval(szUnload);

db_get_field_assoc(Result, "SCORE", szUnload, sizeof(szUnload));
pInfo[playerid][pScore] = strval(szUnload);
This might not solve your problem - but it should make things a little more clear for you.
Reply
#3

Quote:
Originally Posted by Calgon
Посмотреть сообщение
You should know that db_get_field_assoc() returns a string, the code you have here:

pawn Код:
db_get_field_assoc(Result, "ADMIN", pInfo[playerid][pAdmin], 30);
                    db_get_field_assoc(Result, "VIP", pInfo[playerid][pVip], 30);
                    db_get_field_assoc(Result, "CASH", pInfo[playerid][pCash], 30);
                    db_get_field_assoc(Result, "SCORE", pInfo[playerid][pScore], 30);
most likely consists of integers, the best thing to do is to create a temporary string that you can use to unload your data, then use strval to convert it back in to an integer.

pawn Код:
new szUnload[30];

db_get_field_assoc(Result, "ADMIN", szUnload, sizeof(szUnload));
pInfo[playerid][pAdmin] = strval(szUnload);

db_get_field_assoc(Result, "VIP", szUnload, sizeof(szUnload));
pInfo[playerid][pVip] = strval(szUnload);

db_get_field_assoc(Result, "CASH", szUnload, sizeof(szUnload));
pInfo[playerid][pCash] = strval(szUnload);

db_get_field_assoc(Result, "SCORE", szUnload, sizeof(szUnload));
pInfo[playerid][pScore] = strval(szUnload);
This might not solve your problem - but it should make things a little more clear for you.
oh yea... thanks...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)