Problems with sqlite, integers, print and printf. - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Problems with sqlite, integers, print and printf. (
/showthread.php?tid=550119)
Problems with sqlite, integers, print and printf. -
welderlourenco - 10.12.2014
Hi all,
I have a
players table inside
sqlite with the column
id - PK NN AI.
I use
db_get_field_assoc() to get the id value using my query result variable and set it to my players variable, like so:
Код:
enum playersInfo {
pid
}
new players[MAX_PLAYERS][playersInfo];
// ...
// ...
if (db_num_rows(result) == 1) {
db_get_field_assoc(result, "id", players[playerid][pid], 11);
}
Now come the tricky part, i want to debug the value so I call:
Код:
print(players[playerid][pid]); // prints 1, that's the correct id.
printf("id: %d\n", players[playerid][pid]); // prints id: 49 ... wth???
Why in the world is the printf function returning 49?
That's more interesting, if the id in the database is 2, it returns 50 from the printf function, and if the id is 10 it returns 59, but the print function always returns the right value.
Why is that
Thanks for the help...
Re: Problems with sqlite, integers, print and printf. -
Raweresh - 10.12.2014
So, I think
players[playerid][pid] is an integer, you can use function
db_get_field_assoc to save value as string. It should look like this:
Код:
new String[/*MAXIMAL LENGTH OF QUERY*/];
db_get_field_assoc(result, "id", String, 11);
players[playerid][pid] = strval(String);
Re: Problems with sqlite, integers, print and printf. -
welderlourenco - 10.12.2014
Thanks Raweresh, that's exactly it.