Problem with MySQL saving.
#1

Hey! The problem is, when I save my character on server, doesn't updates all thing, even if in the mysql log says that executed successfully. So I show the code:
Code:
mysql_format(sql,q,sizeof(q),
	"UPDATE `characters` SET `Name`='%s', `Gender`='%d',`Skin`='%d' WHERE `ID`='%d'",CharInfo[characterid][name],CharInfo[characterid][gender],CharInfo[characterid][skin],characterid);
	mysql_query(sql,q,false);
	mysql_format(sql,q,sizeof(q),
	"UPDATE `characters` SET `LastEnter`='%s',`Ban`='%d',`Birth`='%s',`Radical`='%s',`Bank`='%d' WHERE `ID`='%d'",CharInfo[characterid][lastEnter],CharInfo[characterid][ban],CharInfo[characterid][birth],CharInfo[characterid][radical],CharInfo[characterid][bankMoney],characterid);
	mysql_query(sql,q,false);
	mysql_format(sql,q,sizeof(q),
	"UPDATE `characters` SET `Cash`='%d',`Level`='%d',`Job`='%d',`Faction`='%d',`AdminJail`='%d' WHERE `ID`='%d'",CharInfo[characterid][cash],CharInfo[characterid][level],CharInfo[characterid][bankMoney],CharInfo[characterid][job],CharInfo[characterid][faction],CharInfo[characterid][adminJail],characterid);
	mysql_query(sql,q,false);
