2 This file is part of GNUnet
3 Copyright (C) 2016 Inria & 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);
97 * Extract results from a query result according
98 * to the given specification. If colums are NULL,
99 * the destination is not modified, and #GNUNET_NO is returned4
103 * @param row, the row from the result to extract
104 * @param result specificatio to extract for
106 #GNUNET_YES if all results could be extracted
107 #GNUNET_NO if at least one result was NULL
108 #GNUNET_SYSERR if a result was invalid
111 GNUNET_MY_extract_result (MYSQL_BIND * result,
112 struct GNUNET_MY_QueryParam *qp,
113 struct GNUNET_MY_ResultSpec *rs,
117 int had_null = GNUNET_NO;
120 for (i = 0 ; NULL != rs[i].conv ; i++)
122 struct GNUNET_MY_ResultSpec *spec;
125 ret = spec->conv (spec->conv_cls,
129 if (GNUNET_SYSERR == ret)
131 //GNUNET_MY_cleanup_result(rs);
132 return GNUNET_SYSERR;
135 if (NULL != spec->result_size)
136 *spec->result_size = spec->dst_size;
139 if (GNUNET_YES == had_null)