Added new function kore_pgsql_v_query_params().

Same as kore_pgsql_query_params but takes a va_list as last parameter
(non-v version takes a variable list of parameters).

Lets people write easier to call wrappers around the query calls. I use
it in a wrapper that takes next states (error, current, continue) as
arguments in a handler with multiple async queries.
This commit is contained in:
Raphaël Monrouzeau 2016-06-07 13:12:31 +02:00
parent 2dfd22a79a
commit 159de3960d
2 changed files with 22 additions and 8 deletions

View File

@ -67,6 +67,8 @@ void kore_pgsql_continue(struct http_request *, struct kore_pgsql *);
int kore_pgsql_query(struct kore_pgsql *, const char *);
int kore_pgsql_query_params(struct kore_pgsql *,
const char *, int, u_int8_t, ...);
int kore_pgsql_v_query_params(struct kore_pgsql *,
const char *, int, u_int8_t, va_list);
int kore_pgsql_register(const char *, const char *);
int kore_pgsql_ntuples(struct kore_pgsql *);
void kore_pgsql_logerror(struct kore_pgsql *);

View File

@ -150,11 +150,10 @@ kore_pgsql_query(struct kore_pgsql *pgsql, const char *query)
}
int
kore_pgsql_query_params(struct kore_pgsql *pgsql,
const char *query, int result, u_int8_t count, ...)
kore_pgsql_v_query_params(struct kore_pgsql *pgsql,
const char *query, int result, u_int8_t count, va_list args)
{
u_int8_t i;
va_list args;
char **values;
int *lengths, *formats, ret;
@ -164,8 +163,6 @@ kore_pgsql_query_params(struct kore_pgsql *pgsql,
}
if (count > 0) {
va_start(args, count);
lengths = kore_calloc(count, sizeof(int));
formats = kore_calloc(count, sizeof(int));
values = kore_calloc(count, sizeof(char *));
@ -208,9 +205,6 @@ kore_pgsql_query_params(struct kore_pgsql *pgsql,
ret = KORE_RESULT_OK;
cleanup:
if (count > 0)
va_end(args);
kore_mem_free(values);
kore_mem_free(lengths);
kore_mem_free(formats);
@ -218,6 +212,24 @@ cleanup:
return (ret);
}
int
kore_pgsql_query_params(struct kore_pgsql *pgsql,
const char *query, int result, u_int8_t count, ...)
{
int ret;
va_list args;
if (count > 0)
va_start(args, count);
ret = kore_pgsql_v_query_params(pgsql, query, result, count, args);
if (count > 0)
va_end(args);
return (ret);
}
int
kore_pgsql_register(const char *dbname, const char *connstring)
{