mercredi 20 juillet 2016

Looping issue for MYSQL

Let's block ads! (Why?)



Looping issue for MYSQL

Gangsta

 
Shockey HD's Avatar
 

Join Date: Jul 2011

Posts: 682

Reputation: 14

DefaultLooping issue for MYSQL

Hey all,

I'm creating a house system and for some reason when I first /createhouse when server starts it'll attempt to use the ID of the last house created therefore it throws a error in MYSQL. On the second attempt, it gets the correct "new" id.

Code:

[21:05:42] CMySQLHandler::Query(INSERT INTO houses (HouseID, Owner, PosX, PosY,PosZ,Interior,VirtualWorld) VALUES(4,'Shockey_HD', 3.959691, -718.891052, 6.190841,0,0)) - An error has occured. (Error ID: 1062, Duplicate entry '4' for key 'PRIMARY')

[21:05:47] >> mysql_query( Connection handle: 1 )

[21:05:47] CMySQLHandler::Query(INSERT INTO houses (HouseID, Owner, PosX, PosY,PosZ,Interior,VirtualWorld) VALUES(5,'Shockey_HD', 3.120903, -716.215087, 6.090567,0,0)) - Successfully executed.

Here is my CreateHouse command:

Code:

CMD:createhouse(playerid,params[])
{
        new ID,String[128], Query[258],hInterior,Float:myPos[3];
        if(sscanf(params,"ud",ID,hInterior)) return SendClientMessage(playerid, COLOR_GREY,"Syntax: /createhouse [Owner ID] [Interior]");
        {
                for(new i = 1; i < MAX_HOUSES; i++)
                {
                    SendClientMessage(playerid, -1, "testing");
                        if(hData[i][Spawned] == 0)
                        {
                                
                        GetPlayerPos(playerid,myPos[0],myPos[1],myPos[2]);
                        hData[i][Spawned] = 1;
                        hData[i][LocX] = myPos[0];
                        hData[i][LocY] = myPos[1];
                        hData[i][LocZ] = myPos[2];
                        format(hData[i][Owner],32,"%s",GetName(ID));
                        format(String, sizeof(String), "This house is owned by %s\nID: %d", hData[i][Owner],i);
                                hData[i][hTextID] = Create3DTextLabel(String, COLOR_GREEN, hData[i][LocX],hData[i][LocY],hData[i][LocZ]+0.5,10.0, 0,1);
                                hData[i][hPickupID] = CreatePickup(1273,1,hData[i][LocX],hData[i][LocY],hData[i][LocZ],0);
                                hData[i][Spawned] = 1;

                                format(Query, sizeof(Query), "INSERT INTO houses (HouseID, Owner, PosX, PosY,PosZ,Interior,VirtualWorld) VALUES(%d,'%s', %f, %f, %f,%d,%d)", i,GetName(ID),myPos[0],myPos[1],myPos[2],GetPlayerInterior(playerid),GetPlayerVirtualWorld(playerid));
                                mysql_query(Query);
                                
                                break;
                        }
                }
        }
        return 1;
}
__________________

Aucun commentaire:

Enregistrer un commentaire