From: Christophe Genevey Metat Date: Thu, 19 May 2016 16:30:11 +0000 (+0000) Subject: GNUNET extract result libgnunetmy X-Git-Tag: initial-import-from-subversion-38251~861 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=81224501b6a9483907571508460e41617643050f;p=oweals%2Fgnunet.git GNUNET extract result libgnunetmy --- diff --git a/src/include/gnunet_my_lib.h b/src/include/gnunet_my_lib.h index b63ee9218..9a26022c8 100644 --- a/src/include/gnunet_my_lib.h +++ b/src/include/gnunet_my_lib.h @@ -95,7 +95,7 @@ struct GNUNET_MY_QueryParam /** * Information to pass to @e conv. Size of @a data. */ - unsigned long data_len; + unsigned long data_len ; }; @@ -222,13 +222,12 @@ GNUNET_MY_result_spec_fixed_size (void *ptr, */ #define GNUNET_MY_result_spec_auto_from_type(dst) GNUNET_MY_result_spec_fixed_size ((dst), sizeof (*(dst))) - /** * FIXME. + * */ int -GNUNET_MY_extract_result (struct GNUNET_MYSQL_Context *mc, - struct GNUNET_MYSQL_StatementHandle *stmt, +GNUNET_MY_extract_result (MYSQL_BIND * result, int row, struct GNUNET_MY_ResultSpec *specs); diff --git a/src/my/my.c b/src/my/my.c index 62b1ede09..71d30dd16 100644 --- a/src/my/my.c +++ b/src/my/my.c @@ -90,5 +90,49 @@ GNUNET_MY_exec_prepared (struct GNUNET_MYSQL_Context *mc, return GNUNET_OK; } +/** + * Extract results from a query result according + * to the given specification. If colums are NULL, + * the destination is not modified, and #GNUNET_NO is returned + * + * + * @param result + * @param row, the row from the result to extract + * @param result specificatio to extract for + * @return + #GNUNET_YES if all results could be extracted + #GNUNET_NO if at least one result was NULL + #GNUNET_SYSERR if a result was invalid +*/ +int +GNUNET_MY_extract_result (MYSQL_BIND * result, + int row, + struct GNUNET_MY_ResultSpec *specs) +{ + unsigned int i ; + int had_null = GNUNET_NO ; + int ret ; + + for(i = 0 ; NULL != specs[i].conv ; i++) + { + struct GNUNET_MY_ResultSpec * spec ; + + spec = &specs[i] ; + ret = spec->conv(spec->conv_cls, + NULL, //wait GNUNET_MY_QueryParam + result); + + if(ret == GNUNET_SYSERR) + return GNUNET_SYSERR ; + + if(spec->result_size != NULL) + *spec->result_size = spec->dst_size; + } + + if(GNUNET_YES == had_null) + return GNUNET_NO ; + + return GNUNET_OK ; +} /* end of my.c */