diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-04-17 19:13:42 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-04-17 19:13:42 +0200 |
commit | 3695a510a18d0bb9ed58fb5270856a88853b4e30 (patch) | |
tree | 9aa9fe53d3b3f16a086a242b660504b793c3aa54 /src/pq/pq_result_helper.c | |
parent | 6b89b84d2781a774adbadf272eb90785889b8407 (diff) | |
download | gnunet-3695a510a18d0bb9ed58fb5270856a88853b4e30.tar.gz gnunet-3695a510a18d0bb9ed58fb5270856a88853b4e30.zip |
add relative_time specs
Diffstat (limited to 'src/pq/pq_result_helper.c')
-rw-r--r-- | src/pq/pq_result_helper.c | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/src/pq/pq_result_helper.c b/src/pq/pq_result_helper.c index dc64597f8..f764593b0 100644 --- a/src/pq/pq_result_helper.c +++ b/src/pq/pq_result_helper.c | |||
@@ -544,6 +544,96 @@ GNUNET_PQ_result_spec_string (const char *name, | |||
544 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 544 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
545 | */ | 545 | */ |
546 | static int | 546 | static int |
547 | extract_rel_time (void *cls, | ||
548 | PGresult *result, | ||
549 | int row, | ||
550 | const char *fname, | ||
551 | size_t *dst_size, | ||
552 | void *dst) | ||
553 | { | ||
554 | struct GNUNET_TIME_Relative *udst = dst; | ||
555 | const int64_t *res; | ||
556 | int fnum; | ||
557 | |||
558 | (void) cls; | ||
559 | fnum = PQfnumber (result, | ||
560 | fname); | ||
561 | if (fnum < 0) | ||
562 | { | ||
563 | GNUNET_break (0); | ||
564 | return GNUNET_SYSERR; | ||
565 | } | ||
566 | if (PQgetisnull (result, | ||
567 | row, | ||
568 | fnum)) | ||
569 | { | ||
570 | GNUNET_break (0); | ||
571 | return GNUNET_SYSERR; | ||
572 | } | ||
573 | GNUNET_assert (NULL != dst); | ||
574 | if (sizeof(struct GNUNET_TIME_Relative) != *dst_size) | ||
575 | { | ||
576 | GNUNET_break (0); | ||
577 | return GNUNET_SYSERR; | ||
578 | } | ||
579 | if (sizeof(int64_t) != | ||
580 | PQgetlength (result, | ||
581 | row, | ||
582 | fnum)) | ||
583 | { | ||
584 | GNUNET_break (0); | ||
585 | return GNUNET_SYSERR; | ||
586 | } | ||
587 | res = (int64_t *) PQgetvalue (result, | ||
588 | row, | ||
589 | fnum); | ||
590 | if (INT64_MAX == GNUNET_ntohll ((uint64_t) *res)) | ||
591 | *udst = GNUNET_TIME_UNIT_FOREVER_REL; | ||
592 | else | ||
593 | udst->rel_value_us = GNUNET_ntohll ((uint64_t) *res); | ||
594 | return GNUNET_OK; | ||
595 | } | ||
596 | |||
597 | |||
598 | /** | ||
599 | * Relative time expected. | ||
600 | * | ||
601 | * @param name name of the field in the table | ||
602 | * @param[out] at where to store the result | ||
603 | * @return array entry for the result specification to use | ||
604 | */ | ||
605 | struct GNUNET_PQ_ResultSpec | ||
606 | GNUNET_PQ_result_spec_relative_time (const char *name, | ||
607 | struct GNUNET_TIME_Relative *rt) | ||
608 | { | ||
609 | struct GNUNET_PQ_ResultSpec res = { | ||
610 | &extract_rel_time, | ||
611 | NULL, | ||
612 | NULL, | ||
613 | (void *) rt, | ||
614 | sizeof(*rt), | ||
615 | name, | ||
616 | NULL | ||
617 | }; | ||
618 | |||
619 | return res; | ||
620 | } | ||
621 | |||
622 | |||
623 | /** | ||
624 | * Extract data from a Postgres database @a result at row @a row. | ||
625 | * | ||
626 | * @param cls closure | ||
627 | * @param result where to extract data from | ||
628 | * @param int row to extract data from | ||
629 | * @param fname name (or prefix) of the fields to extract from | ||
630 | * @param[in,out] dst_size where to store size of result, may be NULL | ||
631 | * @param[out] dst where to store the result | ||
632 | * @return | ||
633 | * #GNUNET_YES if all results could be extracted | ||
634 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | ||
635 | */ | ||
636 | static int | ||
547 | extract_abs_time (void *cls, | 637 | extract_abs_time (void *cls, |
548 | PGresult *result, | 638 | PGresult *result, |
549 | int row, | 639 | int row, |