2 This file is part of GNUnet
3 Copyright (C) 2016 GNUnet e.V.
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @brief library to help with access to a MySQL database
23 * @author Christian Grothoff
26 #include <mysql/mysql.h>
27 #include "gnunet_my_lib.h"
32 * Run a prepared SELECT statement.
34 * @param mc mysql context
35 * @param sh handle to SELECT statment
36 * @param params parameters to the statement
37 * @return mysql result
40 /***** FIXE THIS FUNCTION *****/
42 GNUNET_MY_exec_prepared (struct GNUNET_MYSQL_Context *mc,
43 struct GNUNET_MYSQL_StatementHandle *sh,
44 const struct GNUNET_MY_QueryParam *params)
46 const struct GNUNET_MY_QueryParam *p;
52 for (i=0;NULL != params[i].conv;i++)
53 num += params[i].num_params;
55 MYSQL_BIND qbind[num];
58 memset(qbind, 0, sizeof(qbind));
60 for (i=0;NULL != (p = ¶ms[i])->conv;i++)
71 stmt = GNUNET_MYSQL_statement_get_stmt (mc, sh);
72 if (mysql_stmt_bind_param (stmt,
75 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql",
76 _("`%s' failed at %s:%d with error: %s\n"),
77 "mysql_stmt_bind_param", __FILE__, __LINE__,
78 mysql_stmt_error (stmt));
79 GNUNET_MYSQL_statements_invalidate (mc);
83 if (mysql_stmt_execute (stmt))
85 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql",
86 _("`%s' failed at %s:%d with error: %s\n"),
87 "mysql_stmt_execute", __FILE__, __LINE__,
88 mysql_stmt_error (stmt));
89 GNUNET_MYSQL_statements_invalidate (mc);
96 * Extract results from a query result according
97 * to the given specification. If colums are NULL,
98 * the destination is not modified, and #GNUNET_NO is returned
102 * @param row, the row from the result to extract
103 * @param result specificatio to extract for
105 #GNUNET_YES if all results could be extracted
106 #GNUNET_NO if at least one result was NULL
107 #GNUNET_SYSERR if a result was invalid
110 GNUNET_MY_extract_result (MYSQL_BIND * result,
111 struct GNUNET_MY_QueryParam *qp,
112 struct GNUNET_MY_ResultSpec *rs,
116 int had_null = GNUNET_NO;
119 for(i = 0 ; NULL != rs[i].conv ; i++)
121 struct GNUNET_MY_ResultSpec *spec;
124 ret = spec->conv(spec->conv_cls,
128 if(ret == GNUNET_SYSERR){
129 //GNUNET_MY_cleanup_result(rs);
130 return GNUNET_SYSERR;
133 if(spec->result_size != NULL)
134 *spec->result_size = spec->dst_size;
137 if(GNUNET_YES == had_null)