SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 15/02/2020, 08:46 PM   #1
Davi52
Little Clucker
 
Join Date: Sep 2018
Posts: 40
Reputation: 0
Question Problem with MySQL saving.

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'
Davi52 is offline   Reply With Quote
Old 15/02/2020, 09:58 PM   #2
Unte99
Gangsta
 
Unte99's Avatar
 
Join Date: Jul 2010
Location: Lithuania
Posts: 627
Reputation: 67
Default Re: Problem with MySQL saving.

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
Unte99 is offline   Reply With Quote
Old 15/02/2020, 10:45 PM   #3
Symon
Gangsta
 
Symon's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 991
Reputation: 107
Default Re: Problem with MySQL saving.

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?
__________________
Epic Missions - An upcoming mini missions server.

Fully MySQL featured, no server restart during a mission change, many different mission types available (TDM, DM, BOMBING, LMS, LTS etc.), perks, rewards, level system and much more. Join us and wait for the launch!


Website | Forum | Development logs | Join our Discord
Symon is offline   Reply With Quote
Old 16/02/2020, 07:26 AM   #4
Davi52
Little Clucker
 
Join Date: Sep 2018
Posts: 40
Reputation: 0
Default Re: Problem with MySQL saving.

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!
Davi52 is offline   Reply With Quote
Old 16/02/2020, 09:37 AM   #5
Calisthenics
High-roller
 
Join Date: May 2018
Posts: 1,228
Reputation: 205
Default Re: Problem with MySQL saving.

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.
__________________
Calisthenics is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL saving problem Ripster Scripting Help 2 09/10/2018 06:03 PM
Password Hash Problem & MYSQL Saving Problem Faqahat Scripting Help 3 18/04/2016 11:54 AM
MySQL - Problem with Saving into IDs Saize Scripting Help 2 15/02/2015 03:13 PM
problem saving mysql jcvag44800 Scripting Help 5 07/05/2014 10:27 PM
saving system mysql(not mysql problem) martoivanov Scripting Help 0 29/08/2013 03:37 PM


All times are GMT. The time now is 07:22 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.