sql error PRIMARY KEY must be unique
#5

i get this error after adding your code and it saves nothing not even the first car

Код:
[Warning] db_query: Query failed: 10 values for 9 columns
This was my code before:
Код:
CMD:aveh(playerid, params[])
{
    new model,color,color2,Float:cPos[4], price;
    if(sscanf(params, "iiii", model, price, color,color2)) return SendClientMessage(playerid, -1, "/aveh [model] [price] [color] [color]");
    if(model < 400 || model > 611) return SendClientMessage(playerid,-1, "vehicle IDs between 400 - 611!");
    if(color> 255 || color< 0) return SendClientMessage(playerid, 0xFFFFFF, "Car color ID's: 0-255");
    if(color2> 255 || color2< 0) return SendClientMessage(playerid, 0xFFFFFF, "Car color ID's: 0-255");
    GetPlayerPos(playerid, cPos[0], cPos[1], cPos[2]);
    GetPlayerFacingAngle(playerid, cPos[3]);
    CreateVehicle(model, cPos[0], cPos[1]-3, cPos[2], cPos[3], color, color2, -1);
	LoadedVehicles ++;

	new DBResult: Result;

	Result = db_query(VehicleDB, "SELECT last_insert_rowid()"); // it will return the value for field "userid" generated
	VehicleInfo[LoadedVehicles][vID] = db_get_field_int(Result);
	db_free_result(Result);

	new Query[208];
	format(Query, sizeof Query, "INSERT INTO vehicles (id, owner, ownerid, price, forsale, model, posx, posy, posz, posa) VALUES (%d, '%s', '%d', '%d', '%d', '%d','%f', '%f', '%f', '%f')", VehicleInfo[LoadedVehicles][vID], "NONE", -1, price, 1, model, cPos[0], cPos[1], cPos[2], cPos[3]);
	db_query(VehicleDB, Query);

    return 1;
}

stock LoadVehicles()
{
	new DBResult: Result, id, buf[255];

	format(buf, sizeof buf, "SELECT * FROM vehicles");
	Result = db_query(VehicleDB, buf);

	if (db_num_rows(Result))
	{
		id = LoadedVehicles;
		VehicleInfo[id][vID] = db_get_field_assoc_int(Result, "id");
		VehicleInfo[id][vOwner] = db_get_field_assoc_int(Result, "owner");
    	VehicleInfo[id][vOwnerID] = db_get_field_assoc_int(Result, "ownerid");
    	VehicleInfo[id][vPrice] = db_get_field_assoc_int(Result, "price");
    	VehicleInfo[id][vForSale] = db_get_field_assoc_int(Result, "forsale");
    	VehicleInfo[id][vModel] = db_get_field_assoc_int(Result, "model");
		VehicleInfo[id][vPosX] = db_get_field_assoc_float(Result, "posx");
		VehicleInfo[id][vPosY] = db_get_field_assoc_float(Result, "posy");
     	VehicleInfo[id][vPosZ] = db_get_field_assoc_float(Result, "posz");
      	VehicleInfo[id][vPosA] = db_get_field_assoc_float(Result, "posa");

	//	sscanf(buf, "p<|>e<s[25]ddddddddfffff>", VehicleInfo[id][vOwner], VehicleInfo[id][vOwnerID], VehicleInfo[id][vForSale], VehicleInfo[id][vModel], VehicleInfo[id][vCol1], VehicleInfo[id][vCol2], VehicleInfo[id][vPrice], VehicleInfo[id][vPosX], VehicleInfo[id][vPosY], VehicleInfo[id][vPosZ], VehicleInfo[id][vPosA]);
		CreateVehicle(VehicleInfo[id][vModel],VehicleInfo[id][vPosX],VehicleInfo[id][vPosY],VehicleInfo[id][vPosZ],VehicleInfo[id][vPosA],VehicleInfo[id][vCol1], VehicleInfo[id][vCol2], 60*10000);
		format(buf, sizeof buf, "Vehicle Created model: %d Position: %f, %f, %f", VehicleInfo[id][vModel], VehicleInfo[id][vPosX], VehicleInfo[id][vPosY], VehicleInfo[id][vPosZ]);
		LoadedVehicles = LoadedVehicles+1;
		print(buf);
	}
	db_free_result(Result);
}

This is the code you wanted me to do:

