MySQL Problem
#1

Hello,

When I try and type this command, the dialog shows but, when the query executes and the mysql insert id is fetched, the command won't work. For example, the command gets up to the point where it says vid = mysql_insert_id; and then nothing happens from that point on.

Here is the code:

pawn Код:
case DIALOG_PURCHASE_VEHICLE:
        {
            if(!response) return 1;

            new price = 0, vehName[40];
            for(new w = 0; w < sizeof(DealershipVehicles1); w++)
            {
                if(w == listitem)
                {
                    new temp3[2][128];
                    split(DealershipVehicles1[w], temp3, ',');
                    format(vehName, 40, "%s", temp3[0]);
                    price = strval(temp3[1]);
                }
            }

            if(accountInformation[playerid][money] < price) return SendClientMessage(playerid, COLOR_GREY, "You don't enough to do that!");

            accountInformation[playerid][money] -= price;
            accountInformation[playerid][vehOwner] = 1;

            new veh = GetVehicleModelIDFromName(vehName);

            vehCount++;
            new Float:pos[4];
            new vid;

            pos[0] = 165.0915;
            pos[1] = 1183.0984;
            pos[2] = 14.4849;
            pos[3] = 153.1898;

            new query[200];
            format(query, sizeof(query), "INSERT INTO `vehicles` (`model`, `PosX`, `PosY`, `PosZ`, `Rotation`, `owner`) VALUES('%d', '%f', '%f', '%f', '%f', '%s')", veh, pos[0], pos[1], pos[2], pos[3], PlayerName);
            mysql_query(query);

            mysql_store_result();
            vid = mysql_insert_id();
            mysql_free_result();

//          printf("Working 0.5");
            vehicleInformation[vid][vehiclePos][0] = pos[0]; // Debugged.
            vehicleInformation[vid][vehiclePos][1] = pos[1]; // Debugged.
            vehicleInformation[vid][vehiclePos][2] = pos[2]; // Debugged.
            vehicleInformation[vid][rotation] = pos[3]; // Debugged
            vehicleInformation[vid][colour][0] = -1;   // Debugged.
            vehicleInformation[vid][colour][1] = -1;  // Debugged.
            vehicleInformation[vid][model] = veh; // Debugged.
            vehicleInformation[vid][vehicleDBID] = vid; // Debugged.
            vehicleInformation[vid][vehicleID] = AddStaticVehicleEx(vehicleInformation[vid][model], pos[0], pos[1], pos[2], pos[3], -1, -1, -1);
            printf("Working 1");
            GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
            format(vehicleInformation[vid][vehicleOwner], 100, "%s", PlayerName);


            new rand = random(20);

            new randNumber[4];
            randNumber[0] = random(9);
            randNumber[1] = random(7);
            randNumber[2] = random(5);
            randNumber[3] = random(9);

            new vPlate[50];
            switch(rand) {
                case 0: format(vPlate, sizeof(vPlate), "RB%d%d SD%d%d", randNumber[0], randNumber[1], randNumber[2], randNumber[3]);
                case 1: format(vPlate, sizeof(vPlate), "NV%d%d QV%d%d", randNumber[0], randNumber[1], randNumber[2], randNumber[3]);
                case 2: format(vPlate, sizeof(vPlate), "ZG%d%d WB%d%d", randNumber[0], randNumber[1], randNumber[2], randNumber[3]);
                case 3: format(vPlate, sizeof(vPlate), "BC%d%d EN%d%d", randNumber[0], randNumber[1], randNumber[2], randNumber[3]);
                case 4: format(vPlate, sizeof(vPlate), "VT%d%d RM%d%d", randNumber[0], randNumber[1], randNumber[2], randNumber[3]);
                case 5: format(vPlate, sizeof(vPlate), "SA%d%d TQ%d%d", randNumber[0], randNumber[1], randNumber[2], randNumber[3]);
                case 6: format(vPlate, sizeof(vPlate), "LH%d%d YW%d%d", randNumber[0], randNumber[1], randNumber[2], randNumber[3]);
                case 7: format(vPlate, sizeof(vPlate), "ZK%d%d UE%d%d", randNumber[0], randNumber[1], randNumber[2], randNumber[3]);
                case 8: format(vPlate, sizeof(vPlate), "FC%d%d IR%d%d", randNumber[0], randNumber[1], randNumber[2], randNumber[3]);
                case 9: format(vPlate, sizeof(vPlate), "IB%d%d OT%d%d", randNumber[0], randNumber[1], randNumber[2], randNumber[3]);
                case 10: format(vPlate, sizeof(vPlate), "KZ%d%d PY%d%d", randNumber[0], randNumber[1], randNumber[2], randNumber[3]);
                case 11: format(vPlate, sizeof(vPlate), "WT%d%d GU%d%d", randNumber[0], randNumber[1], randNumber[2], randNumber[3]);
                case 12: format(vPlate, sizeof(vPlate), "SA%d%d HP%d%d", randNumber[0], randNumber[1], randNumber[2], randNumber[3]);
                case 13: format(vPlate, sizeof(vPlate), "JE%d%d JS%d%d", randNumber[0], randNumber[1], randNumber[2], randNumber[3]);
                case 14: format(vPlate, sizeof(vPlate), "XK%d%d KD%d%d", randNumber[0], randNumber[1], randNumber[2], randNumber[3]);
                case 15: format(vPlate, sizeof(vPlate), "LO%d%d LF%d%d", randNumber[0], randNumber[1], randNumber[2], randNumber[3]);
                case 16: format(vPlate, sizeof(vPlate), "KP%d%d ZG%d%d", randNumber[0], randNumber[1], randNumber[2], randNumber[3]);
                case 17: format(vPlate, sizeof(vPlate), "SE%d%d XH%d%d", randNumber[0], randNumber[1], randNumber[2], randNumber[3]);
                case 18: format(vPlate, sizeof(vPlate), "FW%d%d CJ%d%d", randNumber[0], randNumber[1], randNumber[2], randNumber[3]);
                case 19: format(vPlate, sizeof(vPlate), "TL%d%d VK%d%d", randNumber[0], randNumber[1], randNumber[2], randNumber[3]);
                case 20: format(vPlate, sizeof(vPlate), "KA%d%d BL%d%d", randNumber[0], randNumber[1], randNumber[2], randNumber[3]);
            }
            printf("Working 2");

            /*if(IsABicycle(vehicleInformation[vid][model]) || IsAPlane(vehicleInformation[vid][model]) || IsABoat(vehicleInformation[vid][model])) {
                //...
            }
            else
            {*/

            //format(vehicleInformation[vid][plate], 56, "%s", vPlate);
            SetVehicleNumberPlate(vehicleInformation[vid][vehicleID], vPlate);

            vehicleInformation[vid][plate] = vPlate;

            LinkVehicleToInterior(vehicleInformation[vid][vehicleID], GetPlayerInterior(playerid));
            SetVehicleVirtualWorld(vehicleInformation[vid][vehicleID], GetPlayerVirtualWorld(playerid));

            new queryEx[200];
            format(queryEx, sizeof(queryEx), "UPDATE `vehicles` SET `numberPlate` = '%s' WHERE `id` = '%d'", vehicleInformation[vid][plate], vehicleInformation[vid][vehicleID]);
            mysql_query(queryEx);

            SendClientMessage(playerid, COLOR_GREY, "Congratulations, you have successfully purchased a vehicle. It has been parked outside the dealership for you!");
            SendClientMessage(playerid, COLOR_BRIGHTRED, "Make sure you /park it in an apropriate area or an administrator will remove it from the database & server.");
        }
Reply
#2

There is no result when performing an insert query. There is nothing to store and nothing to free.
Reply
#3

So how do I fix it?
Reply
#4

print the mysql_insert_id();
There is possible you have OOB with vehicleInformation[vid]
And remove store and free result, like vince said. nothing to store or free.
Reply
#5

Quote:
Originally Posted by Richie©
Посмотреть сообщение
print the mysql_insert_id();
There is possible you have OOB with vehicleInformation[vid]
And remove store and free result, like vince said. nothing to store or free.
I see, can you tell me how you would effectively right that code?
Reply
#6

To avoid OOB in this case, you can do this;
Assuming that is vehicleInformation[MAX_VEHICLES]....
pawn Код:
if(vid > MAX_VEHICLES) return SendClientMessage(playerid, -1, "[WARNING!] mysql_insert_id returned a value higher then MAX_VEHICLES.");
If you are using auto increment in tables and its not giving right ID, you should;
ALTER TABLE `MyTable` AUTO_INCREMENT = 1, it will reset it.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)