SA-MP Forums Archive
SELECT MYSQL. [+REP] - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: SELECT MYSQL. [+REP] (/showthread.php?tid=598510)



SELECT MYSQL. [+REP] - norton2 - 13.01.2016

Sometimes not selects data from the database MYSQL!

After LOGIN:
Код HTML:
mysql_format(MySQLCon, QuerY, sizeof(QuerY), "SELECT * FROM `vehicles` WHERE `OwnerID` = %d", pInfo[playerid][pID]); 
mysql_pquery(MySQLCon, QuerY, "OnVehiclesLoad", "d", playerid);
OnVehiclesLoad:
Код HTML:
forward OnVehiclesLoad(playerid);
public OnVehiclesLoad(playerid)
{
    for(new r = 0, vd; r < cache_num_rows(); ++r)
    {
        vd = CreateVehicle(400, -3909.9297, 3914.0884, -0.8315, 50.5536, -1, -1, -1), DestroyVehicle(vd);
        new ORM:ormid = Veh[vd][ORM_ID] = orm_create("vehicles", MySQLCon);
        orm_addvar_int(ormid, Veh[vd][ID], "ID"); //this is the key
        orm_addvar_int(ormid, Veh[vd][Owner], "Owner");
        orm_addvar_int(ormid, Veh[vd][Model], "Model");
        orm_addvar_float(ormid, Veh[vd][PosX], "PosX");
        orm_addvar_float(ormid, Veh[vd][PosY], "PosY");
        orm_addvar_float(ormid, Veh[vd][PosZ], "PosZ");
        orm_addvar_float(ormid, Veh[vd][VAngle], "VAngle");
        orm_addvar_int(ormid, Veh[vd][Color1], "Color1");
        orm_addvar_int(ormid, Veh[vd][Color2], "Color2");
        orm_addvar_int(ormid, Veh[vd][Paintjob], "Paintjob");
        orm_addvar_int(ormid, Veh[vd][Value], "Value");
        orm_addvar_int(ormid, Veh[vd][Lock], "Lock");
        orm_addvar_string(ormid, Veh[vd][Plate], 16, "Plate");
        orm_addvar_float(ormid, Veh[vd][KM], "KM");
        orm_addvar_int(ormid, Veh[vd][Mod][0], "Mod0");
        orm_addvar_int(ormid, Veh[vd][Mod][1], "Mod1");
        orm_addvar_int(ormid, Veh[vd][Mod][2], "Mod2");
        orm_addvar_int(ormid, Veh[vd][Mod][3], "Mod3");
        orm_addvar_int(ormid, Veh[vd][Mod][4], "Mod4");
        orm_addvar_int(ormid, Veh[vd][Mod][5], "Mod5");
        orm_addvar_int(ormid, Veh[vd][Mod][6], "Mod6");
        orm_addvar_int(ormid, Veh[vd][Mod][7], "Mod7");
        orm_addvar_int(ormid, Veh[vd][Mod][8], "Mod8");
        orm_addvar_int(ormid, Veh[vd][Mod][9], "Mod9");
        orm_addvar_int(ormid, Veh[vd][Mod][10], "Mod10");
        orm_addvar_int(ormid, Veh[vd][Mod][11], "Mod11");
        orm_addvar_int(ormid, Veh[vd][Mod][12], "Mod12");
        orm_addvar_int(ormid, Veh[vd][Mod][13], "Mod13");
        orm_addvar_string(ormid, Veh[vd][Class], 13, "Class");
        orm_apply_cache(ormid, r);
        orm_setkey(ormid, "ID"); //here we declare it as the key
        Veh[vd][ServerID] = CreateVehicle(Veh[vd][Model], Veh[vd][PosX], Veh[vd][PosY], Veh[vd][PosZ], Veh[vd][VAngle], Veh[vd][Color1], Veh[vd][Color2], -1),
        VBreak[Veh[vd][ServerID]] = 1, KMVeh[Veh[vd][ServerID]] = Veh[vd][KM], SetVehicleNumberPlate(Veh[vd][ServerID], Veh[vd][Plate]);
    }
    return 1;
}
DEBUG:
Код HTML:
[20:46:35] [debug] Run time error 4: "Array index out of bounds"
[20:46:35] [debug]  Accessing element at index 65535 past array upper bound 1999
[20:46:35] [debug] AMX backtrace:
[20:46:35] [debug] #0 0005f3ec in public OnVehiclesLoad (playerid=4) at C:\Users\HP-PavilionG6\Desktop\GameMode Server\gamemodes\GM.pwn:2579
// Do not select the correct model, and this error occurs.
MYSQL LOG:
Код HTML:
StartCB("OnVehiclesLoad");Log("20:46:35","CMySQLResult::GetRowDataByName",2,"field not found (\"Owner\")",0);
Log("20:46:35","CMySQLResult::GetRowDataByName",2,"field not found (\"Model\")",0);
Log("20:46:35","CMySQLResult::GetRowDataByName",2,"field not found (\"PosX\")",0);
Log("20:46:35","CMySQLResult::GetRowDataByName",2,"field not found (\"PosY\")",0);
Log("20:46:35","CMySQLResult::GetRowDataByName",2,"field not found (\"PosZ\")",0);
Log("20:46:35","CMySQLResult::GetRowDataByName",2,"field not found (\"VAngle\")",0);
Log("20:46:35","CMySQLResult::GetRowDataByName",2,"field not found (\"Color1\")",0);
Log("20:46:35","CMySQLResult::GetRowDataByName",2,"field not found (\"Color2\")",0);
Log("20:46:35","CMySQLResult::GetRowDataByName",2,"field not found (\"Paintjob\")",0);
Log("20:46:35","CMySQLResult::GetRowDataByName",2,"field not found (\"Value\")",0);
Log("20:46:35","CMySQLResult::GetRowDataByName",2,"field not found (\"Lock\")",0);
Log("20:46:35","CMySQLResult::GetRowDataByName",2,"field not found (\"Plate\")",0);
Log("20:46:35","CMySQLResult::GetRowDataByName",2,"field not found (\"KM\")",0);
Log("20:46:35","CMySQLResult::GetRowDataByName",2,"field not found (\"Mod0\")",0);
Log("20:46:35","CMySQLResult::GetRowDataByName",2,"field not found (\"Mod1\")",0);
Log("20:46:35","CMySQLResult::GetRowDataByName",2,"field not found (\"Mod2\")",0);
Log("20:46:35","CMySQLResult::GetRowDataByName",2,"field not found (\"Mod3\")",0);
Log("20:46:35","CMySQLResult::GetRowDataByName",2,"field not found (\"Mod4\")",0);
Log("20:46:35","CMySQLResult::GetRowDataByName",2,"field not found (\"Mod5\")",0);
Log("20:46:35","CMySQLResult::GetRowDataByName",2,"field not found (\"Mod6\")",0);
Log("20:46:35","CMySQLResult::GetRowDataByName",2,"field not found (\"Mod7\")",0);
Log("20:46:35","CMySQLResult::GetRowDataByName",2,"field not found (\"Mod8\")",0);
Log("20:46:35","CMySQLResult::GetRowDataByName",2,"field not found (\"Mod9\")",0);
Log("20:46:35","CMySQLResult::GetRowDataByName",2,"field not found (\"Mod10\")",0);
Log("20:46:35","CMySQLResult::GetRowDataByName",2,"field not found (\"Mod11\")",0);
Log("20:46:35","CMySQLResult::GetRowDataByName",2,"field not found (\"Mod12\")",0);
Log("20:46:35","CMySQLResult::GetRowDataByName",2,"field not found (\"Mod13\")",0);
Log("20:46:35","CMySQLResult::GetRowDataByName",2,"field not found (\"Class\")",0);
Log("20:46:35","CMySQLResult::GetRowDataByName",2,"field not found (\"ID\")",0);



