01.04.2016, 12:43
db_queryf
db_query with arguments, allows you to format the query within the function!
Returns DBResult:x if query was successful (starts from DBResult:1)
Returns DBResult:0 if query was unsuccessful
Usage
The query will be "SELECT * FROM `Users` WHERE `Name` = 'Gammix'".
NOTE: You can use "%q" to escape strings as the function uses format internally.
db_query with arguments, allows you to format the query within the function!
Returns DBResult:x if query was successful (starts from DBResult:1)
Returns DBResult:0 if query was unsuccessful
pawn Код:
forward _fix_format();
public _fix_format()
{
format("", 0, "");
}
stock DBResult:db_queryf(DB:db, query[], {Float, _}:...)
{
static
args
;
args = numargs();
#define STATIC_ARGS (2)
if (args > STATIC_ARGS)
{
const
SIZE = 4024
;
static
dest[SIZE]
;
while (--args >= STATIC_ARGS)
{
#emit LCTRL 5
#emit LOAD.alt args
#emit SHL.C.alt 2
#emit ADD.C 12
#emit ADD
#emit LOAD.I
#emit PUSH.pri
}
#emit PUSH.S query
#emit PUSH.C SIZE
#emit PUSH.C dest
#emit LOAD.S.pri 8
#emit CONST.alt 16
#emit SUB
#emit PUSH.pri
#emit SYSREQ.C format
#emit LCTRL 5
#emit SCTRL 4
print(dest);
return db_query(db, dest);
}
else
{
return db_query(db, query);
}
#undef STATIC_ARGS
}
pawn Код:
db_queryf(DB:1, "SELECT * FROM `Users` WHERE `Name` = '%q'", "Gammix");
NOTE: You can use "%q" to escape strings as the function uses format internally.