Problems with sqlite, integers, print and printf.
#1

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...
Reply
#2

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);
Reply
#3

Thanks Raweresh, that's exactly it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)