PDA

View Full Version : Problem with MySQL updating


AA9
20/03/2014, 07:42 PM
So i tried to make a little test script, to check out MySQL R38 plugin. Problem is with updating player data, when he disconnects. I have tried, to increase sizeof query, but nothing changed.


mysql_format(mysql,query,sizeof(query),"UPDATE playerid SET pX='%f',pY='%f', pZ='%f' WHERE MysqlID=%d",x,y,z,alevel,sqlid);
mysql_tquery(mysql,query);



[21:46:00] [DEBUG] mysql_format - connection: 1, len: 128, format: "UPDATE playerid SET pX='%f',pY='%f', pZ='%f' WHERE MysqlID=%d"
[21:46:00] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE playerid SET pX='867.628723',pY='-11.248103', pZ='63.1953", callback: "(null)", format: "(null)"

Macronix
20/03/2014, 10:08 PM
Have you tried WHERE MysqlID='%d'

AA9
20/03/2014, 10:40 PM
Yes, it didn't change anything.

iZN
20/03/2014, 11:45 PM
1. You haven't added any specifier for variable 'alevel'.
2. Table doesn't exist?
3. Dead connection ?
4. What's the purpose of sqlid. If it is made to be some unique ID, why aren't you getting playerid instead of making it global.
5. What is that 'playerid' table name, is that even correct?

Try to debug some more. 'LOG_ALL' and 'LOG_HTML' for easy log in a proper HTML file.

mysql_log(LOG_ALL, LOG_TYPE_HTML); // OnGameModeInit or OnFilterScriptInit

azzerking
21/03/2014, 04:55 AM
Remove the single quotes from around the %f,

only use a single quote if the data being replaced is a string.

So if the data your replacing is using %s or %e then use single quote for everything else you don't need any single quotes

AA9
21/03/2014, 09:53 AM
First i didn't have these quotes around %f, but if it didn't worked, i changed it. Also i have mysql_log(log_all);
I tried to use mysql_query and it didn't work either.

[21:46:00] [DEBUG] mysql_format - connection: 1, len: 128, format: "UPDATE playerid SET pX='%f',pY='%f', pZ='%f' WHERE MysqlID=%d"
[21:46:00] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE playerid SET pX='867.628723',pY='-11.248103', pZ='63.1953", callback: "(null)", format: "(null)"
[21:46:00] [DEBUG] CMySQLQuery::Execute[] - starting query execution
[21:46:00] [DEBUG] CMySQLQuery::Execute[] - query was successfully executed within 0.631 milliseconds
[21:46:01] [DEBUG] CMySQLQuery::Execute[] - no callback specified, skipping result saving

Lloyde
21/03/2014, 10:06 AM
Remove %f and try %s

iZN
21/03/2014, 11:50 AM
First i didn't have these quotes around %f, but if it didn't worked, i changed it. Also i have mysql_log(log_all);
I tried to use mysql_query and it didn't work either.

[21:46:00] [DEBUG] mysql_format - connection: 1, len: 128, format: "UPDATE playerid SET pX='%f',pY='%f', pZ='%f' WHERE MysqlID=%d"
[21:46:00] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE playerid SET pX='867.628723',pY='-11.248103', pZ='63.1953", callback: "(null)", format: "(null)"
[21:46:00] [DEBUG] CMySQLQuery::Execute[] - starting query execution
[21:46:00] [DEBUG] CMySQLQuery::Execute[] - query was successfully executed within 0.631 milliseconds
[21:46:01] [DEBUG] CMySQLQuery::Execute[] - no callback specified, skipping result saving


Nice to see you have skipped my post. Read it carefully, it has your solution.

AA9
21/03/2014, 01:08 PM
1. You haven't added any specifier for variable 'alevel'.
2. Table doesn't exist?
3. Dead connection ?
4. What's the purpose of sqlid. If it is made to be some unique ID, why aren't you getting playerid instead of making it global.
5. What is that 'playerid' table name, is that even correct?

Try to debug some more. 'LOG_ALL' and 'LOG_HTML' for easy log in a proper HTML file.

mysql_log(LOG_ALL, LOG_TYPE_HTML); // OnGameModeInit or OnFilterScriptInit

1. Here's version with mysql_query.

public OnPlayerDisconnect(playerid, reason)
{
if(Logitud[playerid] == true)
{
new query[128];
new Float:x;
new Float:y;
new Float:z;
new alevel = pInfo[playerid][Admin];
new sqlid = pInfo[playerid][MysqlID];
GetPlayerPos(playerid,x,y,z);
format(query,sizeof(query),"UPDATE playerid SET pX=%f,pY=%f, pZ=%f WHERE MysqlID=%d",x,y,z,sqlid);
mysql_query(mysql,query);
Logitud[playerid] = false;
}
return 1;
}


2. Table exists
3.No
4.When player register, then he's SQLID will be last AUTO_INCREMENT value.
5.Yes, table name is "playerid"

AA9
21/03/2014, 01:31 PM
All worked fine, when i didn't save player cordinates. When i added cordinate saving back, it again didn't work.

newbienoob
21/03/2014, 01:37 PM
give it a try
format(query,sizeof(query),"UPDATE `playerid` SET `pX`=%f,`pY`=%f, `pZ`=%f WHERE `MysqlID`=%d",x,y,z,sqlid);

also, you sure your table name is "playerid"

AA9
21/03/2014, 01:48 PM
Yes, i checked it.

AA9
21/03/2014, 02:05 PM
Okay, now it saves, but it logs it a little bit wrong.


mysql_format(mysql,query,sizeof(query),"UPDATE pdata SET pX=%f ,pY=%f, pZ=%f,Admin=%d WHERE MysqlID=%d",X,Y,Z,alevel,sqlid);
mysql_tquery(mysql,query,"","");


[16:11:18] [DEBUG] mysql_format - connection: 1, len: 128, format: "UPDATE pdata SET pX=%f ,pY=%f, pZ=%f,Admin=%d WHERE MysqlID=%d"
[16:11:18] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE pdata SET pX=1277.729980 ,pY=240.059692, pZ=19.554688,Adm", callback: "(null)", format: "(null)"