tags:

views:

51

answers:

1

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
va_arg is not C89; #include <stdarg.h> is missing.
pmg