Help about mysql
#1

Hi im trying to create object like this with a command, but getting an error:

Creating the object:
pawn Код:
CMD:createobject(playerid, params[])
{
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
    if(!IsABuilder(playerid) && PlayerInfo[playerid][pAdmin] < 3) return SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use this command.");
    new model,Float:x,Float:y,Float:z;
    GetPlayerPos(playerid,x,y,z);
    if(sscanf(params, "i", model)) return SendClientMessage(playerid, COLOR_LIGHTBLUE, "Usage: /createobject [model ID]");
    format(dquery, sizeof(dquery), "INSERT INTO objects (ModelID, oX, oY, oZ, roX, roY, roZ) VALUES (%d, %f, %f, %f, %f, %f, %f)", model, x+2, y, z, 0, 0, 0); // ModelID
    mysql_query(dquery,0,0,1);
    mysql_function_query(1, "SELECT MAX(ScriptID) FROM objects", true, "LoadSingleObject", "iiffffffi", playerid, sizeof(object),x +2,y,z,0,0,0,model);
    return 1;
}
Loading the actual object:
pawn Код:
forward LoadSingleObject(playerid, limit,Float:x, Float:y, Float:z, Float:rox, Float:roy, Float:roz,modelid);
public LoadSingleObject(playerid, limit,Float:x, Float:y, Float:z, Float:rox, Float:roy, Float:roz, modelid)
{
    new rows, fields, data[50], string[128];
    cache_get_data(rows, fields);
    for(new i; i < rows; i++)
    {
        for(new h; h <sizeof(object); h++)
        {
            if(object[h][oScriptID] == 0)
            {
                cache_get_field_content(i, "MAX(ScriptID)", data); object[h][oScriptID] = strval(data);
                object[h][oModelID] = modelid;
                object[h][oX] = x;
                object[h][oY] = y;
                object[h][oZ] = z;
                object[h][roX] = rox;
                object[h][roY] = roy;
                object[h][roZ] = roz;
                object[h][oObjectID] = CreateDynamicObject(object[h][oModelID], object[h][oX], object[h][oY], object[h][oZ], object[h][roX], object[h][roY], object[h][roZ]);
                format(dstring, sizeof(dstring), "Object ID %d created. Objects Memory slot: %d",object[h][oScriptID],h);
                SendClientMessage(playerid, COLOR_LIGHTBLUE, dstring);
                format(dquery, sizeof(dquery), "UPDATE objects SET ObjectID = %d WHERE ScriptID = %d",object[h][oObjectID],object[h][oScriptID]);
                mysql_query(dquery,0,0,1);
                format(string, sizeof(string), "BuilderWarn: %s has created object ID %d. (Object: %d)", RPN(playerid), object[h][oScriptID], object[h][oObjectID]);
                SendBuilderMessage(COLOR_GREEN, string);
                break;
            }
        }
    }
    return 1;
}
Error Log:
pawn Код:
1364 Field 'ObjectID' doesn't have a default value OnQueryFinish INSERT INTO objects (ModelID, oX, oY, oZ, roX, roY, roZ) VALUES (1256, 1734.731567, -1860.233642, 13.578986, 0.000000, 0.000000, 0.000000) 1
I don't understand why its printing an error about ObjectID when its clearly being used in LoadSingleObject function.. What should i do to fix this problem?
Reply
#2

Go to phpmyadmin
Click on database name that you are using on left side of screen
Then click on SQL tab
Then paste these queires in text box
PHP код:
ALTER TABLE `objectsDROP COLUMN `ObjectID`;
ALTER TABLE `objectsADD `ObjectIDINT PRIMARY KEY AUTO_INCREMENT
Then hit 'GO'
Then a box will appear saying something like 'Are you sure you want.....' Click Yes on that

Here is a pic of it -
--
Reply
#3

Quote:
Originally Posted by BroZeus
Посмотреть сообщение
Go to phpmyadmin
Click on database name that you are using on left side of screen
Then click on SQL tab
Then paste these queires in text box
PHP код:
ALTER TABLE `objectsDROP COLUMN `ObjectID`;
ALTER TABLE `objectsADD `ObjectIDINT PRIMARY KEY AUTO_INCREMENT
Then hit 'GO'
Then a box will appear saying something like 'Are you sure you want.....' Click Yes on that

Here is a pic of it -
--
I have already key, which is `ScriptID`. I can't have 2 primary keys.
I tried to use the ObjectID as the primary key and then this error showed up once again instead of erroring `ObjectID` there was: " `ScriptID` doesn't have a default value OnQueryFinish "
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)