Which query method is better?
#1

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

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

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?
Reply
#4

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

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
Reply
#6

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

Thanks.
Reply
#7

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


Forum Jump:


Users browsing this thread: 1 Guest(s)