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
40 GNUNET_MY_exec_prepared (struct GNUNET_MYSQL_Context *mc,
41 struct GNUNET_MYSQL_StatementHandle *sh,
42 const struct GNUNET_MY_QueryParam *params)
44 const struct GNUNET_MY_QueryParam *p;
50 for (i=0;NULL != params[i].conv;i++)
51 num += params[i].num_params;
53 MYSQL_BIND qbind[num];
56 memset(qbind, 0, sizeof(qbind));
58 for (i=0;NULL != (p = ¶ms[i])->conv;i++)
69 stmt = GNUNET_MYSQL_statement_get_stmt (mc, sh);
70 if (mysql_stmt_bind_param (stmt,
73 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql",
74 _("`%s' failed at %s:%d with error: %s\n"),
75 "mysql_stmt_bind_param", __FILE__, __LINE__,
76 mysql_stmt_error (stmt));
77 GNUNET_MYSQL_statements_invalidate (mc);
81 if (mysql_stmt_execute (stmt))
83 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql",
84 _("`%s' failed at %s:%d with error: %s\n"),
85 "mysql_stmt_execute", __FILE__, __LINE__,
86 mysql_stmt_error (stmt));
87 GNUNET_MYSQL_statements_invalidate (mc);