Need help with SQLite
#1

Ok, I'm making a GM but when I load data I got something strange...
Here's my code:
pawn Код:
if(dialogid == LOG_DIALOG)
    {
        if(response)
        {
            format(Query, sizeof(Query), "SELECT * FROM `Utenti` WHERE `Nome` = '%s' AND `Password` = '%s'", Nome(playerid), inputtext);
            result = db_query(database, Query);
            if(db_num_rows(result) != 0) //Password corretta
            {
                db_get_field_assoc(result, "Password", Utente[playerid][Password], 16);
                db_get_field_assoc(result, "Livello", Utente[playerid][Livello], 6);
                db_get_field_assoc(result, "Soldi", Utente[playerid][Soldi], 16);
                db_get_field_assoc(result, "Banca", Utente[playerid][Banca], 16);
                db_get_field_assoc(result, "Skin", Utente[playerid][Skin], 6);
                db_get_field_assoc(result, "Bannato", Utente[playerid][Bannato], 3);
                db_free_result(result);
                SendClientMessage(playerid, 0x0000D9AA, "Hai eseguito l'accesso!");
                Loggato[playerid] = true;
                SpawnPlayer(playerid);
            }
//etc...
Now, I made a command to check my data values:
pawn Код:
CMD:mystats(playerid, params[])
{
    #pragma unused params
    new tmpstr[100];
    format(tmpstr,sizeof(tmpstr), "Pass: %s | Livello: %d | Soldi: %d", Utente[playerid][Password], Utente[playerid][Livello], Utente[playerid][Soldi]);
    SendClientMessage(playerid, 0xF60000AA, tmpstr);
    return 1;
}
In my database the values are correct, but when I type the command I get this results:
Код:
Pass: o1100 | Livello: 49 | Soldi: 49
The database values are the follows:
Код:
Pass: ok | Livello: 1 | Soldi: 100
Help me please!
Reply
#2

I assume the Utente[playerid][Password] variable is an array?

If you don't know what I mean, can you show the enumerator?
Reply
#3

Here it's my enumerator:
pawn Код:
enum pInfo
{
    Password,
    Livello,
    Soldi,
    Banca,
    Skin,
    Bannato
}
new Utente[MAX_PLAYERS][pInfo];
EDIT: ouch, I forgot to put the size of the array ._.
EDIT2: ok, now my password is correct, but the "Livello" and "Soldi" are still 49...
Reply
#4

Password needs to be an array, as I believe you may have said in your edit.

Problem solved then?
Reply
#5

No... the "Livello" and "Soldi" are still 49...
Reply
#6

Everything needs to be an array since db_get_field_assoc() stores the value into an array
Reply
#7

Sorry didn't notice that, but as dice7 says they need to be an array, you can then convert them to an integer using a function like strval if required.
Reply
#8

Aw... Is there another way to do that using my enumerator?

Thanks JaTochNietDan and dice7 for the help
Reply
#9

You could do something like this: (Like I did on my GPS system )
pawn Код:
new Value[128];
db_get_field_assoc(result, "Livello", Value, 6);
Utente[playerid][Livello] = strval(Value);
//Next one goes here and so on..
Reply
#10

Thanks Fj0rtizFredde!
Thank you everyone!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)