diff options
Diffstat (limited to 'src/include/gnunet_pq_lib.h')
-rw-r--r-- | src/include/gnunet_pq_lib.h | 253 |
1 files changed, 219 insertions, 34 deletions
diff --git a/src/include/gnunet_pq_lib.h b/src/include/gnunet_pq_lib.h index b21c6974f..78eaf0d49 100644 --- a/src/include/gnunet_pq_lib.h +++ b/src/include/gnunet_pq_lib.h | |||
@@ -131,13 +131,13 @@ GNUNET_PQ_cleanup_query_params_closures ( | |||
131 | * End of query parameter specification. | 131 | * End of query parameter specification. |
132 | */ | 132 | */ |
133 | #define GNUNET_PQ_query_param_end \ | 133 | #define GNUNET_PQ_query_param_end \ |
134 | { \ | 134 | { \ |
135 | .conv = NULL, \ | 135 | .conv = NULL, \ |
136 | .conv_cls = NULL, \ | 136 | .conv_cls = NULL, \ |
137 | .data = NULL, \ | 137 | .data = NULL, \ |
138 | .size = 0, \ | 138 | .size = 0, \ |
139 | .num_params = 0 \ | 139 | .num_params = 0 \ |
140 | } | 140 | } |
141 | 141 | ||
142 | 142 | ||
143 | /** | 143 | /** |
@@ -300,10 +300,10 @@ GNUNET_PQ_query_param_array_bytes_same_size ( | |||
300 | * @return query parameter to use | 300 | * @return query parameter to use |
301 | */ | 301 | */ |
302 | #define GNUNET_PQ_query_param_array_auto_from_type(num, elements, db) \ | 302 | #define GNUNET_PQ_query_param_array_auto_from_type(num, elements, db) \ |
303 | GNUNET_PQ_query_param_array_bytes_same_size ((num), \ | 303 | GNUNET_PQ_query_param_array_bytes_same_size ((num), \ |
304 | (elements), \ | 304 | (elements), \ |
305 | sizeof(*(elements)), \ | 305 | sizeof(*(elements)), \ |
306 | (db)) | 306 | (db)) |
307 | 307 | ||
308 | /** | 308 | /** |
309 | * Generate query parameter for an array of pointers to buffers @a elements, | 309 | * Generate query parameter for an array of pointers to buffers @a elements, |
@@ -333,10 +333,10 @@ GNUNET_PQ_query_param_array_ptrs_bytes_same_size ( | |||
333 | * @return query parameter to use | 333 | * @return query parameter to use |
334 | */ | 334 | */ |
335 | #define GNUNET_PQ_query_param_array_ptrs_auto_from_type(num, elements, db) \ | 335 | #define GNUNET_PQ_query_param_array_ptrs_auto_from_type(num, elements, db) \ |
336 | GNUNET_PQ_query_param_array_ptrs_bytes_same_size ((num), \ | 336 | GNUNET_PQ_query_param_array_ptrs_bytes_same_size ((num), \ |
337 | (elements), \ | 337 | (elements), \ |
338 | sizeof(*(elements[0])), \ | 338 | sizeof(*(elements[0])), \ |
339 | (db)) | 339 | (db)) |
340 | 340 | ||
341 | 341 | ||
342 | /** | 342 | /** |
@@ -376,7 +376,7 @@ GNUNET_PQ_query_param_array_ptrs_string ( | |||
376 | * @return query parameter to use | 376 | * @return query parameter to use |
377 | */ | 377 | */ |
378 | #define GNUNET_PQ_query_param_auto_from_type(x) \ | 378 | #define GNUNET_PQ_query_param_auto_from_type(x) \ |
379 | GNUNET_PQ_query_param_fixed_size ((x), sizeof(*(x))) | 379 | GNUNET_PQ_query_param_fixed_size ((x), sizeof(*(x))) |
380 | 380 | ||
381 | /** | 381 | /** |
382 | * Generate query parameter for an array of absolute time stamps (continuous) | 382 | * Generate query parameter for an array of absolute time stamps (continuous) |
@@ -667,17 +667,17 @@ struct GNUNET_PQ_ResultSpec | |||
667 | * @return array last entry for the result specification to use | 667 | * @return array last entry for the result specification to use |
668 | */ | 668 | */ |
669 | #define GNUNET_PQ_result_spec_end \ | 669 | #define GNUNET_PQ_result_spec_end \ |
670 | { \ | 670 | { \ |
671 | .conv = NULL, \ | 671 | .conv = NULL, \ |
672 | .cleaner = NULL, \ | 672 | .cleaner = NULL, \ |
673 | .cls = NULL, \ | 673 | .cls = NULL, \ |
674 | .dst = NULL, \ | 674 | .dst = NULL, \ |
675 | .dst_size = 0, \ | 675 | .dst_size = 0, \ |
676 | .fname = NULL, \ | 676 | .fname = NULL, \ |
677 | .result_size = NULL, \ | 677 | .result_size = NULL, \ |
678 | .is_nullable = false, \ | 678 | .is_nullable = false, \ |
679 | .is_null = NULL \ | 679 | .is_null = NULL \ |
680 | } | 680 | } |
681 | 681 | ||
682 | 682 | ||
683 | /** | 683 | /** |
@@ -730,7 +730,7 @@ GNUNET_PQ_result_spec_fixed_size (const char *name, | |||
730 | * @return array entry for the result specification to use | 730 | * @return array entry for the result specification to use |
731 | */ | 731 | */ |
732 | #define GNUNET_PQ_result_spec_auto_from_type(name, dst) \ | 732 | #define GNUNET_PQ_result_spec_auto_from_type(name, dst) \ |
733 | GNUNET_PQ_result_spec_fixed_size (name, (dst), sizeof(*(dst))) | 733 | GNUNET_PQ_result_spec_fixed_size (name, (dst), sizeof(*(dst))) |
734 | 734 | ||
735 | 735 | ||
736 | /** | 736 | /** |
@@ -876,6 +876,191 @@ struct GNUNET_PQ_ResultSpec | |||
876 | GNUNET_PQ_result_spec_uint64 (const char *name, | 876 | GNUNET_PQ_result_spec_uint64 (const char *name, |
877 | uint64_t *u64); | 877 | uint64_t *u64); |
878 | 878 | ||
879 | /** | ||
880 | * array of bool expected. | ||
881 | * | ||
882 | * @param db Database context, needed for OID lookup for the correct type | ||
883 | * @param name name of the field in the table | ||
884 | * @param[out] num where to store the number of elements in the array @a bools. | ||
885 | * @param[out] bools pointer to where to store the result, an array of @a num bool's. Allocated by the function, MUST be freed with GNUNET_free. | ||
886 | * @return array entry for the result specification to use | ||
887 | */ | ||
888 | struct GNUNET_PQ_ResultSpec | ||
889 | GNUNET_PQ_result_spec_array_bool ( | ||
890 | const struct GNUNET_PQ_Context *db, | ||
891 | const char *name, | ||
892 | size_t *num, | ||
893 | bool **bools); | ||
894 | |||
895 | /** | ||
896 | * array of uint16_t expected. | ||
897 | * | ||
898 | * @param db Database context, needed for OID lookup for the correct type | ||
899 | * @param name name of the field in the table | ||
900 | * @param[out] num where to store the number of elements in the array @a u16s. | ||
901 | * @param[out] dst pointer to where to store the an array of @a num uint16_t's. Allocated by the function, MUST be freed with GNUNET_free. | ||
902 | * @return array entry for the result specification to use | ||
903 | */ | ||
904 | struct GNUNET_PQ_ResultSpec | ||
905 | GNUNET_PQ_result_spec_array_uint16 ( | ||
906 | const struct GNUNET_PQ_Context *db, | ||
907 | const char *name, | ||
908 | size_t *num, | ||
909 | uint16_t **dst); | ||
910 | |||
911 | /** | ||
912 | * array of uint32_t expected. | ||
913 | * | ||
914 | * @param db Database context, needed for OID lookup for the correct type | ||
915 | * @param name name of the field in the table | ||
916 | * @param[out] num where to store the number of elements in the array @a u32s. | ||
917 | * @param[out] dst pointer to where to store the array of @a num uint32_t's. Allocated by the function, MUST be freed with GNUNET_free. | ||
918 | * @return array entry for the result specification to use | ||
919 | */ | ||
920 | struct GNUNET_PQ_ResultSpec | ||
921 | GNUNET_PQ_result_spec_array_uint32 ( | ||
922 | const struct GNUNET_PQ_Context *db, | ||
923 | const char *name, | ||
924 | size_t *num, | ||
925 | uint32_t **dst); | ||
926 | |||
927 | /** | ||
928 | * array of uint64_t expected. | ||
929 | * | ||
930 | * @param db Database context, needed for OID lookup for the correct type | ||
931 | * @param name name of the field in the table | ||
932 | * @param[out] num where to store the number of elements in the array @a u64s. | ||
933 | * @param[out] dst pointer to where to store the array of @a num uint64_t's. Allocated by the function, MUST be freed with GNUNET_free. | ||
934 | * @return array entry for the result specification to use | ||
935 | */ | ||
936 | struct GNUNET_PQ_ResultSpec | ||
937 | GNUNET_PQ_result_spec_array_uint64 ( | ||
938 | const struct GNUNET_PQ_Context *db, | ||
939 | const char *name, | ||
940 | size_t *num, | ||
941 | uint64_t **dst); | ||
942 | |||
943 | |||
944 | /** | ||
945 | * array of absolute time expected. | ||
946 | * | ||
947 | * @param db Database context, needed for OID lookup for the correct type | ||
948 | * @param name name of the field in the table | ||
949 | * @param[out] num where to store the number of elements in the array @a u64s. | ||
950 | * @param[out] dst pointer to where to store the array of @a num absolute time. Allocated by the function, MUST be freed with GNUNET_free. | ||
951 | * @return array entry for the result specification to use | ||
952 | */ | ||
953 | struct GNUNET_PQ_ResultSpec | ||
954 | GNUNET_PQ_result_spec_array_abs_time ( | ||
955 | const struct GNUNET_PQ_Context *db, | ||
956 | const char *name, | ||
957 | size_t *num, | ||
958 | struct GNUNET_TIME_Absolute **dst); | ||
959 | |||
960 | /** | ||
961 | * array of relative time expected. | ||
962 | * | ||
963 | * @param db Database context, needed for OID lookup for the correct type | ||
964 | * @param name name of the field in the table | ||
965 | * @param[out] num where to store the number of elements in the array @a u64s. | ||
966 | * @param[out] dst pointer to where to store the array of @a num relate time. Allocated by the function, MUST be freed with GNUNET_free. | ||
967 | * @return array entry for the result specification to use | ||
968 | */ | ||
969 | struct GNUNET_PQ_ResultSpec | ||
970 | GNUNET_PQ_result_spec_array_rel_time ( | ||
971 | const struct GNUNET_PQ_Context *db, | ||
972 | const char *name, | ||
973 | size_t *num, | ||
974 | struct GNUNET_TIME_Relative **dst); | ||
975 | |||
976 | /** | ||
977 | * array of relative time expected. | ||
978 | * | ||
979 | * @param db Database context, needed for OID lookup for the correct type | ||
980 | * @param name name of the field in the table | ||
981 | * @param[out] num where to store the number of elements in the array @a u64s. | ||
982 | * @param[out] dst pointer to where to store the array of @a num timestamps. Allocated by the function, MUST be freed with GNUNET_free. | ||
983 | * @return array entry for the result specification to use | ||
984 | */ | ||
985 | |||
986 | struct GNUNET_PQ_ResultSpec | ||
987 | GNUNET_PQ_result_spec_array_timestamp ( | ||
988 | const struct GNUNET_PQ_Context *db, | ||
989 | const char *name, | ||
990 | size_t *num, | ||
991 | struct GNUNET_TIME_Timestamp **dst); | ||
992 | |||
993 | /** | ||
994 | * Array of variable-size result expected. | ||
995 | * | ||
996 | * @param db Database context, needed for OID lookup for the correct type | ||
997 | * @param name name of the field in the table | ||
998 | * @param[out] num where to store the number of elements | ||
999 | * @param[out] sizes where to store the @a num size's of byte-buffers in @a dst | ||
1000 | * @param[out] dst where to store the continuous array of @a num byte-buffers , allocated | ||
1001 | * @return array entry for the result specification to use | ||
1002 | */ | ||
1003 | struct GNUNET_PQ_ResultSpec | ||
1004 | GNUNET_PQ_result_spec_array_variable_size ( | ||
1005 | const struct GNUNET_PQ_Context *db, | ||
1006 | const char *name, | ||
1007 | size_t *num, | ||
1008 | size_t **sizes, | ||
1009 | void **dst); | ||
1010 | |||
1011 | |||
1012 | /** | ||
1013 | * Array of fixed-size result expected. | ||
1014 | * | ||
1015 | * @param db Database context, needed for OID lookup for the correct type | ||
1016 | * @param name name of the field in the table | ||
1017 | * @param size number of bytes expected in each element of @a dst | ||
1018 | * @param[out] num where to store the number of elements | ||
1019 | * @param[out] dst where to store the results, an continuous array of fixed-size elements | ||
1020 | * @return array entry for the result specification to use | ||
1021 | */ | ||
1022 | struct GNUNET_PQ_ResultSpec | ||
1023 | GNUNET_PQ_result_spec_array_fixed_size ( | ||
1024 | const struct GNUNET_PQ_Context *db, | ||
1025 | const char *name, | ||
1026 | size_t size, | ||
1027 | size_t *num, | ||
1028 | void **dst); | ||
1029 | |||
1030 | |||
1031 | /** | ||
1032 | * We expect a fixed-size result, with size determined by the type of `* dst` | ||
1033 | * | ||
1034 | * @param db Database context, needed for OID lookup for the correct type | ||
1035 | * @param name name of the field in the table | ||
1036 | * @param num pointer to where to store the number of elements | ||
1037 | * @param dst pointer to where to store the results, type fits expected result size | ||
1038 | * @return array entry for the result specification to use | ||
1039 | */ | ||
1040 | #define GNUNET_PQ_result_spec_auto_array_from_type(db, name, num, dst) \ | ||
1041 | GNUNET_PQ_result_spec_array_fixed_size ( \ | ||
1042 | (db), \ | ||
1043 | (name), \ | ||
1044 | sizeof(*(dst)), \ | ||
1045 | (num), \ | ||
1046 | (void *) &(dst)) | ||
1047 | |||
1048 | |||
1049 | /** | ||
1050 | * Array of 0-terminated strings expected. | ||
1051 | * | ||
1052 | * @param db Database context, needed for OID lookup for the correct type | ||
1053 | * @param name name of the field in the table | ||
1054 | * @param[out] num where to store the number of elements | ||
1055 | * @param[out] dst where to store the allocated continous array of @a num 0-terminated strings | ||
1056 | * @return array entry for the result specification to use | ||
1057 | */ | ||
1058 | struct GNUNET_PQ_ResultSpec | ||
1059 | GNUNET_PQ_result_spec_array_string ( | ||
1060 | const struct GNUNET_PQ_Context *db, | ||
1061 | const char *name, | ||
1062 | size_t *num, | ||
1063 | char **dst); | ||
879 | 1064 | ||
880 | /* ************************* pq.c functions ************************ */ | 1065 | /* ************************* pq.c functions ************************ */ |
881 | 1066 | ||
@@ -1050,9 +1235,9 @@ struct GNUNET_PQ_PreparedStatement | |||
1050 | * Terminator for prepared statement list. | 1235 | * Terminator for prepared statement list. |
1051 | */ | 1236 | */ |
1052 | #define GNUNET_PQ_PREPARED_STATEMENT_END \ | 1237 | #define GNUNET_PQ_PREPARED_STATEMENT_END \ |
1053 | { \ | 1238 | { \ |
1054 | NULL, NULL \ | 1239 | NULL, NULL \ |
1055 | } | 1240 | } |
1056 | 1241 | ||
1057 | 1242 | ||
1058 | /** | 1243 | /** |
@@ -1122,9 +1307,9 @@ struct GNUNET_PQ_ExecuteStatement | |||
1122 | * Terminator for executable statement list. | 1307 | * Terminator for executable statement list. |
1123 | */ | 1308 | */ |
1124 | #define GNUNET_PQ_EXECUTE_STATEMENT_END \ | 1309 | #define GNUNET_PQ_EXECUTE_STATEMENT_END \ |
1125 | { \ | 1310 | { \ |
1126 | NULL, GNUNET_SYSERR \ | 1311 | NULL, GNUNET_SYSERR \ |
1127 | } | 1312 | } |
1128 | 1313 | ||
1129 | 1314 | ||
1130 | /** | 1315 | /** |