SA-MP Forums Archive
mySQL safe problem - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: mySQL safe problem (/showthread.php?tid=225251)



mySQL safe problem - jesse237 - 13.02.2011

Ok this is really weird.

As soon as I use this:
Код:
format(Query, sizeof(Query), "INSERT INTO `houses` (houseID, HouseOwner, hX, hY, hZ) VALUES ('%d', '%s', %f, %f, %f)", random(250), pName(playerid), X, Y, Z);
It works fine and a new file gets created in the mySQL database with another house.

But as soon as I had this:
Код:
format(Query, sizeof(Query), "INSERT INTO `houses` (houseID, HouseOwner, hX, hY, hZ, Virtualworld, Interior) VALUES ('%d', '%s', %f, %f, %f, %d, %d)", random(250), pName(playerid), X, Y, Z, GetPlayerVirtualWorld(playerid), GetPlayerInterior(playerid));
The virtualworld and playerinterior... it doesn't safe a file, Someone can tell me why?


Re: mySQL safe problem - Luis- - 13.02.2011

Hmm, Maybe try this?

pawn Код:
format(Query, sizeof(Query), "INSERT INTO `houses` (houseID, HouseOwner, hX, hY, hZ, Virtualworld, Interior) VALUES (%d, '%s', %f, %f, %f, %d, %d)", random(250), pName(playerid), X, Y, Z, GetPlayerVirtualWorld(playerid), GetPlayerInterior(playerid));
I am a noob at Sql xD


Re: mySQL safe problem - jesse237 - 13.02.2011

Unfortunately it didn't work.

but yeah it makes sort of sense.
Код:
'whatever here'
Is only for things like:
Код:
new something[256];
right?


Re: mySQL safe problem - Steve M. - 13.02.2011

What is the size of Query? Maybe it's too small for everything to fit in.


Re: mySQL safe problem - jesse237 - 13.02.2011

Thanks Steve! Man.. I'm stupid. But I thought if it was the size, I would get a warning or error message (didn't get any), Still your solution fixed my stupid problem, Thanks!


Re: mySQL safe problem - Calgon - 13.02.2011

Unfortunately not, the data that is sent to be written is merely cut from the format.


Re: mySQL safe problem - Steve M. - 13.02.2011

Quote:
Originally Posted by jesse237
Посмотреть сообщение
Thanks Steve! Man.. I'm stupid. But I thought if it was the size, I would get a warning or error message (didn't get any), Still your solution fixed my stupid problem, Thanks!
No problem, man! Any time


Re: mySQL safe problem - jesse237 - 17.02.2011

Ok I'm having a similar problem now, except this time It is now the size of the Query array...

This works fine, a new file in the mysql database gets created:
Код:
stock SaveHouses(playerid, PHouseID, PHouseOwner[], Float:PX, Float:PY, Float:PZ, Virtual, Interior, HCost, HInt, HAdress[])
{
	new
	    aa = Virtual,
		ab =  Interior,
		bb = HCost,
		bc = HInt,
		cc = HAdress[256],
		Query[1024];
		//Query2[600];
		
	format(Query, sizeof(Query), "INSERT INTO `houses` (houseID, HouseOwner, hX, hY, hZ, Virtualworld, Interior) VALUES (%d, '%s', %f, %f, %f, %d, %d)",
	PHouseID, PHouseOwner, PX, PY, PZ, aa, ab);
	mysql_query(Query);
	//mysql_query(Query2);
	mysql_free_result();
	return 1;
}
And this doesn't work, while just one thing is added to the list of the format function, but no new files get created in the mysql database, all because of one extra thing.
Код:
stock SaveHouses(playerid, PHouseID, PHouseOwner[], Float:PX, Float:PY, Float:PZ, Virtual, Interior, HCost, HInt, HAdress[])
{
	new
	    aa = Virtual,
		ab =  Interior,
		bb = HCost,
		bc = HInt,
		cc = HAdress[256],
		Query[1024];
		//Query2[600];
		
	format(Query, sizeof(Query), "INSERT INTO `houses` (houseID, HouseOwner, hX, hY, hZ, Virtualworld, Interior, Cost) VALUES (%d, '%s', %f, %f, %f, %d, %d, %d)",
	PHouseID, PHouseOwner, PX, PY, PZ, aa, ab, bb);
	mysql_query(Query);
	//mysql_query(Query2);
	mysql_free_result();
	return 1;
}
Btw, can someone inform me about string sizes, because I read different things, like somewhere it said, the maximum could be 256, somewhere else it said it doesn't matter and the mysql gamemode from [leth4l] says Query[600], So I'm not sure what the maximum is.


Re: mySQL safe problem - Hiddos - 17.02.2011

You've got a '%d' too much: You want to update 7 fields but are inputting 8 variables.


Re: mySQL safe problem - jesse237 - 17.02.2011

No wait, I f*cked up on my post, that isn't my original code, I'll edit it.

EDIT: Ok, I edited the post. Sorry for the mistake.