[HELP] MySQL Car System
#1

Hello,
I'm making Car System from zero(include).
I have problems:

When i type /createcar, all is good but in mysql_log is : [15:49:48] [WARNING] cache_get_data - no active cache
In phpmyadmin in database make it http://i.imgur.com/6tF5dqX.png
I connect to server, cars dont load it.
When i make /createcar two time in database dont make it but in mysql_log is : [15:53:46] [ERROR] CMySQLQuery::Execute[()] - (error #1062) Duplicate entry '1' for key 'PRIMARY'

COMMAND:
Код:
CMD:createcar(playerid,params[])
{
	new Float:X,Float:Y,Float:Z;
	new carid = GetFreedID();
	if(GetPlayerVehicleID(playerid) == 0)return SendClientMessage(playerid,COLOR_GREY,"Nisi u vozilu!");
	CarInfo[carid][cModel] = GetVehicleModel(GetPlayerVehicleID(playerid));
	GetPlayerPos(playerid,X,Y,Z);
    format(cquery, sizeof(cquery), "INSERT INTO `cars` (cID, cModel, cUlazX, cUlazY, cUlazZ) VALUES ('%d', '%d', '%f', '%f', '%f')", GetFreedID(), CarInfo[carid][cModel], X,Y,Z);
    mysql_function_query(1, cquery, false, "", "");
    CarInfo[carid][cVehicle] = CreateVehicle(CarInfo[carid][cModel],X,Y,Z,0,3,3,-1);
    DestroyVehicle(GetPlayerVehicleID(playerid));
    SendClientMessage(playerid,0xFFFFA8FF,"Auto na prodaju je uspjesno napravljeno!");
	return 1;
}
SAVE/LOAD:
Код:
stock LoadCars()
{
    mysql_tquery(dbHandle, "SELECT * FROM `cars`", "OnCarsLoad", "");
}


stock OnCarsLoad()
{
    new
        rows,
        fields;

    cache_get_data(rows, fields, dbHandle); // CONNECTION

    if( rows )
    {
        new
            i = 0
        ;
        while( rows > i < MAX_CARS )
        {
            CarInfo[i][cID] = cache_get_field_content_int(0, "cID");
            CarInfo[i][cModel] = cache_get_field_content_int(0, "cModel");
            CarInfo[i][cUlazX] = cache_get_field_content_float(0, "cUlazX");
            CarInfo[i][cUlazY] = cache_get_field_content_float(0, "cUlazY");
            CarInfo[i][cUlazZ] = cache_get_field_content_float(0, "cUlazZ");
            CarInfo[i][cVehicle] = CreateVehicle(CarInfo[i][cModel],CarInfo[i][cUlazX],CarInfo[i][cUlazY],CarInfo[i][cUlazZ],0,3,3,-1);
            i++;
        }
    }
}

stock SaveCars()
{
    for(new i = 0; i < MAX_CARS; i++)
    {
		new carid;
		mysql_format(1, cquery, sizeof(cquery), "UPDATE `cars` SET `cID` = '%d', `cModel` = '%d', `cUlazX` = '%f', `cUlazY` = '%f', cUlazZ` = '%f'  WHERE `cID` = '%d' LIMIT 1", CarInfo[carid][cID],CarInfo[carid][cModel],CarInfo[carid][cUlazX],CarInfo[carid][cUlazY],CarInfo[carid][cUlazZ],i);
		mysql_function_query(1, cquery, false, "", "");
	}
}
That is include for SAVE/LOAD.

-----

This is from gamemode on "OnGameModeInit":
LoadCars();
on OnGameModeExit
SaveCars();
And dbHandle is bHandle = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_BASE, MYSQL_PASS);(in gamemode)
Reply
#2

BUMP!
Reply
#3

For the second error, your "GetFreedID()" seems to be working wrong because it return "1" twice.
Reply
#4

There is GetFreeID
Quote:

stock GetFreedID()
{
for(new i=1; i<MAX_CARS; i++)
{
format(cquery,sizeof(cquery),"SELECT * FROM cars WHERE `cID` = %d LIMIT 1",i);
mysql_function_query(dbHandle, cquery, false, "","");
mysql_store_result();
if(mysql_num_rows() == 0)
{
mysql_free_result();
return i;
}
mysql_free_result();
}
return 0;
}

Reply
#5

BUMP!
Reply
#6

Have Same Problem
Reply
#7

I just don't know why you have to INSERT the ID when creating a car, don't you have it as auto increment?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)