Код:
CMD:aveh(playerid, params[])
{
    new model,color,color2,Float:cPos[4], price;
    if(sscanf(params, "iiii", model, price, color,color2)) return SendClientMessage(playerid, -1, "/aveh [model] [price] [color] [color]");
    if(model < 400 || model > 611) return SendClientMessage(playerid,-1, "vehicle IDs between 400 - 611!");
    if(color> 255 || color< 0) return SendClientMessage(playerid, 0xFFFFFF, "Car color ID's: 0-255");
    if(color2> 255 || color2< 0) return SendClientMessage(playerid, 0xFFFFFF, "Car color ID's: 0-255");
    GetPlayerPos(playerid, cPos[0], cPos[1], cPos[2]);
    GetPlayerFacingAngle(playerid, cPos[3]);
    CreateVehicle(model, cPos[0], cPos[1]-3, cPos[2], cPos[3], color, color2, -1);
	LoadedVehicles ++;

	new Query[208];
	VehicleInfo[LoadedVehicles][vID]++;
	format(Query, sizeof Query, "INSERT INTO vehicles (owner, ownerid, price, forsale, model, posx, posy, posz, posa) VALUES (%d, '%s', '%d', '%d', '%d', '%d','%f', '%f', '%f', '%f')", "NONE", -1, price, 1, model, cPos[0], cPos[1], cPos[2], cPos[3]);
	db_query(VehicleDB, Query);
    return 1;
}

stock LoadVehicles()
{
	new id, buf[255];

	new DBResult:Result = db_query(VehicleDB, "SELECT * FROM `vehicles`");
	VehicleInfo[LoadedVehicles][vID] = db_num_rows(Result);
	db_free_result(Result);

	if (db_num_rows(Result))
	{
		id = LoadedVehicles;
		VehicleInfo[id][vID] = db_get_field_assoc_int(Result, "id");
		VehicleInfo[id][vOwner] = db_get_field_assoc_int(Result, "owner");
    	VehicleInfo[id][vOwnerID] = db_get_field_assoc_int(Result, "ownerid");
    	VehicleInfo[id][vPrice] = db_get_field_assoc_int(Result, "price");
    	VehicleInfo[id][vForSale] = db_get_field_assoc_int(Result, "forsale");
    	VehicleInfo[id][vModel] = db_get_field_assoc_int(Result, "model");
		VehicleInfo[id][vPosX] = db_get_field_assoc_float(Result, "posx");
		VehicleInfo[id][vPosY] = db_get_field_assoc_float(Result, "posy");
     	VehicleInfo[id][vPosZ] = db_get_field_assoc_float(Result, "posz");
      	VehicleInfo[id][vPosA] = db_get_field_assoc_float(Result, "posa");

	//	sscanf(buf, "p<|>e<s[25]ddddddddfffff>", VehicleInfo[id][vOwner], VehicleInfo[id][vOwnerID], VehicleInfo[id][vForSale], VehicleInfo[id][vModel], VehicleInfo[id][vCol1], VehicleInfo[id][vCol2], VehicleInfo[id][vPrice], VehicleInfo[id][vPosX], VehicleInfo[id][vPosY], VehicleInfo[id][vPosZ], VehicleInfo[id][vPosA]);
		CreateVehicle(VehicleInfo[id][vModel],VehicleInfo[id][vPosX],VehicleInfo[id][vPosY],VehicleInfo[id][vPosZ],VehicleInfo[id][vPosA],VehicleInfo[id][vCol1], VehicleInfo[id][vCol2], 60*10000);
		format(buf, sizeof buf, "Vehicle Created model: %d Position: %f, %f, %f", VehicleInfo[id][vModel], VehicleInfo[id][vPosX], VehicleInfo[id][vPosY], VehicleInfo[id][vPosZ]);
		LoadedVehicles = LoadedVehicles+1;
		print(buf);
	}
	db_free_result(Result);
}
Reply


Messages In This Thread
sql error PRIMARY KEY must be unique - by lackmail - 28.10.2017, 23:10
Re: sql error PRIMARY KEY must be unique - by Jefff - 28.10.2017, 23:41
Re: sql error PRIMARY KEY must be unique - by lackmail - 28.10.2017, 23:47
Re: sql error PRIMARY KEY must be unique - by Jefff - 28.10.2017, 23:51
Re: sql error PRIMARY KEY must be unique - by lackmail - 29.10.2017, 00:04
Re: sql error PRIMARY KEY must be unique - by lackmail - 29.10.2017, 00:40

Forum Jump:


Users browsing this thread: 2 Guest(s)