summaryrefslogtreecommitdiff
path: root/src/mysql
diff options
context:
space:
mode:
authorChristophe Genevey Metat <genevey.christophe@gmail.com>2016-06-28 09:47:01 +0000
committerChristophe Genevey Metat <genevey.christophe@gmail.com>2016-06-28 09:47:01 +0000
commit9a514bfb0dd7b656d9c4eb14aa196102c1e3593b (patch)
treef8b4d3cb62f6dcd0abfafcad02b1d88fa9fba830 /src/mysql
parente3ae6d9f6ac5f5e121f252cdd1d1796933d3fc42 (diff)
downloadgnunet-9a514bfb0dd7b656d9c4eb14aa196102c1e3593b.tar.gz
gnunet-9a514bfb0dd7b656d9c4eb14aa196102c1e3593b.zip
delete mysql function
Diffstat (limited to 'src/mysql')
-rw-r--r--src/mysql/mysql.c240
1 files changed, 0 insertions, 240 deletions
diff --git a/src/mysql/mysql.c b/src/mysql/mysql.c
index 7042d662e..acd54a288 100644
--- a/src/mysql/mysql.c
+++ b/src/mysql/mysql.c
@@ -453,244 +453,4 @@ GNUNET_MYSQL_statement_get_stmt (struct GNUNET_MYSQL_StatementHandle *sh)
453} 453}
454 454
455 455
456/**
457 * Bind the parameters for the given MySQL statement
458 * and run it.
459 *
460 * @param sh statement to bind and run
461 * @param ap arguments for the binding
462 * @return GNUNET_SYSERR on error, GNUNET_OK on success
463 */
464static int
465init_params (struct GNUNET_MYSQL_StatementHandle *sh, va_list ap)
466{
467 struct GNUNET_MYSQL_Context *mc = sh->mc;
468 MYSQL_BIND qbind[MAX_PARAM];
469 unsigned int pc;
470 unsigned int off;
471 enum enum_field_types ft;
472
473 pc = mysql_stmt_param_count (sh->statement);
474 if (pc > MAX_PARAM)
475 {
476 /* increase internal constant! */
477 GNUNET_break (0);
478 return GNUNET_SYSERR;
479 }
480 memset (qbind, 0, sizeof (qbind));
481 off = 0;
482 ft = 0;
483 while ((pc > 0) && (-1 != (int) (ft = va_arg (ap, enum enum_field_types))))
484 {
485 qbind[off].buffer_type = ft;
486 switch (ft)
487 {
488 case MYSQL_TYPE_FLOAT:
489 qbind[off].buffer = va_arg (ap, float *);
490
491 break;
492 case MYSQL_TYPE_LONGLONG:
493 qbind[off].buffer = va_arg (ap, unsigned long long *);
494 qbind[off].is_unsigned = va_arg (ap, int);
495
496 break;
497 case MYSQL_TYPE_LONG:
498 qbind[off].buffer = va_arg (ap, unsigned int *);
499 qbind[off].is_unsigned = va_arg (ap, int);
500
501 break;
502 case MYSQL_TYPE_VAR_STRING:
503 case MYSQL_TYPE_STRING:
504 case MYSQL_TYPE_BLOB:
505 qbind[off].buffer = va_arg (ap, void *);
506 qbind[off].buffer_length = va_arg (ap, unsigned long);
507 qbind[off].length = va_arg (ap, unsigned long *);
508
509 break;
510 default:
511 /* unsupported type */
512 GNUNET_break (0);
513 return GNUNET_SYSERR;
514 }
515 pc--;
516 off++;
517 }
518 if (!((pc == 0) && (-1 != (int) ft) && (va_arg (ap, int) == -1)))
519 {
520 GNUNET_break (0);
521 return GNUNET_SYSERR;
522 }
523 if (mysql_stmt_bind_param (sh->statement, qbind))
524 {
525 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql",
526 _("`%s' failed at %s:%d with error: %s\n"),
527 "mysql_stmt_bind_param", __FILE__, __LINE__,
528 mysql_stmt_error (sh->statement));
529 GNUNET_MYSQL_statements_invalidate (mc);
530 return GNUNET_SYSERR;
531 }
532 if (mysql_stmt_execute (sh->statement))
533 {
534 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql",
535 _("`%s' failed at %s:%d with error: %s\n"),
536 "mysql_stmt_execute", __FILE__, __LINE__,
537 mysql_stmt_error (sh->statement));
538 GNUNET_MYSQL_statements_invalidate (mc);
539 return GNUNET_SYSERR;
540 }
541 return GNUNET_OK;
542}
543
544
545
546/**
547 * Run a prepared SELECT statement.
548 *
549 * @param s statement to run
550 * @param result_size number of elements in results array
551 * @param results pointer to already initialized MYSQL_BIND
552 * array (of sufficient size) for passing results
553 * @param processor function to call on each result
554 * @param processor_cls extra argument to processor
555 * @param ap pairs and triplets of "MYSQL_TYPE_XXX" keys and their respective
556 * values (size + buffer-reference for pointers); terminated
557 * with "-1"
558 * @return GNUNET_SYSERR on error, otherwise
559 * the number of successfully affected (or queried) rows
560 */
561int
562GNUNET_MYSQL_statement_run_prepared_select_va (struct
563 GNUNET_MYSQL_StatementHandle *s,
564 unsigned int result_size,
565 MYSQL_BIND * results,
566 GNUNET_MYSQL_DataProcessor
567 processor, void *processor_cls,
568 va_list ap)
569{
570 int ret;
571 unsigned int rsize;
572 int total;
573
574 if (GNUNET_OK != prepare_statement (s))
575 {
576 GNUNET_break (0);
577 return GNUNET_SYSERR;
578 }
579 if (GNUNET_OK != init_params (s, ap))
580 {
581 GNUNET_break (0);
582 return GNUNET_SYSERR;
583 }
584 rsize = mysql_stmt_field_count (s->statement);
585 if (rsize > result_size)
586 {
587 GNUNET_break (0);
588 return GNUNET_SYSERR;
589 }
590 if (mysql_stmt_bind_result (s->statement, results))
591 {
592 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
593 _("`%s' failed at %s:%d with error: %s\n"),
594 "mysql_stmt_bind_result", __FILE__, __LINE__,
595 mysql_stmt_error (s->statement));
596 GNUNET_MYSQL_statements_invalidate (s->mc);
597 return GNUNET_SYSERR;
598 }
599
600 total = 0;
601 while (1)
602 {
603 ret = mysql_stmt_fetch (s->statement);
604 if (ret == MYSQL_NO_DATA)
605 break;
606 if (ret != 0)
607 {
608 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql",
609 _("`%s' failed at %s:%d with error: %s\n"),
610 "mysql_stmt_fetch", __FILE__, __LINE__,
611 mysql_stmt_error (s->statement));
612 GNUNET_MYSQL_statements_invalidate (s->mc);
613 return GNUNET_SYSERR;
614 }
615 total++;
616 if ((NULL == processor) ||
617 (GNUNET_OK != processor (processor_cls, rsize, results)))
618 break;
619 }
620 mysql_stmt_reset (s->statement);
621 return total;
622}
623
624
625/**
626 * Run a prepared SELECT statement.
627 *
628 * @param sh handle to SELECT statment
629 * @param result_size number of elements in results array
630 * @param results pointer to already initialized MYSQL_BIND
631 * array (of sufficient size) for passing results
632 * @param processor function to call on each result
633 * @param processor_cls extra argument to processor
634 * @param ... pairs and triplets of "MYSQL_TYPE_XXX" keys and their respective
635 * values (size + buffer-reference for pointers); terminated
636 * with "-1"
637 * @return GNUNET_SYSERR on error, otherwise
638 * the number of successfully affected (or queried) rows
639 */
640int
641GNUNET_MYSQL_statement_run_prepared_select (struct GNUNET_MYSQL_StatementHandle
642 *sh, unsigned int result_size,
643 MYSQL_BIND * results,
644 GNUNET_MYSQL_DataProcessor
645 processor, void *processor_cls, ...)
646{
647 va_list ap;
648 int ret;
649
650 va_start (ap, processor_cls);
651 ret =
652 GNUNET_MYSQL_statement_run_prepared_select_va (sh, result_size,
653 results, processor,
654 processor_cls, ap);
655 va_end (ap);
656 return ret;
657}
658
659
660/**
661 * Run a prepared statement that does NOT produce results.
662 *
663 * @param sh handle to statment
664 * @param insert_id NULL or address where to store the row ID of whatever
665 * was inserted (only for INSERT statements!)
666 * @param ... pairs and triplets of "MYSQL_TYPE_XXX" keys and their respective
667 * values (size + buffer-reference for pointers); terminated
668 * with "-1"
669 * @return GNUNET_SYSERR on error, otherwise
670 * the number of successfully affected rows
671 */
672int
673GNUNET_MYSQL_statement_run_prepared (struct GNUNET_MYSQL_StatementHandle *sh,
674 unsigned long long *insert_id, ...)
675{
676 va_list ap;
677 int affected;
678
679 if (GNUNET_OK != prepare_statement (sh))
680 return GNUNET_SYSERR;
681 va_start (ap, insert_id);
682 if (GNUNET_OK != init_params (sh, ap))
683 {
684 va_end (ap);
685 return GNUNET_SYSERR;
686 }
687 va_end (ap);
688 affected = mysql_stmt_affected_rows (sh->statement);
689 if (NULL != insert_id)
690 *insert_id = (unsigned long long) mysql_stmt_insert_id (sh->statement);
691 mysql_stmt_reset (sh->statement);
692 return affected;
693}
694
695
696/* end of mysql.c */ 456/* end of mysql.c */