/*
This file is part of GNUnet
- Copyright (C) 2016 GNUnet e.V.
+ Copyright (C) 2016 Inria & GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
/**
* @file my/my.c
* @brief library to help with access to a MySQL database
+ * @author Christophe Genevey
* @author Christian Grothoff
*/
#include "platform.h"
* @param mc mysql context
* @param sh handle to SELECT statment
* @param params parameters to the statement
- * @return
+ * @return
+ #GNUNET_YES if we can prepare all statement
+ #GNUNET_SYSERR if we can't prepare all statement
*/
+
int
GNUNET_MY_exec_prepared (struct GNUNET_MYSQL_Context *mc,
struct GNUNET_MYSQL_StatementHandle *sh,
GNUNET_MYSQL_statements_invalidate (mc);
return GNUNET_SYSERR;
}
+
}
if (mysql_stmt_execute (stmt))
{
GNUNET_MYSQL_statements_invalidate (mc);
return GNUNET_SYSERR;
}
+
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
+ * Extract results from a query result according
+ * to the given specification. If colums are NULL,
+ * the destination is not modified, and #GNUNET_NO is returned4
+ *
+ *
+ * @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)
+GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh,
+ struct GNUNET_MY_QueryParam *qp,
+ struct GNUNET_MY_ResultSpec *rs,
+ int row)
{
+ MYSQL_BIND *result;
unsigned int i;
int had_null = GNUNET_NO;
int ret;
+
+ MYSQL_STMT *stmt;
+
+ stmt = GNUNET_MYSQL_statement_get_stmt (NULL /* FIXME */, sh);
+ // result = mysql_get_result (stmt);
+ result = NULL;
+
+ if (mysql_stmt_bind_result(stmt, result))
+ {
+
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql",
+ _("`%s' failed at %s:%d with error: %s\n"),
+ "mysql_stmt_bind_result", __FILE__, __LINE__,
+ mysql_stmt_error (stmt));
+ return GNUNET_SYSERR;
+ }
- for(i = 0 ; NULL != specs[i].conv ; i++)
+ for (i = 0 ; NULL != rs[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)
+ spec = &rs[i];
+ ret = spec->conv (spec->conv_cls,
+ spec,
+ result);
+
+ if (GNUNET_SYSERR == ret)
+ {
return GNUNET_SYSERR;
+ }
- if(spec->result_size != NULL)
+ if (NULL != spec->result_size)
*spec->result_size = spec->dst_size;
}
-
- if(GNUNET_YES == had_null)
+
+ if (GNUNET_YES == had_null)
return GNUNET_NO;
return GNUNET_OK;
}
-/* end of my.c */
\ No newline at end of file
+/* end of my.c */