MySQL loading bug?
#1

hey guys, i'm getting a weird problem with mysql, wich i never had before...

When loading a string, it loads cutted '-'

pawn Код:
cache_get_field_content(0,"owner",HouseOwner[houseid],MySQL_Connected);
        printf("House %d owner: %s",houseid,HouseOwner[houseid]);
// prints

//House 0 owner: Esta
Owner in mysql is "Estado" not "Esta"...

pawn Код:
new HouseOwner[MAX_HOUSES][24];
the size of HouseOwner is right, so i can't see a problem anywhere...
Reply
#2

Are you sure it actually saves the full name in the database? Check it manually.
Reply
#3

i'm sure it's right. Added and checked it manually.
Reply
#4

Someone? ;(
Reply
#5

Welp, you have to provide one more argument because default sizeof returns wrong value.

pawn Код:
native cache_get_field_content(row, const field_name[], destination[], connectionHandle = 1, max_len=sizeof(destination));
pawn Код:
cache_get_field_content(0,"owner",HouseOwner[houseid],MySQL_Connected);
//changes into
cache_get_field_content(0,"owner",HouseOwner[houseid],MySQL_Connected, 24);
Reply
#6

All my others cache_get_field_content doesn't have defined size and works perfect...

I'll give it a try anyway...
Reply
#7

If you're storing the string into an array, it won't load it properly. The reason for this is because the "sizeof" operator will get the size of the array, and not the string you're trying to store it in. So, for example, if the size of your array is 3, then it'll load 3 characters and nothing more.

Doing this:

pawn Код:
enum enumPlayerInfo
{
   pID,
   pPassword[129]
};

new
   pStats[MAX_PLAYERS][enumPlayerInfo];

cache_get_row(row, field, pStats[playerid][pPassword]);
Is not the same as doing this:

pawn Код:
new
   szPassword[129];
cache_get_row(row, field, szPassword);
In the first example, it will only load two characters of the user's password because the array is the size of the enum (i.e. 2). In the second example, though, it'll figure out that the size of the string "szPassword" is 129 and it can load the entire password.

A workaround is to either add a large string size at the end of your cache_get_X(..) lines, or to modify the a_mysql.inc file. I would choose the first option, though. The second might screw things up.
Reply
#8

Thanks, you guys are awesome :P
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)