And here's the MySQL log. For e.g The name, gender, lastenter changes, but the Cash no, remains the same in the database while in the log its correct.
Code:
[23:40:57] [DEBUG] mysql_format(1, 0x03F4BF44, 1024, "UPDATE `characters` SET `Name`='%s', `Gender`='%d',`Skin`='%d' WHERE `ID`='%d'")
[23:40:57] [DEBUG] mysql_format: return value: '87'
[23:40:57] [DEBUG] mysql_query(1, "UPDATE `characters` SET `Name`='James_Cartment', `Gender`='0',`Skin`='6' WHERE `ID`='1'", 0)
[23:40:57] [DEBUG] CHandle::Execute(this=0x5e0dd0, type=3, query=0x608dc0)
[23:40:57] [DEBUG] CConnection::Execute(query=0x608dc0, this=0x548a70, connection=0x599120)
[23:40:57] [DEBUG] CQuery::Execute(this=0x608dc0, connection=0x599120)
[23:40:57] [INFO] query "UPDATE `characters` SET `Name`='James_Cartment', `Gender`='0',`Skin`='6' WHERE `ID`='1'" successfully executed within 104.726 milliseconds
[23:40:57] [DEBUG] CResultSet::Create(connection=0x599120, query_str='UPDATE `characters` SET `Name`='James_Cartment', `Gender`='0',`Skin`='6' WHERE `ID`='1'')
[23:40:57] [DEBUG] created new resultset '0x555958'
[23:40:57] [DEBUG] fetched MySQL result '0x0'
[23:40:57] [DEBUG] CHandle::Execute - return value: true
[23:40:57] [DEBUG] mysql_query: return value: '0'
[23:40:57] [DEBUG] mysql_format(1, 0x03F4BF44, 1024, "UPDATE `characters` SET `LastEnter`='%s',`Ban`='%d',`Birth`='%s',`Radical`='%s',`Bank`='%d' WHERE `ID`='%d'")
[23:40:57] [DEBUG] mysql_format: return value: '125'
[23:40:57] [DEBUG] mysql_query(1, "UPDATE `characters` SET `LastEnter`='2020/2/15',`Ban`='0',`Birth`='1976/7/24',`Radical`='Mongoloid',`Bank`='0' WHERE `ID`='1'", 0)
[23:40:57] [DEBUG] CHandle::Execute(this=0x5e0dd0, type=3, query=0x608278)
[23:40:57] [DEBUG] CConnection::Execute(query=0x608278, this=0x548a70, connection=0x599120)
[23:40:57] [DEBUG] CQuery::Execute(this=0x608278, connection=0x599120)
[23:40:57] [INFO] query "UPDATE `characters` SET `LastEnter`='2020/2/15',`Ban`='0',`Birth`='1976/7/24',`Radical`='Mongoloid',`Bank`='0' WHERE `ID`='1'" successfully executed within 46.768 milliseconds
[23:40:57] [DEBUG] CResultSet::Create(connection=0x599120, query_str='UPDATE `characters` SET `LastEnter`='2020/2/15',`Ban`='0',`Birth`='1976/7/24',`Radical`='Mongoloid',`Bank`='0' WHERE `ID`='1'')
[23:40:57] [DEBUG] created new resultset '0x555bf8'
[23:40:57] [DEBUG] fetched MySQL result '0x0'
[23:40:57] [DEBUG] CHandle::Execute - return value: true
[23:40:57] [DEBUG] mysql_query: return value: '0'
[23:40:57] [DEBUG] mysql_format(1, 0x03F4BF44, 1024, "UPDATE `characters` SET `Cash`='%d',`Level`='%d',`Job`='%d',`Faction`='%d',`AdminJail`='%d' WHERE `ID`='%d'")
[23:40:57] [DEBUG] mysql_format: return value: '105'
[23:40:57] [DEBUG] mysql_query(1, "UPDATE `characters` SET `Cash`='50203',`Level`='0',`Job`='0',`Faction`='0',`AdminJail`='0' WHERE `ID`='0'", 0)
[23:40:57] [DEBUG] CHandle::Execute(this=0x5e0dd0, type=3, query=0x608440)
[23:40:57] [DEBUG] CConnection::Execute(query=0x608440, this=0x548a70, connection=0x599120)
[23:40:57] [DEBUG] CQuery::Execute(this=0x608440, connection=0x599120)
[23:40:57] [INFO] query "UPDATE `characters` SET `Cash`='50203',`Level`='0',`Job`='0',`Faction`='0',`AdminJail`='0' WHERE `ID`='0'" successfully executed within 46.790 milliseconds
[23:40:57] [DEBUG] CResultSet::Create(connection=0x599120, query_str='UPDATE `characters` SET `Cash`='50203',`Level`='0',`Job`='0',`Faction`='0',`AdminJail`='0' WHERE `ID`='0'')
[23:40:57] [DEBUG] created new resultset '0x61b550'
[23:40:57] [DEBUG] fetched MySQL result '0x0'
[23:40:57] [DEBUG] CHandle::Execute - return value: true
[23:40:57] [DEBUG] mysql_query: return value: '0'
[23:40:57] [DEBUG] mysql_errno(1)
[23:40:57] [DEBUG] CHandle::GetErrorId(this=0x5e0dd0)
[23:40:57] [DEBUG] CConnection::GetError(this=0x548a70, connection=0x599120)
[23:40:57] [DEBUG] CHandle::GetErrorId - return value: true, error id: '0', error msg: ''
[23:40:57] [DEBUG] mysql_errno: return value: '0'
Reply
#2

Tablename is missing.

EDIT: Sorry. Read the query bad. Nevermind.

Quote:

`Cash`='%d'

You don't need the ' for integers. Only use them when the variable type is of string. Also, don't need the ` for column names. So it should be:

Quote:

Cash=%i

Reply
#3

Quote:
Originally Posted by Unte99
View Post
Tablename is missing.

EDIT: Sorry. Read the query bad. Nevermind.



You don't need the ' for integers. Only use them when the variable type is of string. Also, don't need the ` for column names. So it should be:
He's using ' for all integers in that query, so the problem is not that since only the money is the problem. But Davi, i suggest you to remove ' when saving integers as you don't need it.

Are you using a server side money system?
Reply
#4

The problem is solved after a couple of tries. If someone will have this problem, mine fixed with splitting the query into more lines, and after the problem was that some argument types were mismatch. Thanks for trying to help!
Reply
#5

To add to what Unte99 said:
Use single quotes around strings only. This way, mysql will not have to internally convert text to integer or float.
You only need ` ` around columns when they are reserved keywords to avoid conflict.

Of course 1024 size of query was more than enough and the mismatch arguments was the problem but it helps reduces the size of the query in general.

Now onto the main issue. Please avoid using mysql as an INI file system. What I mean is that you should not update data that you know they have not changed. There is no reason to. How often does Name, Gender, Skin, Birth etc. change? Very rare so update when they do.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)