Need help with SQLite -
Zimon95 - 27.02.2011
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!
Re: Need help with SQLite -
JaTochNietDan - 27.02.2011
I assume the Utente[playerid][Password] variable is an array?
If you don't know what I mean, can you show the enumerator?
Re: Need help with SQLite -
Zimon95 - 27.02.2011
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...
Re: Need help with SQLite -
JaTochNietDan - 27.02.2011
Password needs to be an array, as I believe you may have said in your edit.
Problem solved then?
Re: Need help with SQLite -
Zimon95 - 27.02.2011
No... the "Livello" and "Soldi" are still 49...
Re: Need help with SQLite -
dice7 - 27.02.2011
Everything needs to be an array since db_get_field_assoc() stores the value into an array
Re: Need help with SQLite -
JaTochNietDan - 27.02.2011
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.
Re: Need help with SQLite -
Zimon95 - 27.02.2011
Aw... Is there another way to do that using my enumerator?
Thanks JaTochNietDan and dice7 for the help
Re: Need help with SQLite -
Fj0rtizFredde - 27.02.2011
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..
Re: Need help with SQLite -
Zimon95 - 27.02.2011
Thanks Fj0rtizFredde!

Thank you everyone!