A question about mysql. -
Ahmad45123 - 15.04.2015
Hello all.
So I have a question, I have always been using mysql(SQLLite actually) for just small stuff like server stats and so on.
And now I want to convert the user system to mysql but the problem is that there is more than 100 item in the ini file so converting them to mysql will make the INSERT/UPDATE statement freaking long....
Any tips on what is the best way to build the SQL strings and if MySQL is better than INI on user stuff or not ?
Re: A question about mysql. -
BleverCastard - 15.04.2015
Quote:
Originally Posted by Ahmad45123
if MySQL is better than INI on user stuff or not ?
|
It is for one.
Quote:
Originally Posted by Ahmad45123
the problem is that there is more than 100 item in the ini file so converting them to mysql will make the INSERT/UPDATE statement freaking long....
|
It will be time consuming. But it'll be the best transfer that you've ever done.
Re: A question about mysql. -
Ahmad45123 - 15.04.2015
Quote:
Originally Posted by BleverCastard
It is for one.
|
What do you mean ?
Quote:
Originally Posted by BleverCastard
It will be time consuming. But it'll be the best transfer that you've ever done.
|
Oh... Can you provide an example of a huge gamemode that uses mySQL .
I want to see the best way to create the SQL Command.
Re: A question about mysql. -
BroZeus - 15.04.2015
Tip to make INSERT query short is that while creating table don't forget to set default value of the column so that you don't need to insert that value with the query. For example if you set default of Admin money and score to 0 then you have to just use name password and ip in insert query and rest will be set to 0 by default.
The tip to make UPDATE query shorter is:
Quote:
Originally Posted by Haydz
Hey Jimmy, it's been awhile ! Another way would be removing a few of what you're saving and save them separately when they need to be saved.
E.G
`admin` - You'd only need to save that whenever it gets changed, so upon the promoting / demoting admin command just save it then.
`score` - Depending how often a player gets score it might not really matter but you could create your own score function and save the new score var when they're given a score.
`money` - Similar to above, save the players money value whenever they gain / lose money. This way their money data will be up to date if the server happens to crash and the server can't save the data that occoured after the last saving point.
Exp, Level, Kills Deaths - You get the point, save it when the player gets killed / kills somebody else.
Now your query is only 419 characters long, allow some space for the larger values (many 50-80 characters or so). There's nothing wrong with a decent sized query, it has to be saved somehow lol.
pawn Код:
UPDATE `members` SET `weapon1` = %d, `ammo1` = %d, `weapon2` = %d, `ammo2` = %d, `weapon3` = %d, `ammo3` = %d, `weapon4` = %d, `ammo4` = %d, `weapon5` = %d, `ammo5` = %d, `weapon6` = %d, `ammo6` = %d, `weapon7` = %d, `ammo7` = %d, `weapon8` = %d, `ammo8` = %d, `weapon9` = %d, `ammo9` = %d, `weapon10` = %d, `ammo10` = %d, `weapon11` = %d, `ammo11` = %d, `weapon12` = %d, `ammo12` = %d WHERE `id` = %d LIMIT 1
|
Re: A question about mysql. -
Ahmad45123 - 15.04.2015
Quote:
Originally Posted by BroZeus
Tip to make INSERT query short is that while creating table don't forget to set default value of the column so that you don't need to insert that value with the query. For example if you set default of Admin money and score to 0 then you have to just use name password and ip in insert query and rest will be set to 0 by default.
The tip to make UPDATE query shorter is:
|
Ahhh... So I just have to save stuff when they are changed.
Thanks alot mate.
Re: A question about mysql. -
BleverCastard - 15.04.2015
Quote:
Originally Posted by Ahmad45123
What do you mean ?
Oh... Can you provide an example of a huge gamemode that uses mySQL .
I want to see the best way to create the SQL Command.
|
MySQL is a lot better than INI.
There's plenty of gamemodes released mate. I don't like "handing" code to people because I feel they won't learn anything. You pick one and I'll help you out if you get stuck.
Re: A question about mysql. -
HyperionSU - 15.04.2015
Notepad++ can do the trick with the Replace function (CTRL+H) if you want to convert faster. Just replace all the line endings and starts with appropriate symbols.
And by the way there's nothing wrong with having a long query, I guess.
Re: A question about mysql. -
BleverCastard - 15.04.2015
And so can the Pawno Editor?
Re: A question about mysql. -
Ahmad45123 - 15.04.2015
Hey... Ok... I have 256 items meaning there will be 256 columns... That's okay or any lag will be caused ?
Re: A question about mysql. -
Konstantinos - 15.04.2015
No, but it's better to have more rows and less fields.
I'm not aware about your items but you may find interesting two tutorials by Vince:
https://sampforum.blast.hk/showthread.php?tid=420363
https://sampforum.blast.hk/showthread.php?tid=505081
if it's possible in your case.