SA-MP Forums Archive
What is a better method of saving? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: What is a better method of saving? (/showthread.php?tid=224038)



What is a better method of saving? - Scenario - 10.02.2011

I was working on another accounting system with MySQL when I thought to myself; "What is a better method of saving this?". I am thinking of two different ways...

One: You perform multiple queries, using "UPDATE `accounts` SET ..." as the beginning of each query and send them to the SQL server.

Two: You format multiple strings and send all of the data via one query.

I do not have examples to show right now, but I will provide some if necessary...


Re: What is a better method of saving? - Antonio [G-RP] - 10.02.2011

Do you mean like this..?

pawn Код:
new string[650];

    format(string, sizeof(string), "UPDATE `accounts` SET `level` = %d, `admin` = %d, `cash` = %d, `bank` = %d, `skin` = %d, `sex` = %d, `age` = %d, ",PlayerInfo[playerid][pLevel], PlayerInfo[playerid][pAdmin], \
    PlayerInfo[playerid][pCash], PlayerInfo[playerid][pBank], PlayerInfo[playerid][pSkin], PlayerInfo[playerid][pSex],  PlayerInfo[playerid][pAge]);

    format(string, sizeof(string), "%s`pos_x` = %f, `pos_y` = %f, `pos_z` = %f, `interior` = %d, `faction` = %d, `rank` = %d, `mask` = %d, ",string, PlayerInfo[playerid][pPos_x], \
    PlayerInfo[playerid][pPos_y], PlayerInfo[playerid][pPos_z], PlayerInfo[playerid][pInt], PlayerInfo[playerid][pFaction], PlayerInfo[playerid][pRank], PlayerInfo[playerid][pMask]);
I'm pretty sure this is the more efficient method.


Re: What is a better method of saving? - Scenario - 11.02.2011

It is similar... I have it where it has 3 different formatted strings, then on the fourth formatted string it says "UPDATE `accounts` WHERE '%s', '%s', '%s'", query1, query2, query3);".


Re: What is a better method of saving? - Antonio [G-RP] - 11.02.2011

Hmm, I've never considered that method before. I suppose its almost the same, as it's still sending the data via only one query. I'm pretty sure its better if you stick with only one query, rather than multiple queries.


Re: What is a better method of saving? - Krx17 - 11.02.2011

Wouldn't it amount to the same in the end, because essentially your doing the same thing.


Re: What is a better method of saving? - cessil - 11.02.2011

querying a database once with a long string is quicker than multiple with smaller strings


Re: What is a better method of saving? - Kyosaur - 11.02.2011

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
I was working on another accounting system with MySQL when I thought to myself; "What is a better method of saving this?". I am thinking of two different ways...

One: You perform multiple queries, using "UPDATE `accounts` SET ..." as the beginning of each query and send them to the SQL server.

Two: You format multiple strings and send all of the data via one query.

I do not have examples to show right now, but I will provide some if necessary...
I really dont understand why you would send multiple queries when you only need one.


The best method is using threaded queries, and only saving/updating what you need to be saving/updating, all on-the-fly. I see tons of RP servers updating an entire table when only 2 things have changed, i never understood why they would do this. To top it off, most of the people doing this dont even bother threading their queries *sigh*.


Re: What is a better method of saving? - H7_Tr0m - 11.02.2011

Quote:
Originally Posted by Antonio [G-RP]
Посмотреть сообщение
Do you mean like this..?

pawn Код:
new string[650];

    format(string, sizeof(string), "UPDATE `accounts` SET `level` = %d, `admin` = %d, `cash` = %d, `bank` = %d, `skin` = %d, `sex` = %d, `age` = %d, ",PlayerInfo[playerid][pLevel], PlayerInfo[playerid][pAdmin], \
    PlayerInfo[playerid][pCash], PlayerInfo[playerid][pBank], PlayerInfo[playerid][pSkin], PlayerInfo[playerid][pSex],  PlayerInfo[playerid][pAge]);

    format(string, sizeof(string), "%s`pos_x` = %f, `pos_y` = %f, `pos_z` = %f, `interior` = %d, `faction` = %d, `rank` = %d, `mask` = %d, ",string, PlayerInfo[playerid][pPos_x], \
    PlayerInfo[playerid][pPos_y], PlayerInfo[playerid][pPos_z], PlayerInfo[playerid][pInt], PlayerInfo[playerid][pFaction], PlayerInfo[playerid][pRank], PlayerInfo[playerid][pMask]);
I'm pretty sure this is the more efficient method.
i recommend you to use this, it's easier and more eficcient

bye!


Re: What is a better method of saving? - -Rebel Son- - 11.02.2011

Quote:
Originally Posted by H7_Tr0m
Посмотреть сообщение
i recommend you to use this, it's easier and more eficcient

bye!
How sure are you about this?

Explain.


Re: What is a better method of saving? - Antonio [G-RP] - 11.02.2011

Quote:
Originally Posted by -Rebel Son-
Посмотреть сообщение
How sure are you about this?

Explain.
What?