sql error PRIMARY KEY must be unique
#6

i found out the issue there was an extra '%d'
Код:
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]);
it saves correctly but it only loads the first car:
Код:
stock LoadVehicles()
{
	new id, buf[255];

	new DBResult:Result = db_query(VehicleDB, "SELECT * FROM `vehicles`");
	VehicleInfo[LoadedVehicles][vID] = db_num_rows(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);
}
EDIT

I have figured it out this is what i have done and it works thanks jeff for the help
Код:
stock LoadVehicles()
{
	new buf[255];

	new DBResult:Result = db_query(VehicleDB, "SELECT * FROM `vehicles`");
	new rows = db_num_rows(Result);
	if(!rows) return print("No Saved Vehicles!");
	for(new i; i < rows; i++)
	{
		VehicleInfo[i][vID] = db_get_field_assoc_int(Result, "id");
		VehicleInfo[i][vOwner] = db_get_field_assoc_int(Result, "owner");
    	VehicleInfo[i][vOwnerID] = db_get_field_assoc_int(Result, "ownerid");
    	VehicleInfo[i][vPrice] = db_get_field_assoc_int(Result, "price");
    	VehicleInfo[i][vForSale] = db_get_field_assoc_int(Result, "forsale");
    	VehicleInfo[i][vModel] = db_get_field_assoc_int(Result, "model");
		VehicleInfo[i][vPosX] = db_get_field_assoc_float(Result, "posx");
		VehicleInfo[i][vPosY] = db_get_field_assoc_float(Result, "posy");
     	VehicleInfo[i][vPosZ] = db_get_field_assoc_float(Result, "posz");
      	VehicleInfo[i][vPosA] = db_get_field_assoc_float(Result, "posa");

		CreateVehicle(VehicleInfo[i][vModel],VehicleInfo[i][vPosX],VehicleInfo[i][vPosY],VehicleInfo[i][vPosZ],VehicleInfo[i][vPosA],VehicleInfo[i][vCol1], VehicleInfo[i][vCol2], 60*10000);
		format(buf, sizeof buf, "Vehicle Created model: %d Position: %f, %f, %f", VehicleInfo[i][vModel], VehicleInfo[i][vPosX], VehicleInfo[i][vPosY], VehicleInfo[i][vPosZ]);
		LoadedVehicles++;
		print(buf);
  		db_next_row(Result);
	}
	db_free_result(Result);
	return 1;
}
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: 1 Guest(s)