Question about mysql saved data - 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: Question about mysql saved data (
/showthread.php?tid=660800)
Question about mysql saved data -
darkHero - 13.11.2018
Imagine that I have a large amount of data to save, it would be better to execute everything in a single query or in several with a smaller string.
A query
Quote:
new query[2500]; // Example, in case of having a lot of data
format(query, sizeof(query), "UPDATE `USER` SET `var`=%d, `var2`=%d, `var3`=%d, `var4`=%d WHERE `ID`='%d'", var, var2, var3, var4, id);
mysql_tquery(conexion, query, "", "");
|
Various queries
Quote:
new query[256]; // Example
format(query, sizeof(query), "UPDATE `USER` SET `var3`=%d, `var4`=%d WHERE `ID`='%d'", var3, var4, id);
mysql_tquery(conexion, query, "", "");
format(query, sizeof(query), "UPDATE `USER` SET `var`=%d, `var2`=%d WHERE `ID`='%d'", var, var2, id);
mysql_tquery(conexion, query, "", "");
|
These are examples.
Re: Question about mysql saved data -
GangstaSunny. - 13.11.2018
In one query.
Re: Question about mysql saved data -
darkHero - 13.11.2018
even if that leads to making a big string?
Re: Question about mysql saved data -
dotSILENT - 13.11.2018
Single query should be faster, although it can get pretty confusing if you need to update a really large set of data.
If you don't care about the result and you are using tquery (as I see in the code) then I think it's not really any big deal, you could go with 2 queries if you really require it. I would however stick to single query as long as it works, though I'd keep a big global array for formatting such things instead of declaring them in the function's scope, as it's a massive performance improvement especially if you need to do it in many places.
I have a global array caled fmt which is over 2500 cells big and I use it for every string formatting, including mysql queries. This way I hardly ever need to declare any new variables for my strings.