aboutsummaryrefslogtreecommitdiff
path: root/src/mysql
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-06-21 13:17:16 +0000
committerChristian Grothoff <christian@grothoff.org>2016-06-21 13:17:16 +0000
commit1732154b8c021e7ee0e34c28cf3b1a843454727a (patch)
tree3cb7fd79f409467c07d831ec055ebcdc8bfe61a2 /src/mysql
parent8919055de77f692ce3f0c1b9781fc9011de9cb6f (diff)
downloadgnunet-1732154b8c021e7ee0e34c28cf3b1a843454727a.tar.gz
gnunet-1732154b8c021e7ee0e34c28cf3b1a843454727a.zip
towards fixing mysql plugin
Diffstat (limited to 'src/mysql')
-rw-r--r--src/mysql/mysql.c48
1 files changed, 23 insertions, 25 deletions
diff --git a/src/mysql/mysql.c b/src/mysql/mysql.c
index ae77de9a7..7042d662e 100644
--- a/src/mysql/mysql.c
+++ b/src/mysql/mysql.c
@@ -104,6 +104,11 @@ struct GNUNET_MYSQL_StatementHandle
104 struct GNUNET_MYSQL_StatementHandle *prev; 104 struct GNUNET_MYSQL_StatementHandle *prev;
105 105
106 /** 106 /**
107 * Mysql Context the statement handle belongs to.
108 */
109 struct GNUNET_MYSQL_Context *mc;
110
111 /**
107 * Original query string. 112 * Original query string.
108 */ 113 */
109 char *query; 114 char *query;
@@ -366,6 +371,7 @@ GNUNET_MYSQL_statement_prepare (struct GNUNET_MYSQL_Context *mc,
366 struct GNUNET_MYSQL_StatementHandle *sh; 371 struct GNUNET_MYSQL_StatementHandle *sh;
367 372
368 sh = GNUNET_new (struct GNUNET_MYSQL_StatementHandle); 373 sh = GNUNET_new (struct GNUNET_MYSQL_StatementHandle);
374 sh->mc = mc;
369 sh->query = GNUNET_strdup (query); 375 sh->query = GNUNET_strdup (query);
370 GNUNET_CONTAINER_DLL_insert (mc->shead, mc->stail, sh); 376 GNUNET_CONTAINER_DLL_insert (mc->shead, mc->stail, sh);
371 return sh; 377 return sh;
@@ -404,9 +410,10 @@ GNUNET_MYSQL_statement_run (struct GNUNET_MYSQL_Context *mc, const char *sql)
404 * @return GNUNET_OK on success 410 * @return GNUNET_OK on success
405 */ 411 */
406static int 412static int
407prepare_statement (struct GNUNET_MYSQL_Context *mc, 413prepare_statement (struct GNUNET_MYSQL_StatementHandle *sh)
408 struct GNUNET_MYSQL_StatementHandle *sh)
409{ 414{
415 struct GNUNET_MYSQL_Context *mc = sh->mc;
416
410 if (GNUNET_YES == sh->valid) 417 if (GNUNET_YES == sh->valid)
411 return GNUNET_OK; 418 return GNUNET_OK;
412 if ((NULL == mc->dbf) && (GNUNET_OK != iopen (mc))) 419 if ((NULL == mc->dbf) && (GNUNET_OK != iopen (mc)))
@@ -435,15 +442,13 @@ prepare_statement (struct GNUNET_MYSQL_Context *mc,
435 * be used, and if, with caution! On failures during the interaction with 442 * be used, and if, with caution! On failures during the interaction with
436 * the handle, you must call 'GNUNET_MYSQL_statements_invalidate'! 443 * the handle, you must call 'GNUNET_MYSQL_statements_invalidate'!
437 * 444 *
438 * @param mc mysql context
439 * @param sh prepared statement to introspect 445 * @param sh prepared statement to introspect
440 * @return MySQL statement handle, NULL on error 446 * @return MySQL statement handle, NULL on error
441 */ 447 */
442MYSQL_STMT * 448MYSQL_STMT *
443GNUNET_MYSQL_statement_get_stmt (struct GNUNET_MYSQL_Context * mc, 449GNUNET_MYSQL_statement_get_stmt (struct GNUNET_MYSQL_StatementHandle *sh)
444 struct GNUNET_MYSQL_StatementHandle * sh)
445{ 450{
446 (void) prepare_statement (mc, sh); 451 (void) prepare_statement (sh);
447 return sh->statement; 452 return sh->statement;
448} 453}
449 454
@@ -452,15 +457,14 @@ GNUNET_MYSQL_statement_get_stmt (struct GNUNET_MYSQL_Context * mc,
452 * Bind the parameters for the given MySQL statement 457 * Bind the parameters for the given MySQL statement
453 * and run it. 458 * and run it.
454 * 459 *
455 * @param mc mysql context
456 * @param sh statement to bind and run 460 * @param sh statement to bind and run
457 * @param ap arguments for the binding 461 * @param ap arguments for the binding
458 * @return GNUNET_SYSERR on error, GNUNET_OK on success 462 * @return GNUNET_SYSERR on error, GNUNET_OK on success
459 */ 463 */
460static int 464static int
461init_params (struct GNUNET_MYSQL_Context *mc, 465init_params (struct GNUNET_MYSQL_StatementHandle *sh, va_list ap)
462 struct GNUNET_MYSQL_StatementHandle *sh, va_list ap)
463{ 466{
467 struct GNUNET_MYSQL_Context *mc = sh->mc;
464 MYSQL_BIND qbind[MAX_PARAM]; 468 MYSQL_BIND qbind[MAX_PARAM];
465 unsigned int pc; 469 unsigned int pc;
466 unsigned int off; 470 unsigned int off;
@@ -542,7 +546,6 @@ init_params (struct GNUNET_MYSQL_Context *mc,
542/** 546/**
543 * Run a prepared SELECT statement. 547 * Run a prepared SELECT statement.
544 * 548 *
545 * @param mc mysql context
546 * @param s statement to run 549 * @param s statement to run
547 * @param result_size number of elements in results array 550 * @param result_size number of elements in results array
548 * @param results pointer to already initialized MYSQL_BIND 551 * @param results pointer to already initialized MYSQL_BIND
@@ -556,8 +559,7 @@ init_params (struct GNUNET_MYSQL_Context *mc,
556 * the number of successfully affected (or queried) rows 559 * the number of successfully affected (or queried) rows
557 */ 560 */
558int 561int
559GNUNET_MYSQL_statement_run_prepared_select_va (struct GNUNET_MYSQL_Context *mc, 562GNUNET_MYSQL_statement_run_prepared_select_va (struct
560 struct
561 GNUNET_MYSQL_StatementHandle *s, 563 GNUNET_MYSQL_StatementHandle *s,
562 unsigned int result_size, 564 unsigned int result_size,
563 MYSQL_BIND * results, 565 MYSQL_BIND * results,
@@ -569,12 +571,12 @@ GNUNET_MYSQL_statement_run_prepared_select_va (struct GNUNET_MYSQL_Context *mc,
569 unsigned int rsize; 571 unsigned int rsize;
570 int total; 572 int total;
571 573
572 if (GNUNET_OK != prepare_statement (mc, s)) 574 if (GNUNET_OK != prepare_statement (s))
573 { 575 {
574 GNUNET_break (0); 576 GNUNET_break (0);
575 return GNUNET_SYSERR; 577 return GNUNET_SYSERR;
576 } 578 }
577 if (GNUNET_OK != init_params (mc, s, ap)) 579 if (GNUNET_OK != init_params (s, ap))
578 { 580 {
579 GNUNET_break (0); 581 GNUNET_break (0);
580 return GNUNET_SYSERR; 582 return GNUNET_SYSERR;
@@ -591,7 +593,7 @@ GNUNET_MYSQL_statement_run_prepared_select_va (struct GNUNET_MYSQL_Context *mc,
591 _("`%s' failed at %s:%d with error: %s\n"), 593 _("`%s' failed at %s:%d with error: %s\n"),
592 "mysql_stmt_bind_result", __FILE__, __LINE__, 594 "mysql_stmt_bind_result", __FILE__, __LINE__,
593 mysql_stmt_error (s->statement)); 595 mysql_stmt_error (s->statement));
594 GNUNET_MYSQL_statements_invalidate (mc); 596 GNUNET_MYSQL_statements_invalidate (s->mc);
595 return GNUNET_SYSERR; 597 return GNUNET_SYSERR;
596 } 598 }
597 599
@@ -607,7 +609,7 @@ GNUNET_MYSQL_statement_run_prepared_select_va (struct GNUNET_MYSQL_Context *mc,
607 _("`%s' failed at %s:%d with error: %s\n"), 609 _("`%s' failed at %s:%d with error: %s\n"),
608 "mysql_stmt_fetch", __FILE__, __LINE__, 610 "mysql_stmt_fetch", __FILE__, __LINE__,
609 mysql_stmt_error (s->statement)); 611 mysql_stmt_error (s->statement));
610 GNUNET_MYSQL_statements_invalidate (mc); 612 GNUNET_MYSQL_statements_invalidate (s->mc);
611 return GNUNET_SYSERR; 613 return GNUNET_SYSERR;
612 } 614 }
613 total++; 615 total++;
@@ -623,7 +625,6 @@ GNUNET_MYSQL_statement_run_prepared_select_va (struct GNUNET_MYSQL_Context *mc,
623/** 625/**
624 * Run a prepared SELECT statement. 626 * Run a prepared SELECT statement.
625 * 627 *
626 * @param mc mysql context
627 * @param sh handle to SELECT statment 628 * @param sh handle to SELECT statment
628 * @param result_size number of elements in results array 629 * @param result_size number of elements in results array
629 * @param results pointer to already initialized MYSQL_BIND 630 * @param results pointer to already initialized MYSQL_BIND
@@ -637,8 +638,7 @@ GNUNET_MYSQL_statement_run_prepared_select_va (struct GNUNET_MYSQL_Context *mc,
637 * the number of successfully affected (or queried) rows 638 * the number of successfully affected (or queried) rows
638 */ 639 */
639int 640int
640GNUNET_MYSQL_statement_run_prepared_select (struct GNUNET_MYSQL_Context *mc, 641GNUNET_MYSQL_statement_run_prepared_select (struct GNUNET_MYSQL_StatementHandle
641 struct GNUNET_MYSQL_StatementHandle
642 *sh, unsigned int result_size, 642 *sh, unsigned int result_size,
643 MYSQL_BIND * results, 643 MYSQL_BIND * results,
644 GNUNET_MYSQL_DataProcessor 644 GNUNET_MYSQL_DataProcessor
@@ -649,7 +649,7 @@ GNUNET_MYSQL_statement_run_prepared_select (struct GNUNET_MYSQL_Context *mc,
649 649
650 va_start (ap, processor_cls); 650 va_start (ap, processor_cls);
651 ret = 651 ret =
652 GNUNET_MYSQL_statement_run_prepared_select_va (mc, sh, result_size, 652 GNUNET_MYSQL_statement_run_prepared_select_va (sh, result_size,
653 results, processor, 653 results, processor,
654 processor_cls, ap); 654 processor_cls, ap);
655 va_end (ap); 655 va_end (ap);
@@ -660,7 +660,6 @@ GNUNET_MYSQL_statement_run_prepared_select (struct GNUNET_MYSQL_Context *mc,
660/** 660/**
661 * Run a prepared statement that does NOT produce results. 661 * Run a prepared statement that does NOT produce results.
662 * 662 *
663 * @param mc mysql context
664 * @param sh handle to statment 663 * @param sh handle to statment
665 * @param insert_id NULL or address where to store the row ID of whatever 664 * @param insert_id NULL or address where to store the row ID of whatever
666 * was inserted (only for INSERT statements!) 665 * was inserted (only for INSERT statements!)
@@ -671,17 +670,16 @@ GNUNET_MYSQL_statement_run_prepared_select (struct GNUNET_MYSQL_Context *mc,
671 * the number of successfully affected rows 670 * the number of successfully affected rows
672 */ 671 */
673int 672int
674GNUNET_MYSQL_statement_run_prepared (struct GNUNET_MYSQL_Context *mc, 673GNUNET_MYSQL_statement_run_prepared (struct GNUNET_MYSQL_StatementHandle *sh,
675 struct GNUNET_MYSQL_StatementHandle *sh,
676 unsigned long long *insert_id, ...) 674 unsigned long long *insert_id, ...)
677{ 675{
678 va_list ap; 676 va_list ap;
679 int affected; 677 int affected;
680 678
681 if (GNUNET_OK != prepare_statement (mc, sh)) 679 if (GNUNET_OK != prepare_statement (sh))
682 return GNUNET_SYSERR; 680 return GNUNET_SYSERR;
683 va_start (ap, insert_id); 681 va_start (ap, insert_id);
684 if (GNUNET_OK != init_params (mc, sh, ap)) 682 if (GNUNET_OK != init_params (sh, ap))
685 { 683 {
686 va_end (ap); 684 va_end (ap);
687 return GNUNET_SYSERR; 685 return GNUNET_SYSERR;