What is a better method of saving?
#1

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...
Reply
#2

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.
Reply
#3

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);".
Reply
#4

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.
Reply
#5

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

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

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*.
Reply
#8

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!
Reply
#9

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.
Reply
#10

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

Explain.
What?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)