MySQL saving problem
#1

Hey! I am a little confused. Just start make a backpack-system with MySQL R41 and I have issue with saving. When I create a backpack with INSERT INTO `backpacks` command, everything is alright. But when I try to move another position and save it with UPDATE `backpacks`, the object moved and debug says changed value but the value isn't change in the table. Sorry for my bad english..


Код:
[19:05:48] [DEBUG] mysql_format(1, 0x0076E3C0, 256, "UPDATE `backpacks` SET `PosX` = %f, `PosY` = %f, `PosZ` = %f, `PosRX` = %f, `PosRY` = %f, `PosRZ` = %f WHERE `ID` = %i")
[19:05:48] [DEBUG] mysql_format: return value: '159'
[19:05:48] [DEBUG] mysql_tquery(1, "UPDATE `backpacks` SET `PosX` = -73.955910, `PosY` = 1081.626831, `PosZ` = 19.742188, `PosRX` = 0.000000, `PosRY` = 0.000000, `PosRZ` = 0.000000 WHERE `ID` = 0", "", "")
[19:05:48] [DEBUG] CCallback::Create(amx=0x291f930, name='', format='', params=0x76e3ac, param_offset=5)
[19:05:48] [DEBUG] CHandle::Execute(this=0x68cb348, type=1, query=0x690bd10)
[19:05:48] [DEBUG] CHandle::Execute - return value: true
[19:05:48] [DEBUG] mysql_tquery: return value: '1'
Код:
SaveBackpack(id)
{
    if(!bInfo[id][ID]) return 0;
    
	new query[256];
	mysql_format(Database, query, sizeof query, "UPDATE `backpacks` SET `PosX` = %f, `PosY` = %f, `PosZ` = %f, `PosRX` = %f, `PosRY` = %f, `PosRZ` = %f WHERE `ID` = %i",
	bInfo[id][Pos][0], bInfo[id][Pos][1], bInfo[id][Pos][2], bInfo[id][Pos][3], bInfo[id][Pos][4], bInfo[id][Pos][5], bInfo[id][VirtualWorld], bInfo[id][Interior], bInfo[id][Type], bInfo[id][Use], bInfo[id][ID]);
	mysql_tquery(Database, query);
	
	for(new i = 0; i < 20; i++)
	{
		mysql_format(Database, query, sizeof query, "UPDATE `backpacks` SET `Item%d` = %d WHERE `ID` = %i", i, bInfo[id][Item][i], bInfo[id][ID]);
		mysql_tquery(Database, query);
		mysql_format(Database, query, sizeof query, "UPDATE `backpacks` SET `ItemAmount%d` = %d WHERE `ID` = %i", i, bInfo[id][ItemAmount][i], bInfo[id][ID]);
		mysql_tquery(Database, query);
	}
	printf("[Mentйs] Hбtizsбk elmentve. ID: %d.", id);
	return 1;
}
Reply
#2

This is your query:
Код:
"UPDATE `backpacks` SET `PosX` = -73.955910, `PosY` = 1081.626831, `PosZ` = 19.742188, `PosRX` = 0.000000, `PosRY` = 0.000000, `PosRZ` = 0.000000 WHERE `ID` = 0"
It attempts to update a row in which the ID is equal to 0 but it does not exist so no rows are affected.

Let's take a closer look at the columns count and arguments count:
Код:
`PosX` = %f, `PosY` = %f, `PosZ` = %f, 
`PosRX` = %f, `PosRY` = %f, `PosRZ` = %f 
WHERE `ID` = %i",
bInfo[id][Pos][0], bInfo[id][Pos][1], bInfo[id][Pos][2],
bInfo[id][Pos][3], bInfo[id][Pos][4], bInfo[id][Pos][5], 
bInfo[id][VirtualWorld], bInfo[id][Interior], bInfo[id][Type], bInfo[id][Use], bInfo[id][ID]);
It takes the value of virtual world which is 0. Remove virtual world, interior, type and use from the arguments or add the columns in the query if you want to update these as well.
Reply
#3

Omg.. Thank you so much!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)