I wish to Call mysql_real_escape on each argument of a vararg list before it is then passed on to vsprintf to include into an SQL string, is there anyway I can do this easilly? Seems I missed prepared statements, this seems to be usefull though anyway.
+2
A:
Call va_start()
(and va_end()
) twice.
The first time in a loop with va_arg()
inside to test (and change) each argument;
and the next time for vsprintf
/* check args */
va_start(val, parm);
while (MORE_ARGUMENTS) {
arg = va_arg(val, char*);
/* mysql_real_escape(arg); */
}
va_end(val);
/* print */
va_start(val, parm);
vsprintf(buf, FORMAT_STRING, val);
va_end(val);
pmg
2010-09-18 17:02:30
va_arg is not C89; #include <stdarg.h> is missing.
2010-09-18 20:30:58
pmg
2010-09-18 20:54:55