SA-MP Forums Archive
Function like format, 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: Function like format, mysql_format (/showthread.php?tid=504527)



Function like format, mysql_format - andyandyy8 - 04.04.2014

Hi!
I want to use a function for mysql_query something like Function("UPDATE players SET money=%s where id=%d",name,id);
Can I make something like this?
I tried all what i know...


Re: Function like format, mysql_format - Dignity - 04.04.2014

You want "function" to do what "mysql_query" does?

If so (top of your script);

pawn Код:
#define Function mysql_query
Should work.


Re: Function like format, mysql_format - Dokins - 04.04.2014

pawn Код:
new query[256];
format(query, sizeof(query), "UPDATE %s SET %s = %d WHERE id = %d LIMIT 1", tablename, fieldname, value, sqlid);
mysql_query(query);
It's simple, just create a string, format it and query it!

You can also replace the '%s' %d etc with actual values.

Of course if you need to retrieve them, do it like you would in a string.

Have fun dude!


Re: Function like format, mysql_format - andyandyy8 - 05.04.2014

You didn't understand what i want ...
I must to be more explicit...
I want a stock who combine mysql_format and mysql_query...
To execute query you must write only the query....
Function("UPDATE players SET age=%d where id=%d" age,id);


Re: Function like format, mysql_format - Dokins - 05.04.2014

pawn Код:
MySQL_SetInteger(sqlid, fieldname[], value, tablename[])
{
    new query[256];
    format(query, sizeof(query), "UPDATE %s SET %s = %d WHERE id = %d LIMIT 1", tablename, fieldname, value, sqlid);
    return mysql_query(query);
}



Re: Function like format, mysql_format - andyandyy8 - 05.04.2014

Thanks a lot !


Re: Function like format, mysql_format - Dokins - 05.04.2014

No problem, but I'd advise only to use this when updating a single value.

It may cause lag if used excessively.


Re: Function like format, mysql_format - andyandyy8 - 05.04.2014

Quote:

It may cause lag if used excessively.

Why?Is the same thing like
Quote:

format(query, sizeof(query), "UPDATE pl SET s = 5 WHERE id = 1 LIMIT 1");
mysql_query(query);

Why did you put there LIMIT 1?


Re: Function like format, mysql_format - Dokins - 05.04.2014

To limit the query to one update.