aboutsummaryrefslogtreecommitdiff
path: root/src/mysql/mysql.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mysql/mysql.c')
-rw-r--r--src/mysql/mysql.c358
1 files changed, 177 insertions, 181 deletions
diff --git a/src/mysql/mysql.c b/src/mysql/mysql.c
index c78fbeb4b..50f5683d7 100644
--- a/src/mysql/mysql.c
+++ b/src/mysql/mysql.c
@@ -12,12 +12,12 @@
12 WITHOUT ANY WARRANTY; without even the implied warranty of 12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Affero General Public License for more details. 14 Affero General Public License for more details.
15 15
16 You should have received a copy of the GNU Affero General Public License 16 You should have received a copy of the GNU Affero General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 18
19 SPDX-License-Identifier: AGPL3.0-or-later 19 SPDX-License-Identifier: AGPL3.0-or-later
20*/ 20 */
21/** 21/**
22 * @file mysql/mysql.c 22 * @file mysql/mysql.c
23 * @brief library to help with access to a MySQL database 23 * @brief library to help with access to a MySQL database
@@ -41,16 +41,16 @@
41 */ 41 */
42#define DIE_MYSQL(cmd, dbh) \ 42#define DIE_MYSQL(cmd, dbh) \
43 do \ 43 do \
44 { \ 44 { \
45 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, \ 45 GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, \
46 "mysql", \ 46 "mysql", \
47 _ ("`%s' failed at %s:%d with error: %s\n"), \ 47 _("`%s' failed at %s:%d with error: %s\n"), \
48 cmd, \ 48 cmd, \
49 __FILE__, \ 49 __FILE__, \
50 __LINE__, \ 50 __LINE__, \
51 mysql_error ((dbh)->dbf)); \ 51 mysql_error((dbh)->dbf)); \
52 GNUNET_assert (0); \ 52 GNUNET_assert(0); \
53 } while (0); 53 } while (0);
54 54
55/** 55/**
56 * Log an error message at log-level 'level' that indicates 56 * Log an error message at log-level 'level' that indicates
@@ -59,23 +59,21 @@
59 */ 59 */
60#define LOG_MYSQL(level, cmd, dbh) \ 60#define LOG_MYSQL(level, cmd, dbh) \
61 do \ 61 do \
62 { \ 62 { \
63 GNUNET_log_from (level, \ 63 GNUNET_log_from(level, \
64 "mysql", \ 64 "mysql", \
65 _ ("`%s' failed at %s:%d with error: %s\n"), \ 65 _("`%s' failed at %s:%d with error: %s\n"), \
66 cmd, \ 66 cmd, \
67 __FILE__, \ 67 __FILE__, \
68 __LINE__, \ 68 __LINE__, \
69 mysql_error ((dbh)->dbf)); \ 69 mysql_error((dbh)->dbf)); \
70 } while (0); 70 } while (0);
71 71
72 72
73/** 73/**
74 * Mysql context. 74 * Mysql context.
75 */ 75 */
76struct GNUNET_MYSQL_Context 76struct GNUNET_MYSQL_Context {
77{
78
79 /** 77 /**
80 * Our configuration. 78 * Our configuration.
81 */ 79 */
@@ -111,9 +109,7 @@ struct GNUNET_MYSQL_Context
111/** 109/**
112 * Handle for a prepared statement. 110 * Handle for a prepared statement.
113 */ 111 */
114struct GNUNET_MYSQL_StatementHandle 112struct GNUNET_MYSQL_StatementHandle {
115{
116
117 /** 113 /**
118 * Kept in a DLL. 114 * Kept in a DLL.
119 */ 115 */
@@ -154,8 +150,8 @@ struct GNUNET_MYSQL_StatementHandle
154 * @return NULL on error 150 * @return NULL on error
155 */ 151 */
156static char * 152static char *
157get_my_cnf_path (const struct GNUNET_CONFIGURATION_Handle *cfg, 153get_my_cnf_path(const struct GNUNET_CONFIGURATION_Handle *cfg,
158 const char *section) 154 const char *section)
159{ 155{
160 char *cnffile; 156 char *cnffile;
161 char *home_dir; 157 char *home_dir;
@@ -167,51 +163,51 @@ get_my_cnf_path (const struct GNUNET_CONFIGURATION_Handle *cfg,
167 int configured; 163 int configured;
168 164
169#ifndef WINDOWS 165#ifndef WINDOWS
170 pw = getpwuid (getuid ()); 166 pw = getpwuid(getuid());
171 if (! pw) 167 if (!pw)
172 { 168 {
173 GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_ERROR, "mysql", "getpwuid"); 169 GNUNET_log_from_strerror(GNUNET_ERROR_TYPE_ERROR, "mysql", "getpwuid");
174 return NULL; 170 return NULL;
175 } 171 }
176 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (cfg, section, "CONFIG")) 172 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value(cfg, section, "CONFIG"))
177 { 173 {
178 GNUNET_assert (GNUNET_OK == 174 GNUNET_assert(GNUNET_OK ==
179 GNUNET_CONFIGURATION_get_value_filename (cfg, 175 GNUNET_CONFIGURATION_get_value_filename(cfg,
180 section, 176 section,
181 "CONFIG", 177 "CONFIG",
182 &cnffile)); 178 &cnffile));
183 configured = GNUNET_YES; 179 configured = GNUNET_YES;
184 } 180 }
185 else 181 else
186 { 182 {
187 home_dir = GNUNET_strdup (pw->pw_dir); 183 home_dir = GNUNET_strdup(pw->pw_dir);
188 GNUNET_asprintf (&cnffile, "%s/.my.cnf", home_dir); 184 GNUNET_asprintf(&cnffile, "%s/.my.cnf", home_dir);
189 GNUNET_free (home_dir); 185 GNUNET_free(home_dir);
190 configured = GNUNET_NO; 186 configured = GNUNET_NO;
191 } 187 }
192#else 188#else
193 home_dir = (char *) GNUNET_malloc (_MAX_PATH + 1); 189 home_dir = (char *)GNUNET_malloc(_MAX_PATH + 1);
194 plibc_conv_to_win_path ("~/", home_dir); 190 plibc_conv_to_win_path("~/", home_dir);
195 GNUNET_asprintf (&cnffile, "%s/.my.cnf", home_dir); 191 GNUNET_asprintf(&cnffile, "%s/.my.cnf", home_dir);
196 GNUNET_free (home_dir); 192 GNUNET_free(home_dir);
197 configured = GNUNET_NO; 193 configured = GNUNET_NO;
198#endif 194#endif
199 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, 195 GNUNET_log_from(GNUNET_ERROR_TYPE_INFO,
200 "mysql", 196 "mysql",
201 _ ("Trying to use file `%s' for MySQL configuration.\n"), 197 _("Trying to use file `%s' for MySQL configuration.\n"),
202 cnffile); 198 cnffile);
203 if ((0 != STAT (cnffile, &st)) || (0 != ACCESS (cnffile, R_OK)) || 199 if ((0 != STAT(cnffile, &st)) || (0 != ACCESS(cnffile, R_OK)) ||
204 (! S_ISREG (st.st_mode))) 200 (!S_ISREG(st.st_mode)))
205 { 201 {
206 if (configured == GNUNET_YES) 202 if (configured == GNUNET_YES)
207 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 203 GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR,
208 "mysql", 204 "mysql",
209 _ ("Could not access file `%s': %s\n"), 205 _("Could not access file `%s': %s\n"),
210 cnffile, 206 cnffile,
211 strerror (errno)); 207 strerror(errno));
212 GNUNET_free (cnffile); 208 GNUNET_free(cnffile);
213 return NULL; 209 return NULL;
214 } 210 }
215 return cnffile; 211 return cnffile;
216} 212}
217 213
@@ -224,7 +220,7 @@ get_my_cnf_path (const struct GNUNET_CONFIGURATION_Handle *cfg,
224 * @return #GNUNET_OK on success 220 * @return #GNUNET_OK on success
225 */ 221 */
226static int 222static int
227iopen (struct GNUNET_MYSQL_Context *mc) 223iopen(struct GNUNET_MYSQL_Context *mc)
228{ 224{
229 char *mysql_dbname; 225 char *mysql_dbname;
230 char *mysql_server; 226 char *mysql_server;
@@ -234,88 +230,88 @@ iopen (struct GNUNET_MYSQL_Context *mc)
234 my_bool reconnect; 230 my_bool reconnect;
235 unsigned int timeout; 231 unsigned int timeout;
236 232
237 mc->dbf = mysql_init (NULL); 233 mc->dbf = mysql_init(NULL);
238 if (mc->dbf == NULL) 234 if (mc->dbf == NULL)
239 return GNUNET_SYSERR; 235 return GNUNET_SYSERR;
240 if (mc->cnffile != NULL) 236 if (mc->cnffile != NULL)
241 mysql_options (mc->dbf, MYSQL_READ_DEFAULT_FILE, mc->cnffile); 237 mysql_options(mc->dbf, MYSQL_READ_DEFAULT_FILE, mc->cnffile);
242 mysql_options (mc->dbf, MYSQL_READ_DEFAULT_GROUP, "client"); 238 mysql_options(mc->dbf, MYSQL_READ_DEFAULT_GROUP, "client");
243 reconnect = 0; 239 reconnect = 0;
244 mysql_options (mc->dbf, MYSQL_OPT_RECONNECT, &reconnect); 240 mysql_options(mc->dbf, MYSQL_OPT_RECONNECT, &reconnect);
245 mysql_options (mc->dbf, MYSQL_OPT_CONNECT_TIMEOUT, (const void *) &timeout); 241 mysql_options(mc->dbf, MYSQL_OPT_CONNECT_TIMEOUT, (const void *)&timeout);
246 mysql_options (mc->dbf, MYSQL_SET_CHARSET_NAME, "UTF8"); 242 mysql_options(mc->dbf, MYSQL_SET_CHARSET_NAME, "UTF8");
247 timeout = 60; /* in seconds */ 243 timeout = 60; /* in seconds */
248 mysql_options (mc->dbf, MYSQL_OPT_READ_TIMEOUT, (const void *) &timeout); 244 mysql_options(mc->dbf, MYSQL_OPT_READ_TIMEOUT, (const void *)&timeout);
249 mysql_options (mc->dbf, MYSQL_OPT_WRITE_TIMEOUT, (const void *) &timeout); 245 mysql_options(mc->dbf, MYSQL_OPT_WRITE_TIMEOUT, (const void *)&timeout);
250 mysql_dbname = NULL; 246 mysql_dbname = NULL;
251 if (GNUNET_YES == 247 if (GNUNET_YES ==
252 GNUNET_CONFIGURATION_have_value (mc->cfg, mc->section, "DATABASE")) 248 GNUNET_CONFIGURATION_have_value(mc->cfg, mc->section, "DATABASE"))
253 GNUNET_assert (GNUNET_OK == 249 GNUNET_assert(GNUNET_OK ==
254 GNUNET_CONFIGURATION_get_value_string (mc->cfg, 250 GNUNET_CONFIGURATION_get_value_string(mc->cfg,
255 mc->section, 251 mc->section,
256 "DATABASE", 252 "DATABASE",
257 &mysql_dbname)); 253 &mysql_dbname));
258 else 254 else
259 mysql_dbname = GNUNET_strdup ("gnunet"); 255 mysql_dbname = GNUNET_strdup("gnunet");
260 mysql_user = NULL; 256 mysql_user = NULL;
261 if (GNUNET_YES == 257 if (GNUNET_YES ==
262 GNUNET_CONFIGURATION_have_value (mc->cfg, mc->section, "USER")) 258 GNUNET_CONFIGURATION_have_value(mc->cfg, mc->section, "USER"))
263 { 259 {
264 GNUNET_assert (GNUNET_OK == 260 GNUNET_assert(GNUNET_OK ==
265 GNUNET_CONFIGURATION_get_value_string (mc->cfg, 261 GNUNET_CONFIGURATION_get_value_string(mc->cfg,
266 mc->section, 262 mc->section,
267 "USER", 263 "USER",
268 &mysql_user)); 264 &mysql_user));
269 } 265 }
270 mysql_password = NULL; 266 mysql_password = NULL;
271 if (GNUNET_YES == 267 if (GNUNET_YES ==
272 GNUNET_CONFIGURATION_have_value (mc->cfg, mc->section, "PASSWORD")) 268 GNUNET_CONFIGURATION_have_value(mc->cfg, mc->section, "PASSWORD"))
273 { 269 {
274 GNUNET_assert (GNUNET_OK == 270 GNUNET_assert(GNUNET_OK ==
275 GNUNET_CONFIGURATION_get_value_string (mc->cfg, 271 GNUNET_CONFIGURATION_get_value_string(mc->cfg,
276 mc->section, 272 mc->section,
277 "PASSWORD", 273 "PASSWORD",
278 &mysql_password)); 274 &mysql_password));
279 } 275 }
280 mysql_server = NULL; 276 mysql_server = NULL;
281 if (GNUNET_YES == 277 if (GNUNET_YES ==
282 GNUNET_CONFIGURATION_have_value (mc->cfg, mc->section, "HOST")) 278 GNUNET_CONFIGURATION_have_value(mc->cfg, mc->section, "HOST"))
283 { 279 {
284 GNUNET_assert (GNUNET_OK == 280 GNUNET_assert(GNUNET_OK ==
285 GNUNET_CONFIGURATION_get_value_string (mc->cfg, 281 GNUNET_CONFIGURATION_get_value_string(mc->cfg,
286 mc->section, 282 mc->section,
287 "HOST", 283 "HOST",
288 &mysql_server)); 284 &mysql_server));
289 } 285 }
290 mysql_port = 0; 286 mysql_port = 0;
291 if (GNUNET_YES == 287 if (GNUNET_YES ==
292 GNUNET_CONFIGURATION_have_value (mc->cfg, mc->section, "PORT")) 288 GNUNET_CONFIGURATION_have_value(mc->cfg, mc->section, "PORT"))
293 { 289 {
294 GNUNET_assert (GNUNET_OK == 290 GNUNET_assert(GNUNET_OK ==
295 GNUNET_CONFIGURATION_get_value_number (mc->cfg, 291 GNUNET_CONFIGURATION_get_value_number(mc->cfg,
296 mc->section, 292 mc->section,
297 "PORT", 293 "PORT",
298 &mysql_port)); 294 &mysql_port));
299 } 295 }
300 296
301 GNUNET_assert (mysql_dbname != NULL); 297 GNUNET_assert(mysql_dbname != NULL);
302 mysql_real_connect (mc->dbf, 298 mysql_real_connect(mc->dbf,
303 mysql_server, 299 mysql_server,
304 mysql_user, 300 mysql_user,
305 mysql_password, 301 mysql_password,
306 mysql_dbname, 302 mysql_dbname,
307 (unsigned int) mysql_port, 303 (unsigned int)mysql_port,
308 NULL, 304 NULL,
309 CLIENT_IGNORE_SIGPIPE); 305 CLIENT_IGNORE_SIGPIPE);
310 GNUNET_free_non_null (mysql_server); 306 GNUNET_free_non_null(mysql_server);
311 GNUNET_free_non_null (mysql_user); 307 GNUNET_free_non_null(mysql_user);
312 GNUNET_free_non_null (mysql_password); 308 GNUNET_free_non_null(mysql_password);
313 GNUNET_free (mysql_dbname); 309 GNUNET_free(mysql_dbname);
314 if (mysql_error (mc->dbf)[0]) 310 if (mysql_error(mc->dbf)[0])
315 { 311 {
316 LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, "mysql_real_connect", mc); 312 LOG_MYSQL(GNUNET_ERROR_TYPE_ERROR, "mysql_real_connect", mc);
317 return GNUNET_SYSERR; 313 return GNUNET_SYSERR;
318 } 314 }
319 return GNUNET_OK; 315 return GNUNET_OK;
320} 316}
321 317
@@ -328,15 +324,15 @@ iopen (struct GNUNET_MYSQL_Context *mc)
328 * @return the mysql context 324 * @return the mysql context
329 */ 325 */
330struct GNUNET_MYSQL_Context * 326struct GNUNET_MYSQL_Context *
331GNUNET_MYSQL_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg, 327GNUNET_MYSQL_context_create(const struct GNUNET_CONFIGURATION_Handle *cfg,
332 const char *section) 328 const char *section)
333{ 329{
334 struct GNUNET_MYSQL_Context *mc; 330 struct GNUNET_MYSQL_Context *mc;
335 331
336 mc = GNUNET_new (struct GNUNET_MYSQL_Context); 332 mc = GNUNET_new(struct GNUNET_MYSQL_Context);
337 mc->cfg = cfg; 333 mc->cfg = cfg;
338 mc->section = section; 334 mc->section = section;
339 mc->cnffile = get_my_cnf_path (cfg, section); 335 mc->cnffile = get_my_cnf_path(cfg, section);
340 336
341 return mc; 337 return mc;
342} 338}
@@ -349,24 +345,24 @@ GNUNET_MYSQL_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
349 * @param mc mysql context 345 * @param mc mysql context
350 */ 346 */
351void 347void
352GNUNET_MYSQL_statements_invalidate (struct GNUNET_MYSQL_Context *mc) 348GNUNET_MYSQL_statements_invalidate(struct GNUNET_MYSQL_Context *mc)
353{ 349{
354 struct GNUNET_MYSQL_StatementHandle *sh; 350 struct GNUNET_MYSQL_StatementHandle *sh;
355 351
356 for (sh = mc->shead; NULL != sh; sh = sh->next) 352 for (sh = mc->shead; NULL != sh; sh = sh->next)
357 {
358 if (GNUNET_YES == sh->valid)
359 { 353 {
360 mysql_stmt_close (sh->statement); 354 if (GNUNET_YES == sh->valid)
361 sh->valid = GNUNET_NO; 355 {
356 mysql_stmt_close(sh->statement);
357 sh->valid = GNUNET_NO;
358 }
359 sh->statement = NULL;
362 } 360 }
363 sh->statement = NULL;
364 }
365 if (NULL != mc->dbf) 361 if (NULL != mc->dbf)
366 { 362 {
367 mysql_close (mc->dbf); 363 mysql_close(mc->dbf);
368 mc->dbf = NULL; 364 mc->dbf = NULL;
369 } 365 }
370} 366}
371 367
372 368
@@ -376,19 +372,19 @@ GNUNET_MYSQL_statements_invalidate (struct GNUNET_MYSQL_Context *mc)
376 * @param mc context to destroy 372 * @param mc context to destroy
377 */ 373 */
378void 374void
379GNUNET_MYSQL_context_destroy (struct GNUNET_MYSQL_Context *mc) 375GNUNET_MYSQL_context_destroy(struct GNUNET_MYSQL_Context *mc)
380{ 376{
381 struct GNUNET_MYSQL_StatementHandle *sh; 377 struct GNUNET_MYSQL_StatementHandle *sh;
382 378
383 GNUNET_MYSQL_statements_invalidate (mc); 379 GNUNET_MYSQL_statements_invalidate(mc);
384 while (NULL != (sh = mc->shead)) 380 while (NULL != (sh = mc->shead))
385 { 381 {
386 GNUNET_CONTAINER_DLL_remove (mc->shead, mc->stail, sh); 382 GNUNET_CONTAINER_DLL_remove(mc->shead, mc->stail, sh);
387 GNUNET_free (sh->query); 383 GNUNET_free(sh->query);
388 GNUNET_free (sh); 384 GNUNET_free(sh);
389 } 385 }
390 GNUNET_free (mc); 386 GNUNET_free(mc);
391 mysql_library_end (); 387 mysql_library_end();
392} 388}
393 389
394 390
@@ -401,15 +397,15 @@ GNUNET_MYSQL_context_destroy (struct GNUNET_MYSQL_Context *mc)
401 * @return prepared statement, NULL on error 397 * @return prepared statement, NULL on error
402 */ 398 */
403struct GNUNET_MYSQL_StatementHandle * 399struct GNUNET_MYSQL_StatementHandle *
404GNUNET_MYSQL_statement_prepare (struct GNUNET_MYSQL_Context *mc, 400GNUNET_MYSQL_statement_prepare(struct GNUNET_MYSQL_Context *mc,
405 const char *query) 401 const char *query)
406{ 402{
407 struct GNUNET_MYSQL_StatementHandle *sh; 403 struct GNUNET_MYSQL_StatementHandle *sh;
408 404
409 sh = GNUNET_new (struct GNUNET_MYSQL_StatementHandle); 405 sh = GNUNET_new(struct GNUNET_MYSQL_StatementHandle);
410 sh->mc = mc; 406 sh->mc = mc;
411 sh->query = GNUNET_strdup (query); 407 sh->query = GNUNET_strdup(query);
412 GNUNET_CONTAINER_DLL_insert (mc->shead, mc->stail, sh); 408 GNUNET_CONTAINER_DLL_insert(mc->shead, mc->stail, sh);
413 return sh; 409 return sh;
414} 410}
415 411
@@ -423,17 +419,17 @@ GNUNET_MYSQL_statement_prepare (struct GNUNET_MYSQL_Context *mc,
423 * #GNUNET_SYSERR if there was a problem 419 * #GNUNET_SYSERR if there was a problem
424 */ 420 */
425int 421int
426GNUNET_MYSQL_statement_run (struct GNUNET_MYSQL_Context *mc, const char *sql) 422GNUNET_MYSQL_statement_run(struct GNUNET_MYSQL_Context *mc, const char *sql)
427{ 423{
428 if ((NULL == mc->dbf) && (GNUNET_OK != iopen (mc))) 424 if ((NULL == mc->dbf) && (GNUNET_OK != iopen(mc)))
429 return GNUNET_SYSERR;
430 mysql_query (mc->dbf, sql);
431 if (mysql_error (mc->dbf)[0])
432 {
433 LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, "mysql_query", mc);
434 GNUNET_MYSQL_statements_invalidate (mc);
435 return GNUNET_SYSERR; 425 return GNUNET_SYSERR;
436 } 426 mysql_query(mc->dbf, sql);
427 if (mysql_error(mc->dbf)[0])
428 {
429 LOG_MYSQL(GNUNET_ERROR_TYPE_ERROR, "mysql_query", mc);
430 GNUNET_MYSQL_statements_invalidate(mc);
431 return GNUNET_SYSERR;
432 }
437 return GNUNET_OK; 433 return GNUNET_OK;
438} 434}
439 435
@@ -446,32 +442,32 @@ GNUNET_MYSQL_statement_run (struct GNUNET_MYSQL_Context *mc, const char *sql)
446 * @return #GNUNET_OK on success 442 * @return #GNUNET_OK on success
447 */ 443 */
448static int 444static int
449prepare_statement (struct GNUNET_MYSQL_StatementHandle *sh) 445prepare_statement(struct GNUNET_MYSQL_StatementHandle *sh)
450{ 446{
451 struct GNUNET_MYSQL_Context *mc = sh->mc; 447 struct GNUNET_MYSQL_Context *mc = sh->mc;
452 448
453 if (GNUNET_YES == sh->valid) 449 if (GNUNET_YES == sh->valid)
454 return GNUNET_OK; 450 return GNUNET_OK;
455 if ((NULL == mc->dbf) && (GNUNET_OK != iopen (mc))) 451 if ((NULL == mc->dbf) && (GNUNET_OK != iopen(mc)))
456 return GNUNET_SYSERR; 452 return GNUNET_SYSERR;
457 sh->statement = mysql_stmt_init (mc->dbf); 453 sh->statement = mysql_stmt_init(mc->dbf);
458 if (NULL == sh->statement) 454 if (NULL == sh->statement)
459 { 455 {
460 GNUNET_MYSQL_statements_invalidate (mc); 456 GNUNET_MYSQL_statements_invalidate(mc);
461 return GNUNET_SYSERR; 457 return GNUNET_SYSERR;
462 } 458 }
463 if (0 != mysql_stmt_prepare (sh->statement, sh->query, strlen (sh->query))) 459 if (0 != mysql_stmt_prepare(sh->statement, sh->query, strlen(sh->query)))
464 { 460 {
465 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 461 GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR,
466 "mysql", 462 "mysql",
467 "prepare_statement: %s\n", 463 "prepare_statement: %s\n",
468 sh->query); 464 sh->query);
469 LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, "mysql_stmt_prepare", mc); 465 LOG_MYSQL(GNUNET_ERROR_TYPE_ERROR, "mysql_stmt_prepare", mc);
470 mysql_stmt_close (sh->statement); 466 mysql_stmt_close(sh->statement);
471 sh->statement = NULL; 467 sh->statement = NULL;
472 GNUNET_MYSQL_statements_invalidate (mc); 468 GNUNET_MYSQL_statements_invalidate(mc);
473 return GNUNET_SYSERR; 469 return GNUNET_SYSERR;
474 } 470 }
475 sh->valid = GNUNET_YES; 471 sh->valid = GNUNET_YES;
476 return GNUNET_OK; 472 return GNUNET_OK;
477} 473}
@@ -486,9 +482,9 @@ prepare_statement (struct GNUNET_MYSQL_StatementHandle *sh)
486 * @return MySQL statement handle, NULL on error 482 * @return MySQL statement handle, NULL on error
487 */ 483 */
488MYSQL_STMT * 484MYSQL_STMT *
489GNUNET_MYSQL_statement_get_stmt (struct GNUNET_MYSQL_StatementHandle *sh) 485GNUNET_MYSQL_statement_get_stmt(struct GNUNET_MYSQL_StatementHandle *sh)
490{ 486{
491 (void) prepare_statement (sh); 487 (void)prepare_statement(sh);
492 return sh->statement; 488 return sh->statement;
493} 489}
494 490