MySQL R7 loading problem
#1

Well as you guys know, we have to convert all our queries if we want to use the R7 version of Blue-G's MySQL plugin. Well I have 350 queries, converted them all and tested them and found out that nothing loads. The houses, businesses, icons, vehicles...etc...nothing. Here's an example of how I went about loading:

My "Load" function should load the "Name" from the database into the "name" variable, but it didn't. The way I did this was to check if the job exists and if it does, I assign a value of "1" into the "exist[1]" array so I can continue loading but apparently the script forgets the value of the "exist[1]" array.

pawn Код:
stock Load()
{
    new name[24];
    mysql_function_query(1,"SELECT `Name` FROM `jobs` WHERE `ID` = 1",true,"Loading","i",1);
    if(exist[1] == 1)
    {
        print("Loaded");
        cache_get_field_content(0,"Name",name);
    }
}
pawn Код:
forward Loading(id);
public Loading(id)
{
    cache_get_data(rows,fields);
    if(rows)
    {
        exist[1] = 1;
        print("Exists.");
    }
    else
    {
        exist[1] = 0;
        print("Doesn't exist.");
    }
    return 1;
}
What am I doing wrong?
The information above is not used in the actual gamemode.
Reply
#2

remove

if(exist[1] == 1)
{
print("Loaded");
cache_get_field_content(0,"Name",name);
}


pawn Код:
stock Load()
{
    new name[24];
    mysql_function_query(1,"SELECT `Name` FROM `jobs` WHERE `ID` = 1",true,"Loading","i",1);
}

forward Loading(id);
public Loading(id)
{
    cache_get_data(rows,fields);
    if(rows)
    {
        cache_get_field_content(0,"Name",name);
//continue code here, just transfer all variables with the function.. thats why it was made
    }
    return 1;
}
Reply
#3

I understand that, but is there a workaround? Because I have many other checks in my gamemode that checks whether things exists or not. Example: when I need to create a job, I need to check if the ID is already used (therefore if it exists) when I need to set the checkpoint, I need to check if it exists...and so on.
Reply
#4

Of course there's a workaround for this. Functions like this:
pawn Код:
stock DoesSomethingExist()
{
    mysql_query("SELECT NULL FROM table WHERE field = value");
    mysql_store_result();
    new rows = mysql_num_rows();
    mysql_free_result();
    return rows != 0 ? true : false;
}
... are no longer effective. You need to be more clever than that.

So whereever you call the function Load(), you can be smarter, and do the checking right away. When the query is finished, you can continue. For example, check if a name is registered before registering it.
pawn Код:
// lets say this is CMD:register
GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
format(query, sizeof(query), "SELECT NULL FROM players WHERE name = '%s'", PlayerName);
mysql_function_query(1, query, true, "OnUserCheckFinish", "i", playerid);

// OnUserCheckFinish
forward OnUserCheckFinish(playerid);
public OnUserCheckFinish(playerid)
{
    cache_get_data(rows, fields);
    if(rows == 1)
    {
        // Account already exists!
    }
    else
    {
        // No account!
    }
}
As you can see, this eliminates the need for a dull IsPlayerNameInUse which would use a similar format as the first code above.
Reply
#5

I understand that all but I don't think you see where am going with this...I sent you a PM.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)