SA-MP Forums Archive
Format VS MYSQL_FORMAT - 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: Format VS MYSQL_FORMAT (/showthread.php?tid=491225)



Format VS MYSQL_FORMAT - andyandyy8 - 29.01.2014

Hi !
I am not sure what to use format or mysql_format... Which is more faster ?


Re: Format VS MYSQL_FORMAT - SwisherSweet - 29.01.2014

mysql_format is for mysql databases,
And yes mysql will always be faster, I have experience with these things...


Re : Format VS MYSQL_FORMAT - andyandyy8 - 29.01.2014

I use it for creating a query...
Thanks . Can you argue?


Re: Format VS MYSQL_FORMAT - SwisherSweet - 30.01.2014

Quote:
Originally Posted by ******
View Post
Care to share this experience, maybe in the form of speed test comparisons?
It was about a year ago, And it was on my laptop which crashed and I lost all information... If I ever have the time I will try to check it again...But after I finish scripting a project for Battlezone...


Re: Format VS MYSQL_FORMAT - PowerPC603 - 30.01.2014

Format is good overall.
MySQL_format is usefull for creating queries for MySQL.

Format doesn't support %e, mysql_format does.
The %e is used for escaping strings to prevent mysql-injections.
It's basically identical to using mysql_real_escape_string.

The difference is that you first need to escape a string and store it in a variable, then insert the variable in a format, so you need 2 instructions to create escaped queries using format.
pawn Code:
new EscapedName[30], Query[128], Name[24];
GetPlayerName(playerid, Name, sizeof(Name));
mysql_real_escape_string(Name, EscapedName, ConnectionHandle);
format(Query, sizeof(Query), "INSERT INTO playerdata (PlayerName) VALUES ('%s')", EscapedName);
Using mysql_format and %e only requires 1 instruction so your code gets shorter and less complex.
pawn Code:
new Query[128], Name[24];
GetPlayerName(playerid, Name, sizeof(Name));
mysql_format(ConnectionHandle, Query, sizeof(Query), "INSERT INTO playerdata (PlayerName) VALUES ('%e')", Name);
As for speed, I haven't checked this yet.