Re: SELECT MYSQL. [+REP] - valych - 13.01.2016

According to your mysql log, there are no such fields in your table like Owner, Model, PosX, PosY, PosZ and so on. Then, due to some reason, fuction CreateVehicle in this line:
PHP код:
CreateVehicle(400, -3909.92973914.0884, -0.831550.5536, -1, -1, -1), //.... 
returns INVALID_VEHICLE_ID (65535) which causes your runtime error. Wiki says that INVALID_VEHICLE_ID is returned when wrong model id is passed to the function or when amount of created vehicles exceeds the limit (2000 for now).
To solve the first problem, I guess you should create those fields, for the second one: do something with amount of created vehicles OR amount of rows in your mysql table.


Re: SELECT MYSQL. [+REP] - norton2 - 14.01.2016

Quote:
Originally Posted by valych
Посмотреть сообщение
According to your mysql log, there are no such fields in your table like Owner, Model, PosX, PosY, PosZ and so on. Then, due to some reason, fuction CreateVehicle in this line:
PHP код:
CreateVehicle(400, -3909.92973914.0884, -0.831550.5536, -1, -1, -1), //.... 
returns INVALID_VEHICLE_ID (65535) which causes your runtime error. Wiki says that INVALID_VEHICLE_ID is returned when wrong model id is passed to the function or when amount of created vehicles exceeds the limit (2000 for now).
To solve the first problem, I guess you should create those fields, for the second one: do something with amount of created vehicles OR amount of rows in your mysql table.
Okay, thank you. +1.