MySQL insert stops in the middle
#1

Here is the debug:

Код:
INSERT INTO `cars_system` (`VehicleID`,`Model``Color1`, `Color2`,`Respawn`,`OwnerID`,`Owned`,`Freezed`,`Price`,`Engine`,`Lights`,`Alarm`,`Doors`,`Hood`,`Trunk`,`Object`,`PosX`, `PosY`, `PosZ`, `PosA`) VALUES ('1','402','-1','-1','-1','0','0','1','33','0',
Here is the code:

Код:
CMD:spawncar(playerid,params[])
{
	if(Player[playerid][AdminLevel] <= 2) return SendClientMessage(playerid,-1,"You aren't an admin!");//Check if the player is currently rcon logged in.
	new CarPrice,id = CarsCount,CarModel[32], tmp[128];
		
	if(sscanf(params,"is[32]",CarPrice, CarModel)) return SendClientMessage(playerid,-1,"USAGE: /spawncar <price> <model>");//Checking if the player uses the correct syntax. The parameter "i" in sscanf means integer, also could be used as "d".
	new Float:x,Float:y,Float:z, Float: Angle;//Creating the floats, to store the player's position.
	GetPlayerPos(playerid,x,y,z);//Getting the player's position and storing it
	GetPlayerFacingAngle(playerid, Angle);
		new 
        CarID = GetCarIDFromName(CarModel); 

	Vehicle[id][VehicleID] = id;//Setting the house price to the selected one.
	Vehicle[id][Model] = CarID;//Setting the house price to the selected one.
	Vehicle[id][PosX] = x;//Setting the house price to the selected one.
	Vehicle[id][PosY] = y;//Setting the house price to the selected one.
	Vehicle[id][PosZ] = z;//Setting the house price to the selected one.
	Vehicle[id][PosA] = Angle;//Setting the house price to the selected one.
	Vehicle[id][Color1] = -1;//Setting the house price to the selected one.
	Vehicle[id][Color2] = -1;//Setting the house price to the selected one.
	Vehicle[id][Respawn] = -1;//Setting the house price to the selected one.
	Vehicle[id][OwnerID] = 0;//Setting the house price to the selected one.
	Vehicle[id][Owned] = 0;//Setting the house price to the selected one.
	Vehicle[id][Freezed] = 1;//Setting the house price to the selected one.
	Vehicle[id][Price] = CarPrice;//Setting the house price to the selected one.
	Vehicle[id][Engine] = 0;//Setting the house price to the selected one.
	Vehicle[id][Lights] = 0;//Setting the house price to the selected one.
	Vehicle[id][Doors] = 0;//Setting the house price to the selected one.
	Vehicle[id][Alarm] = 0;//Setting the house price to the selected one.
	Vehicle[id][Hood] = 0;//Setting the house price to the selected one.
	Vehicle[id][Trunk] = 0;//Setting the house price to the selected one.
	Vehicle[id][Object] = 1;//Setting the house price to the selected one.

    if (CarID == -1) return SendClientMessage(playerid, -1, "Invalid car name"); 
	
	Player[playerid][pSpawnVehicle] = CreateVehicle(CarID, x, y, z, Angle, Vehicle[id][Color1], Vehicle[id][Color2], -1);
	LinkVehicleToInterior(Player[playerid][pSpawnVehicle], GetPlayerInterior(playerid));
	SetVehicleParamsEx(Player[playerid][pSpawnVehicle], Vehicle[id][Engine], Vehicle[id][Lights], Vehicle[id][Alarm], Vehicle[id][Doors],  Vehicle[id][Hood],  Vehicle[id][Trunk], Vehicle[id][Object]);
	PutPlayerInVehicle(playerid, Player[playerid][pSpawnVehicle], 0);
	format(tmp, sizeof(tmp), "[CAR FOR SALE]\n{FFFFFF}Owner: Dealership \nPrice: $%d",Vehicle[id][Price]);
	Create3DTextLabel(tmp, COLOR_SYNTAX,x,y,z, 40.0,0,0);
	SendClientMessage(playerid,-1,"Car spawned");
	CarsCount++;
	new query[256];
	mysql_format(g_SQL, query, sizeof(query),
	"INSERT INTO `cars_system` (`VehicleID`,`Model``Color1`, `Color2`,`Respawn`,`OwnerID`,`Owned`,`Freezed`,`Price`,`Engine`,`Lights`,`Alarm`,`Doors`,`Hood`,`Trunk`,`Object`,`PosX`, `PosY`, `PosZ`, `PosA`) VALUES ('%i','%i','%i','%i','%i','%i','%i','%i','%i','%i','%i','%i','%i','%i','%i','%i',%f,%f,%f,%f)",
	CarsCount,CarID,Vehicle[id][Color1],Vehicle[id][Color2],Vehicle[id][Respawn],Vehicle[id][OwnerID],Vehicle[id][Owned],Vehicle[id][Freezed],Vehicle[id][Price],Vehicle[id][Engine],Vehicle[id][Lights],Vehicle[id][Alarm],Vehicle[id][Doors],Vehicle[id][Hood],Vehicle[id][Trunk],Vehicle[id][Object],Vehicle[id][PosX],Vehicle[id][PosY],Vehicle[id][PosZ],Vehicle[id][PosA]);
	mysql_tquery(g_SQL, query, "", "");
	printf(query);

	return 1;
}
Reply
#2

The variable 'query' only allows for 256 characters. Make it larger.

Edit
Reply
#3

Now it insert on printf but not in MySQL i seted query to 600

Printf --->

Код:
INSERT INTO `cars_system` (`VehicleID`,`Model``Color1`, `Color2`,`Respawn`,`OwnerID`,`Owned`,`Freezed`,`Price`,`Engine`,`Lights`,`Alarm`,`Doors`,`Hood`,`Trunk`,`Object`,`PosX`, `PosY`, `PosZ`, `PosA`) VALUES ('1','402','-1','-1','-1','0','0','1','33','0','0','0','0','0','0','1',1648.493,-1111.489,23.914,110.289)
EDIT: Problem fixed i forgot one , after `Model`.
Reply
#4

Try taking a look at ORM. It will prevent mistakes like these by taking care of most variable handling.
Reply
#5

I see there's some unescape string in this syntax.
Код:
1648.493,-1111.489,23.914,110.289
You need to add single quotes ' for string on mysql syntax.
Reply
#6

Quote:
Originally Posted by bondowocopz
Посмотреть сообщение
I see there's some unescape string in this syntax.
Код:
1648.493,-1111.489,23.914,110.289
You need to add single quotes ' for string on mysql syntax.
those numbers are floats, not strings :P

Anyway, I've had this problem a numerous amount of times, and everytime it's the same thing, string exceeds character limit.

use this to check how many characters your query has.

Also, I recommend you to replace the "%f" and "%s" with the max amount of characters it COULD have when you paste it in that site, then add +5 or +10 chars to make sure you can't get an exploit there.

example: INSERT INTO Users ( name, password, adminlevel ) VALUES ( '%s', '%s', %i ); with params: xXxx_Swaglord_xXxX, you_cant_guess_this_password, 0

that would become:
INSERT INTO Users ( name, password, adminlevel ) VALUES ( 'xXxx_Swaglord_xXxX', 'you_cant_guess_this_password', 0 ); when executed.

when entering that string to the website I provided, you'll see it has more characters than when you just keep %s etc.

that string would have 116 characters, rounding it would come to approx 120 characters, so you'd do:
pawn Код:
new query[ 120 ]; // or 128, whatever you prefer aslong as it's 117 since the string has that size.
I usually go to this site after I've written a few queries just to make sure it can't get bugged, it took me a long time to find out that it was this when it happened to me the first time :P
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)