Mysql query function question
#1

Hello,

Well I was wondering if this is possible:

pawn Код:
mysql_function_query(connectionHandle, query, false, "SaveVehicleCallback", "dd", carid, playerid);
So I can use playerid in the function so I can for example send the playerid a message "Vehicle already exists"
(this is for saving a vehicle)

pawn Код:
command(savecar, playerid, params[])
{
    new carid = GetPlayerVehicleID(playerid);
    if(AdminLoggedIn[playerid] == 1 && Player[playerid][Adminlevel] >= 6)
    {
        if(IsPlayerInAnyVehicle(playerid))
        {
            new query[300];

            format(query, sizeof(query), "SELECT * FROM `Vehicles` WHERE `VehicleID` = %d", carid);
            mysql_function_query(connectionHandle, query, false, "SaveVehicleCallback", "dd", carid, playerid);
        }
    }
    else
    {
        TextDrawShowForPlayer(playerid, Text:CantCommand);
        SetTimerEx("RemoveCantCommand", 3500, false, "d", playerid);
    }
    return 1;
}
pawn Код:
public SaveVehicleCallback(vehicleid, playerid)
{
    new
        rows,
        fields;

    cache_get_data(rows, fields);
    if(rows == 1)
    {
        SendClientMessage(playerid, WARNRED, "This Vehicle already exists");
    }
    else if(rows == 0)
    {
        new query[300];

        format(query, sizeof(query), "INSERT INTO `Vehicles` (`ModelID`) VALUES(%d)", Vehicles[vehicleid][ModelID]);
        mysql_function_query(connectionHandle, query, false, "DefaultCallback", "");
    }
    else
    {
        SendClientMessage(playerid, COLOR_WHITE, "There was a "#COL_EMB_RED"fatal error "#COL_EMB_WHITE"during registration! Please contact a developer.");
    }
    return 1;
}
Reply
#2

Yes, it's possible, you can pass any parameter to a callback.
Reply
#3

Quote:
Originally Posted by Pooh7
Посмотреть сообщение
Yes, it's possible, you can pass any parameter to a callback.
Thanks.
Reply
#4

Just a heads up, if that query you are sending to the database is a SELECT query as it would seem to be "SELECT *" is what i can see there... I would change the caching to true as opposed to false.. If you know what I mean?
Reply
#5

Quote:
Originally Posted by LiamM
Посмотреть сообщение
Just a heads up, if that query you are sending to the database is a SELECT query as it would seem to be "SELECT *" is what i can see there... I would change the caching to true as opposed to false.. If you know what I mean?
What do you mean?
Reply
#6

Actually, what you could do is make it an INSERT query when someone executes the command. Obviously, you'll pass the playerid parameter to the thread function and then you can use mysql_affected_rows() to determine if it was able to add one or not. Example:

pawn Код:
CMD:somequery(playerid, params[])
{
    mysql_function_query(1, "INSERT INTO `values` (`1`, `2`) VALUES(93, 92)", false, "SomeFunction", "d", playerid);
    return 1;
}

public SomeFunction(playerid)
{
    if(playerid != INVALID_PLAYER_ID)
    {
        if(mysql_affected_rows() > 0)
        {
            // it worked
        }
        else
        {
            // it failed
        }
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)