aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorÖzgür Kesim <oec-taler@kesim.org>2023-07-30 00:08:48 +0200
committerÖzgür Kesim <oec-taler@kesim.org>2023-07-30 00:11:27 +0200
commit80f5ce941d40ddffdc592a6428b4c54df00ebb28 (patch)
tree2681969edd28f6ba08cd6b5065d195940b291ac3 /src/include
parente2fca041289bc082d000d15469c9700487a19c3c (diff)
downloadgnunet-80f5ce941d40ddffdc592a6428b4c54df00ebb28.tar.gz
gnunet-80f5ce941d40ddffdc592a6428b4c54df00ebb28.zip
pq: simplified and improved API for array-support
NEWS: GNUNET_PQ_get_oid removed, GNUNET_PQ_get_oid_by_name improved
Diffstat (limited to 'src/include')
-rw-r--r--src/include/gnunet_pq_lib.h158
1 files changed, 65 insertions, 93 deletions
diff --git a/src/include/gnunet_pq_lib.h b/src/include/gnunet_pq_lib.h
index ff59a63b9..3408362a6 100644
--- a/src/include/gnunet_pq_lib.h
+++ b/src/include/gnunet_pq_lib.h
@@ -132,13 +132,13 @@ GNUNET_PQ_cleanup_query_params_closures (
132 * End of query parameter specification. 132 * End of query parameter specification.
133 */ 133 */
134#define GNUNET_PQ_query_param_end \ 134#define GNUNET_PQ_query_param_end \
135 { \ 135 { \
136 .conv = NULL, \ 136 .conv = NULL, \
137 .conv_cls = NULL, \ 137 .conv_cls = NULL, \
138 .data = NULL, \ 138 .data = NULL, \
139 .size = 0, \ 139 .size = 0, \
140 .num_params = 0 \ 140 .num_params = 0 \
141 } 141 }
142 142
143 143
144/** 144/**
@@ -182,34 +182,6 @@ GNUNET_PQ_query_param_string (const char *ptr);
182struct GNUNET_PQ_QueryParam 182struct GNUNET_PQ_QueryParam
183GNUNET_PQ_query_param_bool (bool b); 183GNUNET_PQ_query_param_bool (bool b);
184 184
185
186/**
187 * Array types (in Postgres) that are supported in GNUnet.
188 */
189enum GNUNET_PQ_DataTypes
190{
191 GNUNET_PQ_DATATYPE_UNKNOWN, /* Unsupported type */
192 GNUNET_PQ_DATATYPE_BOOL,
193 GNUNET_PQ_DATATYPE_INT2,
194 GNUNET_PQ_DATATYPE_INT4,
195 GNUNET_PQ_DATATYPE_INT8,
196 GNUNET_PQ_DATATYPE_BYTEA,
197 GNUNET_PQ_DATATYPE_VARCHAR,
198 GNUNET_PQ_DATATYPE_MAX, /* Must be last */
199};
200
201/**
202 * Returns the oid for a given, basic datatype
203 *
204 * @param db The db-connection
205 * @param typ the Datatype
206 * @return The oid
207 */
208Oid
209GNUNET_PQ_get_oid (
210 const struct GNUNET_PQ_Context *db,
211 enum GNUNET_PQ_DataTypes typ);
212
213/** 185/**
214 * Returns the oid for a given datatype by name. 186 * Returns the oid for a given datatype by name.
215 * 187 *
@@ -254,7 +226,7 @@ struct GNUNET_PQ_QueryParam
254GNUNET_PQ_query_param_array_bool ( 226GNUNET_PQ_query_param_array_bool (
255 unsigned int num, 227 unsigned int num,
256 const bool *elements, 228 const bool *elements,
257 const struct GNUNET_PQ_Context *db); 229 struct GNUNET_PQ_Context *db);
258 230
259/** 231/**
260 * Generate query parameter for an array of uint16_t in host byte order. 232 * Generate query parameter for an array of uint16_t in host byte order.
@@ -269,7 +241,7 @@ struct GNUNET_PQ_QueryParam
269GNUNET_PQ_query_param_array_uint16 ( 241GNUNET_PQ_query_param_array_uint16 (
270 unsigned int num, 242 unsigned int num,
271 const uint16_t *elements, 243 const uint16_t *elements,
272 const struct GNUNET_PQ_Context *db); 244 struct GNUNET_PQ_Context *db);
273 245
274/** 246/**
275 * Generate query parameter for an array of uint32_t in host byte order. 247 * Generate query parameter for an array of uint32_t in host byte order.
@@ -284,7 +256,7 @@ struct GNUNET_PQ_QueryParam
284GNUNET_PQ_query_param_array_uint32 ( 256GNUNET_PQ_query_param_array_uint32 (
285 unsigned int num, 257 unsigned int num,
286 const uint32_t *elements, 258 const uint32_t *elements,
287 const struct GNUNET_PQ_Context *db); 259 struct GNUNET_PQ_Context *db);
288 260
289/** 261/**
290 * Generate query parameter for an array of uint64 in host byte order. 262 * Generate query parameter for an array of uint64 in host byte order.
@@ -299,7 +271,7 @@ struct GNUNET_PQ_QueryParam
299GNUNET_PQ_query_param_array_uint64 ( 271GNUNET_PQ_query_param_array_uint64 (
300 unsigned int num, 272 unsigned int num,
301 const uint64_t *elements, 273 const uint64_t *elements,
302 const struct GNUNET_PQ_Context *db); 274 struct GNUNET_PQ_Context *db);
303 275
304/** 276/**
305 * Generate query parameter for an array of buffers @a elements, each of 277 * Generate query parameter for an array of buffers @a elements, each of
@@ -316,7 +288,7 @@ GNUNET_PQ_query_param_array_bytes (
316 unsigned int num, 288 unsigned int num,
317 const void *elements, 289 const void *elements,
318 const size_t *sizes, 290 const size_t *sizes,
319 const struct GNUNET_PQ_Context *db); 291 struct GNUNET_PQ_Context *db);
320 292
321/** 293/**
322 * Generate query parameter for an array of buffers @a elements, 294 * Generate query parameter for an array of buffers @a elements,
@@ -333,7 +305,7 @@ GNUNET_PQ_query_param_array_bytes_same_size (
333 unsigned int num, 305 unsigned int num,
334 const void *elements, 306 const void *elements,
335 size_t same_size, 307 size_t same_size,
336 const struct GNUNET_PQ_Context *db); 308 struct GNUNET_PQ_Context *db);
337 309
338/** 310/**
339 * Generate array of equal-sized query parameter with size determined 311 * Generate array of equal-sized query parameter with size determined
@@ -345,10 +317,10 @@ GNUNET_PQ_query_param_array_bytes_same_size (
345 * @return query parameter to use 317 * @return query parameter to use
346 */ 318 */
347#define GNUNET_PQ_query_param_array_auto_from_type(num, elements, db) \ 319#define GNUNET_PQ_query_param_array_auto_from_type(num, elements, db) \
348 GNUNET_PQ_query_param_array_bytes_same_size ((num), \ 320 GNUNET_PQ_query_param_array_bytes_same_size ((num), \
349 (elements), \ 321 (elements), \
350 sizeof(*(elements)), \ 322 sizeof(*(elements)), \
351 (db)) 323 (db))
352 324
353/** 325/**
354 * Generate query parameter for an array of pointers to buffers @a elements, 326 * Generate query parameter for an array of pointers to buffers @a elements,
@@ -365,7 +337,7 @@ GNUNET_PQ_query_param_array_ptrs_bytes_same_size (
365 unsigned int num, 337 unsigned int num,
366 const void *elements[], 338 const void *elements[],
367 size_t same_size, 339 size_t same_size,
368 const struct GNUNET_PQ_Context *db); 340 struct GNUNET_PQ_Context *db);
369 341
370/** 342/**
371 * Generate array of equal-sized query parameter with size determined by 343 * Generate array of equal-sized query parameter with size determined by
@@ -378,10 +350,10 @@ GNUNET_PQ_query_param_array_ptrs_bytes_same_size (
378 * @return query parameter to use 350 * @return query parameter to use
379 */ 351 */
380#define GNUNET_PQ_query_param_array_ptrs_auto_from_type(num, elements, db) \ 352#define GNUNET_PQ_query_param_array_ptrs_auto_from_type(num, elements, db) \
381 GNUNET_PQ_query_param_array_ptrs_bytes_same_size ((num), \ 353 GNUNET_PQ_query_param_array_ptrs_bytes_same_size ((num), \
382 (elements), \ 354 (elements), \
383 sizeof(*(elements[0])), \ 355 sizeof(*(elements[0])), \
384 (db)) 356 (db))
385 357
386 358
387/** 359/**
@@ -396,7 +368,7 @@ struct GNUNET_PQ_QueryParam
396GNUNET_PQ_query_param_array_string ( 368GNUNET_PQ_query_param_array_string (
397 unsigned int num, 369 unsigned int num,
398 const char *elements, 370 const char *elements,
399 const struct GNUNET_PQ_Context *db); 371 struct GNUNET_PQ_Context *db);
400 372
401 373
402/** 374/**
@@ -411,7 +383,7 @@ struct GNUNET_PQ_QueryParam
411GNUNET_PQ_query_param_array_ptrs_string ( 383GNUNET_PQ_query_param_array_ptrs_string (
412 unsigned int num, 384 unsigned int num,
413 const char *elements[], 385 const char *elements[],
414 const struct GNUNET_PQ_Context *db); 386 struct GNUNET_PQ_Context *db);
415 387
416/** 388/**
417 * Generate fixed-size query parameter with size determined 389 * Generate fixed-size query parameter with size determined
@@ -421,7 +393,7 @@ GNUNET_PQ_query_param_array_ptrs_string (
421 * @return query parameter to use 393 * @return query parameter to use
422 */ 394 */
423#define GNUNET_PQ_query_param_auto_from_type(x) \ 395#define GNUNET_PQ_query_param_auto_from_type(x) \
424 GNUNET_PQ_query_param_fixed_size ((x), sizeof(*(x))) 396 GNUNET_PQ_query_param_fixed_size ((x), sizeof(*(x)))
425 397
426/** 398/**
427 * Generate query parameter for an array of absolute time stamps (continuous) 399 * Generate query parameter for an array of absolute time stamps (continuous)
@@ -434,7 +406,7 @@ struct GNUNET_PQ_QueryParam
434GNUNET_PQ_query_param_array_abs_time ( 406GNUNET_PQ_query_param_array_abs_time (
435 unsigned int num, 407 unsigned int num,
436 const struct GNUNET_TIME_Absolute *elements, 408 const struct GNUNET_TIME_Absolute *elements,
437 const struct GNUNET_PQ_Context *db); 409 struct GNUNET_PQ_Context *db);
438 410
439/** 411/**
440 * Generate query parameter for an array of absolute time stamps (pointers) 412 * Generate query parameter for an array of absolute time stamps (pointers)
@@ -447,7 +419,7 @@ struct GNUNET_PQ_QueryParam
447GNUNET_PQ_query_param_array_ptrs_abs_time ( 419GNUNET_PQ_query_param_array_ptrs_abs_time (
448 unsigned int num, 420 unsigned int num,
449 const struct GNUNET_TIME_Absolute *elements[], 421 const struct GNUNET_TIME_Absolute *elements[],
450 const struct GNUNET_PQ_Context *db); 422 struct GNUNET_PQ_Context *db);
451 423
452/** 424/**
453 * Generate query parameter for an array of relative time stamps (continuous) 425 * Generate query parameter for an array of relative time stamps (continuous)
@@ -460,7 +432,7 @@ struct GNUNET_PQ_QueryParam
460GNUNET_PQ_query_param_array_rel_time ( 432GNUNET_PQ_query_param_array_rel_time (
461 unsigned int num, 433 unsigned int num,
462 const struct GNUNET_TIME_Relative *elements, 434 const struct GNUNET_TIME_Relative *elements,
463 const struct GNUNET_PQ_Context *db); 435 struct GNUNET_PQ_Context *db);
464 436
465/** 437/**
466 * Generate query parameter for an array of relative time stamps (pointers) 438 * Generate query parameter for an array of relative time stamps (pointers)
@@ -473,7 +445,7 @@ struct GNUNET_PQ_QueryParam
473GNUNET_PQ_query_param_array_ptrs_rel_time ( 445GNUNET_PQ_query_param_array_ptrs_rel_time (
474 unsigned int num, 446 unsigned int num,
475 const struct GNUNET_TIME_Relative *elements[], 447 const struct GNUNET_TIME_Relative *elements[],
476 const struct GNUNET_PQ_Context *db); 448 struct GNUNET_PQ_Context *db);
477 449
478/** 450/**
479 * Generate query parameter for an array of time stamps (continuous) 451 * Generate query parameter for an array of time stamps (continuous)
@@ -486,7 +458,7 @@ struct GNUNET_PQ_QueryParam
486GNUNET_PQ_query_param_array_timestamp ( 458GNUNET_PQ_query_param_array_timestamp (
487 unsigned int num, 459 unsigned int num,
488 const struct GNUNET_TIME_Timestamp *elements, 460 const struct GNUNET_TIME_Timestamp *elements,
489 const struct GNUNET_PQ_Context *db); 461 struct GNUNET_PQ_Context *db);
490 462
491/** 463/**
492 * Generate query parameter for an array of time stamps (pointers) 464 * Generate query parameter for an array of time stamps (pointers)
@@ -499,7 +471,7 @@ struct GNUNET_PQ_QueryParam
499GNUNET_PQ_query_param_array_ptrs_timestamp ( 471GNUNET_PQ_query_param_array_ptrs_timestamp (
500 unsigned int num, 472 unsigned int num,
501 const struct GNUNET_TIME_Timestamp *elements[], 473 const struct GNUNET_TIME_Timestamp *elements[],
502 const struct GNUNET_PQ_Context *db); 474 struct GNUNET_PQ_Context *db);
503 475
504/** 476/**
505 * Generate query parameter for an RSA public key. The 477 * Generate query parameter for an RSA public key. The
@@ -712,17 +684,17 @@ struct GNUNET_PQ_ResultSpec
712 * @return array last entry for the result specification to use 684 * @return array last entry for the result specification to use
713 */ 685 */
714#define GNUNET_PQ_result_spec_end \ 686#define GNUNET_PQ_result_spec_end \
715 { \ 687 { \
716 .conv = NULL, \ 688 .conv = NULL, \
717 .cleaner = NULL, \ 689 .cleaner = NULL, \
718 .cls = NULL, \ 690 .cls = NULL, \
719 .dst = NULL, \ 691 .dst = NULL, \
720 .dst_size = 0, \ 692 .dst_size = 0, \
721 .fname = NULL, \ 693 .fname = NULL, \
722 .result_size = NULL, \ 694 .result_size = NULL, \
723 .is_nullable = false, \ 695 .is_nullable = false, \
724 .is_null = NULL \ 696 .is_null = NULL \
725 } 697 }
726 698
727 699
728/** 700/**
@@ -775,7 +747,7 @@ GNUNET_PQ_result_spec_fixed_size (const char *name,
775 * @return array entry for the result specification to use 747 * @return array entry for the result specification to use
776 */ 748 */
777#define GNUNET_PQ_result_spec_auto_from_type(name, dst) \ 749#define GNUNET_PQ_result_spec_auto_from_type(name, dst) \
778 GNUNET_PQ_result_spec_fixed_size (name, (dst), sizeof(*(dst))) 750 GNUNET_PQ_result_spec_fixed_size (name, (dst), sizeof(*(dst)))
779 751
780 752
781/** 753/**
@@ -932,7 +904,7 @@ GNUNET_PQ_result_spec_uint64 (const char *name,
932 */ 904 */
933struct GNUNET_PQ_ResultSpec 905struct GNUNET_PQ_ResultSpec
934GNUNET_PQ_result_spec_array_bool ( 906GNUNET_PQ_result_spec_array_bool (
935 const struct GNUNET_PQ_Context *db, 907 struct GNUNET_PQ_Context *db,
936 const char *name, 908 const char *name,
937 size_t *num, 909 size_t *num,
938 bool **bools); 910 bool **bools);
@@ -948,7 +920,7 @@ GNUNET_PQ_result_spec_array_bool (
948 */ 920 */
949struct GNUNET_PQ_ResultSpec 921struct GNUNET_PQ_ResultSpec
950GNUNET_PQ_result_spec_array_uint16 ( 922GNUNET_PQ_result_spec_array_uint16 (
951 const struct GNUNET_PQ_Context *db, 923 struct GNUNET_PQ_Context *db,
952 const char *name, 924 const char *name,
953 size_t *num, 925 size_t *num,
954 uint16_t **dst); 926 uint16_t **dst);
@@ -964,7 +936,7 @@ GNUNET_PQ_result_spec_array_uint16 (
964 */ 936 */
965struct GNUNET_PQ_ResultSpec 937struct GNUNET_PQ_ResultSpec
966GNUNET_PQ_result_spec_array_uint32 ( 938GNUNET_PQ_result_spec_array_uint32 (
967 const struct GNUNET_PQ_Context *db, 939 struct GNUNET_PQ_Context *db,
968 const char *name, 940 const char *name,
969 size_t *num, 941 size_t *num,
970 uint32_t **dst); 942 uint32_t **dst);
@@ -980,7 +952,7 @@ GNUNET_PQ_result_spec_array_uint32 (
980 */ 952 */
981struct GNUNET_PQ_ResultSpec 953struct GNUNET_PQ_ResultSpec
982GNUNET_PQ_result_spec_array_uint64 ( 954GNUNET_PQ_result_spec_array_uint64 (
983 const struct GNUNET_PQ_Context *db, 955 struct GNUNET_PQ_Context *db,
984 const char *name, 956 const char *name,
985 size_t *num, 957 size_t *num,
986 uint64_t **dst); 958 uint64_t **dst);
@@ -997,7 +969,7 @@ GNUNET_PQ_result_spec_array_uint64 (
997 */ 969 */
998struct GNUNET_PQ_ResultSpec 970struct GNUNET_PQ_ResultSpec
999GNUNET_PQ_result_spec_array_abs_time ( 971GNUNET_PQ_result_spec_array_abs_time (
1000 const struct GNUNET_PQ_Context *db, 972 struct GNUNET_PQ_Context *db,
1001 const char *name, 973 const char *name,
1002 size_t *num, 974 size_t *num,
1003 struct GNUNET_TIME_Absolute **dst); 975 struct GNUNET_TIME_Absolute **dst);
@@ -1013,7 +985,7 @@ GNUNET_PQ_result_spec_array_abs_time (
1013 */ 985 */
1014struct GNUNET_PQ_ResultSpec 986struct GNUNET_PQ_ResultSpec
1015GNUNET_PQ_result_spec_array_rel_time ( 987GNUNET_PQ_result_spec_array_rel_time (
1016 const struct GNUNET_PQ_Context *db, 988 struct GNUNET_PQ_Context *db,
1017 const char *name, 989 const char *name,
1018 size_t *num, 990 size_t *num,
1019 struct GNUNET_TIME_Relative **dst); 991 struct GNUNET_TIME_Relative **dst);
@@ -1030,7 +1002,7 @@ GNUNET_PQ_result_spec_array_rel_time (
1030 1002
1031struct GNUNET_PQ_ResultSpec 1003struct GNUNET_PQ_ResultSpec
1032GNUNET_PQ_result_spec_array_timestamp ( 1004GNUNET_PQ_result_spec_array_timestamp (
1033 const struct GNUNET_PQ_Context *db, 1005 struct GNUNET_PQ_Context *db,
1034 const char *name, 1006 const char *name,
1035 size_t *num, 1007 size_t *num,
1036 struct GNUNET_TIME_Timestamp **dst); 1008 struct GNUNET_TIME_Timestamp **dst);
@@ -1047,7 +1019,7 @@ GNUNET_PQ_result_spec_array_timestamp (
1047 */ 1019 */
1048struct GNUNET_PQ_ResultSpec 1020struct GNUNET_PQ_ResultSpec
1049GNUNET_PQ_result_spec_array_variable_size ( 1021GNUNET_PQ_result_spec_array_variable_size (
1050 const struct GNUNET_PQ_Context *db, 1022 struct GNUNET_PQ_Context *db,
1051 const char *name, 1023 const char *name,
1052 size_t *num, 1024 size_t *num,
1053 size_t **sizes, 1025 size_t **sizes,
@@ -1066,7 +1038,7 @@ GNUNET_PQ_result_spec_array_variable_size (
1066 */ 1038 */
1067struct GNUNET_PQ_ResultSpec 1039struct GNUNET_PQ_ResultSpec
1068GNUNET_PQ_result_spec_array_fixed_size ( 1040GNUNET_PQ_result_spec_array_fixed_size (
1069 const struct GNUNET_PQ_Context *db, 1041 struct GNUNET_PQ_Context *db,
1070 const char *name, 1042 const char *name,
1071 size_t size, 1043 size_t size,
1072 size_t *num, 1044 size_t *num,
@@ -1083,12 +1055,12 @@ GNUNET_PQ_result_spec_array_fixed_size (
1083 * @return array entry for the result specification to use 1055 * @return array entry for the result specification to use
1084 */ 1056 */
1085#define GNUNET_PQ_result_spec_auto_array_from_type(db, name, num, dst) \ 1057#define GNUNET_PQ_result_spec_auto_array_from_type(db, name, num, dst) \
1086 GNUNET_PQ_result_spec_array_fixed_size ( \ 1058 GNUNET_PQ_result_spec_array_fixed_size ( \
1087 (db), \ 1059 (db), \
1088 (name), \ 1060 (name), \
1089 sizeof(*(dst)), \ 1061 sizeof(*(dst)), \
1090 (num), \ 1062 (num), \
1091 (void *) &(dst)) 1063 (void *) &(dst))
1092 1064
1093 1065
1094/** 1066/**
@@ -1102,7 +1074,7 @@ GNUNET_PQ_result_spec_array_fixed_size (
1102 */ 1074 */
1103struct GNUNET_PQ_ResultSpec 1075struct GNUNET_PQ_ResultSpec
1104GNUNET_PQ_result_spec_array_string ( 1076GNUNET_PQ_result_spec_array_string (
1105 const struct GNUNET_PQ_Context *db, 1077 struct GNUNET_PQ_Context *db,
1106 const char *name, 1078 const char *name,
1107 size_t *num, 1079 size_t *num,
1108 char **dst); 1080 char **dst);
@@ -1280,9 +1252,9 @@ struct GNUNET_PQ_PreparedStatement
1280 * Terminator for prepared statement list. 1252 * Terminator for prepared statement list.
1281 */ 1253 */
1282#define GNUNET_PQ_PREPARED_STATEMENT_END \ 1254#define GNUNET_PQ_PREPARED_STATEMENT_END \
1283 { \ 1255 { \
1284 NULL, NULL \ 1256 NULL, NULL \
1285 } 1257 }
1286 1258
1287 1259
1288/** 1260/**
@@ -1352,9 +1324,9 @@ struct GNUNET_PQ_ExecuteStatement
1352 * Terminator for executable statement list. 1324 * Terminator for executable statement list.
1353 */ 1325 */
1354#define GNUNET_PQ_EXECUTE_STATEMENT_END \ 1326#define GNUNET_PQ_EXECUTE_STATEMENT_END \
1355 { \ 1327 { \
1356 NULL, GNUNET_SYSERR \ 1328 NULL, GNUNET_SYSERR \
1357 } 1329 }
1358 1330
1359 1331
1360/** 1332/**