Thanks for the help Desolation, but the function checks the number of arguments; all arguments must be passed at once.
I won't post the whole function, because it's long, but I'll post some usage examples. Note: The actual function prototype is very slightly different to what I posted above. (I left the initial arg out, because it didn't really change the question.)
It's a bit hard to tell since I don't really know exactly what your function does.
I wrote the function this way, because I like to call it as I did above (from C). The -1 is only there to ensure that the function can detect if insufficient arguments are passed in to describe all the placeholders.
PURPOSE: prepare and store a statement handle (sth) for later execution
INPUT: st_num - desired identification number for statement handle,
must be < NOS_OF_STHs. Used to refer to sth later,
and from Perl.
query - null terminated query string (passed to MySQL)
... - For each placeholder ("?") in query:
<> the type, as given in the enum enum_field_types
<> an integer which represents:
a) for string types: the length of the buffer needed to
store the largest value expected
b) for integer types: whether the integer is unsigned
The last argument must be -1.
OUTPUT: 0 - success
>0 - Failure. Returns an error code. If return value is > 10000, the
MySQL error code is also given as OUTPUT % 10000 (our error code
then equals (int)(OUTPUT / 10000))
int eDBi_make_sth(unsigned int st_num, const char *query, ...);
/* USAGE example */
if(eDBi_make_sth(1, "SELECT user_id, last_name FROM users WHERE age > ? AND first_name = ?",
/* handle error */
Usually, I call the function from C, which works well. But I'd like to be able to call it from Perl also. In order to do this, I need to be able to dynamically create the function call, like the switch statement in my first post did. However, there may be many placeholders in a query, so I'd prefer another method.