SA-MP Forums Archive
Which query method is better? - 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)
+--- Thread: Which query method is better? (/showthread.php?tid=379298)



Which query method is better? - tMike - 21.09.2012

Hey dear,

i tried a lot of methodes and now a question turned up in me.

Which save method is better? all in one or one string for one data?

A query does not consume the whole string...

For example:

pawn Код:
new query[160];
GetPlayerName(playerid, name, MAX_PLAYER_NAME);
format(query,sizeof(query),"UPDATE players SET PlayerLevel = '%d' WHERE Name = '%s' LIMIT 1", PlayerData[playerid][plLevel], name);
mysql_query(query, THREAD_MYSELECT,-1,sqlconnection);
format(query,sizeof(query),"UPDATE players SET AdminLevel= '%d' WHERE Name = '%s' LIMIT 1", PlayerData[playerid][plAdmin], name);
mysql_query(query, THREAD_MYSELECT,-1,sqlconnection);
format(query,sizeof(query),"UPDATE players SET DonateRank = '%d' WHERE Name = '%s' LIMIT 1", PlayerData[playerid][plDonate], name);
mysql_query(query, THREAD_MYSELECT,-1,sqlconnection);
format(query,sizeof(query),"UPDATE players SET Registered= '%d' WHERE Name = '%s' LIMIT 1", PlayerData[playerid][plRegistered], name);
mysql_query(query, THREAD_MYSELECT,-1,sqlconnection);
Ore should i go on this way:

pawn Код:
new query[2048];
GetPlayerName(playerid, name, MAX_PLAYER_NAME);
format(query,sizeof(query),"UPDATE players SET PlayerLevel = '%d', AdminLevel = %d, DonateRank = %d, Registered = %d (etc., - so this will be a very very long query with additional strings and other things) WHERE Name = '%s' LIMIT 1", PlayerData[playerid][plLevel], PlayerData[playerid][plAdmin], PlayerData[playerid][plDonateRank],PlayerData[playerid][plRegistered], name);
mysql_query(query, THREAD_MYSELECT,-1,sqlconnection);
I ask because the string size is very high. Our server has over 100 players a day and when im saving all the data the server laggs (because its to much maybe). And i think it is up to the querys.

Thanks for help.

Greets


Re: Which query method is better? - Vince - 21.09.2012

One query is better than multiple queries at all times. Don't care about string size too much. If your server lags, then by all means use threaded queries.


AW: Re: Which query method is better? - tMike - 21.09.2012

Quote:
Originally Posted by Vince
Посмотреть сообщение
One query is better than multiple queries at all times. Don't care about string size too much. If your server lags, then by all means use threaded queries.
Thanks for your help. I will try it now.

I have tried a lot of things to make the queries threaded, but I'm not sure how to use it right. Can u explain it to me or give me a link to an explanation?


Re: Which query method is better? - Vince - 21.09.2012

Here's a tutorial on R7: https://sampforum.blast.hk/showthread.php?tid=337810

Also the MySQL storage engine might have something to do with it. I'm not exactly sure which storage engine is better for update queries, but I do know that MyISAM uses table level locking and InnoDB uses row level locking.


AW: Which query method is better? - tMike - 21.09.2012

Ok, i will try it later. (i'm using R6 actually, so i have to rewrite the whole mysql-parts of my script).

I've another problem now.

The compiler told me, that the input line is to long (error 075: input line too long (after substitutions)).
Should I use more strings? What would you recommend me?

LG


AW: Re: Which query method is better? - tMike - 21.09.2012

You mean with strcat or the slash function ( \ )?

Thanks.


AW: Which query method is better? - tMike - 21.09.2012

pawn Код:
new szQuery[768];
format(szQuery, sizeof(szQuery), "UPDATE `players` SET `value` = 1, `value2` = 6, `value3` = 'cats'");
format(szQuery, sizeof(szQuery), "%s `value4` = 'sixtytwo', `value5` = 'thefutureiswithinyoursights'", szQuery);
format(szQuery, sizeof(szQuery), "%s `value6` = 'itsalright', `value7` = 'junglemassive'", szQuery);
format(szQuery, sizeof(szQuery), "%s WHERE `Name` = '%s'", szQuery, GetPlayerNameEx(playerid));
like this?

thanks for ur help.