aboutsummaryrefslogtreecommitdiff
path: root/src/pq
diff options
context:
space:
mode:
Diffstat (limited to 'src/pq')
-rw-r--r--src/pq/pq.h16
-rw-r--r--src/pq/pq_connect.c226
-rw-r--r--src/pq/pq_query_helper.c112
-rw-r--r--src/pq/pq_result_helper.c70
4 files changed, 236 insertions, 188 deletions
diff --git a/src/pq/pq.h b/src/pq/pq.h
index 0c011a6ef..46d749fcc 100644
--- a/src/pq/pq.h
+++ b/src/pq/pq.h
@@ -102,7 +102,21 @@ struct GNUNET_PQ_Context
102 /** 102 /**
103 * Mapping between array types and Oid's, filled at reconnect 103 * Mapping between array types and Oid's, filled at reconnect
104 */ 104 */
105 Oid oids[GNUNET_PQ_DATATYPE_MAX]; 105 struct
106 {
107 /* allocated number of elements array @table */
108 unsigned int cap;
109
110 /* number of entries in @table */
111 unsigned int num;
112
113 struct name2oid
114 {
115 const char *name;
116 Oid oid;
117 } *table;
118
119 } oids;
106}; 120};
107 121
108 122
diff --git a/src/pq/pq_connect.c b/src/pq/pq_connect.c
index ba272bce4..5a42d1ae9 100644
--- a/src/pq/pq_connect.c
+++ b/src/pq/pq_connect.c
@@ -322,149 +322,103 @@ GNUNET_PQ_reconnect_if_down (struct GNUNET_PQ_Context *db)
322} 322}
323 323
324 324
325/** 325enum GNUNET_GenericReturnValue
326 * Retrieves the Oid's for the supported array types and sets db->arraytype2oid 326GNUNET_PQ_get_oid_by_name (
327 * on succes. 327 struct GNUNET_PQ_Context *db,
328 * 328 const char *name,
329 * @param[in,out] db Context for the database connection 329 Oid *oid)
330 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
331 */
332static enum GNUNET_GenericReturnValue
333get_array_type_oids (struct GNUNET_PQ_Context *db)
334{ 330{
335 PGresult *res; 331 /* Check if the entry is in the cache already */
336 ExecStatusType est; 332 for (unsigned int i = 0; i < db->oids.num; i++)
337
338 GNUNET_assert (NULL != db);
339 /* Initialize to Oid(0) (= unknown) */
340 memset (db->oids,
341 0,
342 sizeof(db->oids));
343
344 res = PQexec (db->conn,
345 "SELECT"
346 " typname, oid"
347 " FROM pg_type "
348 " WHERE typname in "
349 " ('bool', 'int2', 'int4', 'int8', 'bytea', 'varchar');");
350
351 est = PQresultStatus (res);
352 if ( (PGRES_COMMAND_OK != est) &&
353 (PGRES_TUPLES_OK != est))
354 { 333 {
355 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 334 /* Pointer comparison */
356 "Failed to run statement to retrieve Oids for array types!\n"); 335 if (name == db->oids.table[i].name)
357 return GNUNET_SYSERR; 336 {
337 *oid = db->oids.table[i].oid;
338 return GNUNET_OK;
339 }
358 } 340 }
359 341
360 if ( (2 != PQnfields (res)) || 342 /* No entry found in cache, ask database */
361 (0 != PQfnumber (res, "typname")) ||
362 (1 != PQfnumber (res, "oid"))
363 )
364 { 343 {
365 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 344 enum GNUNET_DB_QueryStatus qs;
366 "Unexpected table retrieved for array types\n"); 345 struct GNUNET_PQ_QueryParam params[] = {
367 return GNUNET_SYSERR; 346 GNUNET_PQ_query_param_string (name),
347 GNUNET_PQ_query_param_end
348 };
349 struct GNUNET_PQ_ResultSpec spec[] = {
350 GNUNET_PQ_result_spec_uint32 ("oid",
351 oid),
352 GNUNET_PQ_result_spec_end
353 };
354
355 GNUNET_assert (NULL != db);
356
357 qs = GNUNET_PQ_eval_prepared_singleton_select (db,
358 "gnunet_pq_get_oid_by_name",
359 params,
360 spec);
361 if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
362 return GNUNET_SYSERR;
368 } 363 }
369 364
365 /* Add the entry to the cache */
366 if (NULL == db->oids.table)
370 { 367 {
371 int nrows = PQntuples (res); 368 db->oids.table = GNUNET_new_array (8,
372 int nfound = 1; /* skip GNUNET_PQ_DATATYPE_UNKNOWN */ 369 typeof(*db->oids.table));
373 char dummy; 370 db->oids.cap = 8;
374 371 db->oids.num = 0;
375 for (int r = 0; r < nrows; r++)
376 {
377 enum GNUNET_PQ_DataTypes atype = GNUNET_PQ_DATATYPE_UNKNOWN;
378 char *typ_s = PQgetvalue (res,r,0);
379 char *oid_s = PQgetvalue (res,r,1);
380 GNUNET_assert (NULL != typ_s);
381 GNUNET_assert (NULL != oid_s);
382
383 if (! strcmp (typ_s,"bool"))
384 atype = GNUNET_PQ_DATATYPE_BOOL;
385 else if (! strcmp (typ_s,"int2"))
386 atype = GNUNET_PQ_DATATYPE_INT2;
387 else if (! strcmp (typ_s,"int4"))
388 atype = GNUNET_PQ_DATATYPE_INT4;
389 else if (! strcmp (typ_s,"int8"))
390 atype = GNUNET_PQ_DATATYPE_INT8;
391 else if (! strcmp (typ_s,"bytea"))
392 atype = GNUNET_PQ_DATATYPE_BYTEA;
393 else if (! strcmp (typ_s,"varchar"))
394 atype = GNUNET_PQ_DATATYPE_VARCHAR;
395 else
396 continue;
397
398 GNUNET_assert (GNUNET_PQ_DATATYPE_MAX > atype);
399
400 if ( (GNUNET_PQ_DATATYPE_UNKNOWN != atype) &&
401 (1 == sscanf (oid_s,
402 "%u%c",
403 &db->oids[atype],
404 &dummy)))
405 {
406 nfound++;
407 }
408 }
409
410 if (GNUNET_PQ_DATATYPE_MAX != nfound)
411 {
412 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
413 "Couldn't find all array types, only found %d of %d!\n",
414 nfound - 1,
415 GNUNET_PQ_DATATYPE_MAX - 1);
416 return GNUNET_SYSERR;
417 }
418 } 372 }
419 return GNUNET_OK;
420}
421 373
374 if (db->oids.cap <= db->oids.num)
375 GNUNET_array_grow (db->oids.table,
376 db->oids.cap,
377 db->oids.cap + 8);
422 378
423Oid 379 db->oids.table[db->oids.num].name = name;
424GNUNET_PQ_get_oid ( 380 db->oids.table[db->oids.num].oid = *oid;
425 const struct GNUNET_PQ_Context *db, 381 db->oids.num++;
426 enum GNUNET_PQ_DataTypes typ) 382
427{ 383 return GNUNET_OK;
428 GNUNET_assert (GNUNET_PQ_DATATYPE_MAX > typ);
429 return db->oids[typ];
430} 384}
431 385
432 386
387/**
388 * Load the initial set of OIDs for the supported
389 * array-datatypes
390 *
391 * @param db The database context
392 * @return GNUNET_OK on success, GNUNET_SYSERR if any of the types couldn't be found
393 */
394static
433enum GNUNET_GenericReturnValue 395enum GNUNET_GenericReturnValue
434GNUNET_PQ_get_oid_by_name ( 396load_initial_oids (struct GNUNET_PQ_Context *db)
435 struct GNUNET_PQ_Context *db,
436 const char *name,
437 Oid *oid)
438{ 397{
439 char *typname; 398 static const char *typnames[] = {
440 enum GNUNET_DB_QueryStatus qs; 399 "bool",
441 struct GNUNET_PQ_QueryParam params[] = { 400 "int2",
442 GNUNET_PQ_query_param_string (name), 401 "int4",
443 GNUNET_PQ_query_param_end 402 "int8",
444 }; 403 "bytea",
445 struct GNUNET_PQ_ResultSpec rs[] = { 404 "varchar"
446 GNUNET_PQ_result_spec_string ("typname",
447 &typname),
448 GNUNET_PQ_result_spec_uint32 ("oid",
449 oid),
450 GNUNET_PQ_result_spec_end
451 }; 405 };
406 Oid oid;
452 407
453 GNUNET_assert (NULL != db); 408 for (size_t i = 0; i< sizeof(typnames) / sizeof(*typnames); i++)
454 409 {
455 /* Initialize to Oid(0) (= unknown) */ 410 if (GNUNET_OK !=
456 *oid = 0; 411 GNUNET_PQ_get_oid_by_name (db,
457 412 typnames[i],
458 qs = GNUNET_PQ_eval_prepared_singleton_select (db, 413 &oid))
459 "gnunet_pq_get_oid_by_name", 414 {
460 params, 415 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
461 rs); 416 "pq",
462 if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) 417 "Couldn't retrieve OID for type %s\n",
463 return GNUNET_SYSERR; 418 typnames[i]);
464 419 return GNUNET_SYSERR;
465 if (0 != strcasecmp (typname, name)) 420 }
466 return GNUNET_SYSERR; 421 }
467
468 return GNUNET_OK; 422 return GNUNET_OK;
469} 423}
470 424
@@ -559,16 +513,6 @@ GNUNET_PQ_reconnect (struct GNUNET_PQ_Context *db)
559 } 513 }
560 } 514 }
561 515
562 /* Retrieve the OIDs for the supported Array types */
563 if (GNUNET_SYSERR == get_array_type_oids (db))
564 {
565 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
566 "Failed to retrieve OID information for array types!\n");
567 PQfinish (db->conn);
568 db->conn = NULL;
569 return;
570 }
571
572 /* Prepare statement for OID lookup by name */ 516 /* Prepare statement for OID lookup by name */
573 { 517 {
574 PGresult *res; 518 PGresult *res;
@@ -596,6 +540,18 @@ GNUNET_PQ_reconnect (struct GNUNET_PQ_Context *db)
596 PQclear (res); 540 PQclear (res);
597 } 541 }
598 542
543 /* Reset the OID-cache and retrieve the OIDs for the supported Array types */
544 db->oids.num = 0;
545 if (GNUNET_SYSERR == load_initial_oids (db))
546 {
547 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
548 "Failed to retrieve OID information for array types!\n");
549 PQfinish (db->conn);
550 db->conn = NULL;
551 return;
552 }
553
554
599 if (NULL != db->auto_suffix) 555 if (NULL != db->auto_suffix)
600 { 556 {
601 PGresult *res; 557 PGresult *res;
diff --git a/src/pq/pq_query_helper.c b/src/pq/pq_query_helper.c
index 0199f21dd..71421345f 100644
--- a/src/pq/pq_query_helper.c
+++ b/src/pq/pq_query_helper.c
@@ -962,15 +962,18 @@ struct GNUNET_PQ_QueryParam
962GNUNET_PQ_query_param_array_bool ( 962GNUNET_PQ_query_param_array_bool (
963 unsigned int num, 963 unsigned int num,
964 const bool *elements, 964 const bool *elements,
965 const struct GNUNET_PQ_Context *db) 965 struct GNUNET_PQ_Context *db)
966{ 966{
967 Oid oid;
968 GNUNET_assert (GNUNET_OK ==
969 GNUNET_PQ_get_oid_by_name (db,"bool",&oid));
967 return query_param_array_generic (num, 970 return query_param_array_generic (num,
968 true, 971 true,
969 elements, 972 elements,
970 NULL, 973 NULL,
971 sizeof(bool), 974 sizeof(bool),
972 array_of_bool, 975 array_of_bool,
973 db->oids[GNUNET_PQ_DATATYPE_BOOL]); 976 oid);
974} 977}
975 978
976 979
@@ -978,15 +981,18 @@ struct GNUNET_PQ_QueryParam
978GNUNET_PQ_query_param_array_uint16 ( 981GNUNET_PQ_query_param_array_uint16 (
979 unsigned int num, 982 unsigned int num,
980 const uint16_t *elements, 983 const uint16_t *elements,
981 const struct GNUNET_PQ_Context *db) 984 struct GNUNET_PQ_Context *db)
982{ 985{
986 Oid oid;
987 GNUNET_assert (GNUNET_OK ==
988 GNUNET_PQ_get_oid_by_name (db,"int2",&oid));
983 return query_param_array_generic (num, 989 return query_param_array_generic (num,
984 true, 990 true,
985 elements, 991 elements,
986 NULL, 992 NULL,
987 sizeof(uint16_t), 993 sizeof(uint16_t),
988 array_of_uint16, 994 array_of_uint16,
989 db->oids[GNUNET_PQ_DATATYPE_INT2]); 995 oid);
990} 996}
991 997
992 998
@@ -994,15 +1000,18 @@ struct GNUNET_PQ_QueryParam
994GNUNET_PQ_query_param_array_uint32 ( 1000GNUNET_PQ_query_param_array_uint32 (
995 unsigned int num, 1001 unsigned int num,
996 const uint32_t *elements, 1002 const uint32_t *elements,
997 const struct GNUNET_PQ_Context *db) 1003 struct GNUNET_PQ_Context *db)
998{ 1004{
1005 Oid oid;
1006 GNUNET_assert (GNUNET_OK ==
1007 GNUNET_PQ_get_oid_by_name (db,"int4",&oid));
999 return query_param_array_generic (num, 1008 return query_param_array_generic (num,
1000 true, 1009 true,
1001 elements, 1010 elements,
1002 NULL, 1011 NULL,
1003 sizeof(uint32_t), 1012 sizeof(uint32_t),
1004 array_of_uint32, 1013 array_of_uint32,
1005 db->oids[GNUNET_PQ_DATATYPE_INT4]); 1014 oid);
1006} 1015}
1007 1016
1008 1017
@@ -1010,15 +1019,18 @@ struct GNUNET_PQ_QueryParam
1010GNUNET_PQ_query_param_array_uint64 ( 1019GNUNET_PQ_query_param_array_uint64 (
1011 unsigned int num, 1020 unsigned int num,
1012 const uint64_t *elements, 1021 const uint64_t *elements,
1013 const struct GNUNET_PQ_Context *db) 1022 struct GNUNET_PQ_Context *db)
1014{ 1023{
1024 Oid oid;
1025 GNUNET_assert (GNUNET_OK ==
1026 GNUNET_PQ_get_oid_by_name (db,"int8",&oid));
1015 return query_param_array_generic (num, 1027 return query_param_array_generic (num,
1016 true, 1028 true,
1017 elements, 1029 elements,
1018 NULL, 1030 NULL,
1019 sizeof(uint64_t), 1031 sizeof(uint64_t),
1020 array_of_uint64, 1032 array_of_uint64,
1021 db->oids[GNUNET_PQ_DATATYPE_INT8]); 1033 oid);
1022} 1034}
1023 1035
1024 1036
@@ -1027,15 +1039,18 @@ GNUNET_PQ_query_param_array_bytes (
1027 unsigned int num, 1039 unsigned int num,
1028 const void *elements, 1040 const void *elements,
1029 const size_t *sizes, 1041 const size_t *sizes,
1030 const struct GNUNET_PQ_Context *db) 1042 struct GNUNET_PQ_Context *db)
1031{ 1043{
1044 Oid oid;
1045 GNUNET_assert (GNUNET_OK ==
1046 GNUNET_PQ_get_oid_by_name (db,"bytea",&oid));
1032 return query_param_array_generic (num, 1047 return query_param_array_generic (num,
1033 true, 1048 true,
1034 elements, 1049 elements,
1035 sizes, 1050 sizes,
1036 0, 1051 0,
1037 array_of_byte, 1052 array_of_byte,
1038 db->oids[GNUNET_PQ_DATATYPE_BYTEA]); 1053 oid);
1039} 1054}
1040 1055
1041 1056
@@ -1044,15 +1059,18 @@ GNUNET_PQ_query_param_array_ptrs_bytes (
1044 unsigned int num, 1059 unsigned int num,
1045 const void *elements[], 1060 const void *elements[],
1046 const size_t *sizes, 1061 const size_t *sizes,
1047 const struct GNUNET_PQ_Context *db) 1062 struct GNUNET_PQ_Context *db)
1048{ 1063{
1064 Oid oid;
1065 GNUNET_assert (GNUNET_OK ==
1066 GNUNET_PQ_get_oid_by_name (db,"bytea",&oid));
1049 return query_param_array_generic (num, 1067 return query_param_array_generic (num,
1050 false, 1068 false,
1051 elements, 1069 elements,
1052 sizes, 1070 sizes,
1053 0, 1071 0,
1054 array_of_byte, 1072 array_of_byte,
1055 db->oids[GNUNET_PQ_DATATYPE_BYTEA]); 1073 oid);
1056} 1074}
1057 1075
1058 1076
@@ -1061,15 +1079,18 @@ GNUNET_PQ_query_param_array_bytes_same_size (
1061 unsigned int num, 1079 unsigned int num,
1062 const void *elements, 1080 const void *elements,
1063 size_t same_size, 1081 size_t same_size,
1064 const struct GNUNET_PQ_Context *db) 1082 struct GNUNET_PQ_Context *db)
1065{ 1083{
1084 Oid oid;
1085 GNUNET_assert (GNUNET_OK ==
1086 GNUNET_PQ_get_oid_by_name (db,"bytea",&oid));
1066 return query_param_array_generic (num, 1087 return query_param_array_generic (num,
1067 true, 1088 true,
1068 elements, 1089 elements,
1069 NULL, 1090 NULL,
1070 same_size, 1091 same_size,
1071 array_of_byte, 1092 array_of_byte,
1072 db->oids[GNUNET_PQ_DATATYPE_BYTEA]); 1093 oid);
1073} 1094}
1074 1095
1075 1096
@@ -1078,15 +1099,18 @@ GNUNET_PQ_query_param_array_ptrs_bytes_same_size (
1078 unsigned int num, 1099 unsigned int num,
1079 const void *elements[], 1100 const void *elements[],
1080 size_t same_size, 1101 size_t same_size,
1081 const struct GNUNET_PQ_Context *db) 1102 struct GNUNET_PQ_Context *db)
1082{ 1103{
1104 Oid oid;
1105 GNUNET_assert (GNUNET_OK ==
1106 GNUNET_PQ_get_oid_by_name (db,"bytea",&oid));
1083 return query_param_array_generic (num, 1107 return query_param_array_generic (num,
1084 false, 1108 false,
1085 elements, 1109 elements,
1086 NULL, 1110 NULL,
1087 same_size, 1111 same_size,
1088 array_of_byte, 1112 array_of_byte,
1089 db->oids[GNUNET_PQ_DATATYPE_BYTEA]); 1113 oid);
1090} 1114}
1091 1115
1092 1116
@@ -1094,15 +1118,18 @@ struct GNUNET_PQ_QueryParam
1094GNUNET_PQ_query_param_array_string ( 1118GNUNET_PQ_query_param_array_string (
1095 unsigned int num, 1119 unsigned int num,
1096 const char *elements, 1120 const char *elements,
1097 const struct GNUNET_PQ_Context *db) 1121 struct GNUNET_PQ_Context *db)
1098{ 1122{
1123 Oid oid;
1124 GNUNET_assert (GNUNET_OK ==
1125 GNUNET_PQ_get_oid_by_name (db,"varchar",&oid));
1099 return query_param_array_generic (num, 1126 return query_param_array_generic (num,
1100 true, 1127 true,
1101 elements, 1128 elements,
1102 NULL, 1129 NULL,
1103 0, 1130 0,
1104 array_of_string, 1131 array_of_string,
1105 db->oids[GNUNET_PQ_DATATYPE_VARCHAR]); 1132 oid);
1106} 1133}
1107 1134
1108 1135
@@ -1110,15 +1137,18 @@ struct GNUNET_PQ_QueryParam
1110GNUNET_PQ_query_param_array_ptrs_string ( 1137GNUNET_PQ_query_param_array_ptrs_string (
1111 unsigned int num, 1138 unsigned int num,
1112 const char *elements[], 1139 const char *elements[],
1113 const struct GNUNET_PQ_Context *db) 1140 struct GNUNET_PQ_Context *db)
1114{ 1141{
1142 Oid oid;
1143 GNUNET_assert (GNUNET_OK ==
1144 GNUNET_PQ_get_oid_by_name (db,"varchar",&oid));
1115 return query_param_array_generic (num, 1145 return query_param_array_generic (num,
1116 false, 1146 false,
1117 elements, 1147 elements,
1118 NULL, 1148 NULL,
1119 0, 1149 0,
1120 array_of_string, 1150 array_of_string,
1121 db->oids[GNUNET_PQ_DATATYPE_VARCHAR]); 1151 oid);
1122} 1152}
1123 1153
1124 1154
@@ -1126,15 +1156,18 @@ struct GNUNET_PQ_QueryParam
1126GNUNET_PQ_query_param_array_abs_time ( 1156GNUNET_PQ_query_param_array_abs_time (
1127 unsigned int num, 1157 unsigned int num,
1128 const struct GNUNET_TIME_Absolute *elements, 1158 const struct GNUNET_TIME_Absolute *elements,
1129 const struct GNUNET_PQ_Context *db) 1159 struct GNUNET_PQ_Context *db)
1130{ 1160{
1161 Oid oid;
1162 GNUNET_assert (GNUNET_OK ==
1163 GNUNET_PQ_get_oid_by_name (db,"int8",&oid));
1131 return query_param_array_generic (num, 1164 return query_param_array_generic (num,
1132 true, 1165 true,
1133 elements, 1166 elements,
1134 NULL, 1167 NULL,
1135 sizeof(struct GNUNET_TIME_Absolute), 1168 sizeof(struct GNUNET_TIME_Absolute),
1136 array_of_abs_time, 1169 array_of_abs_time,
1137 db->oids[GNUNET_PQ_DATATYPE_INT8]); 1170 oid);
1138} 1171}
1139 1172
1140 1173
@@ -1142,15 +1175,18 @@ struct GNUNET_PQ_QueryParam
1142GNUNET_PQ_query_param_array_ptrs_abs_time ( 1175GNUNET_PQ_query_param_array_ptrs_abs_time (
1143 unsigned int num, 1176 unsigned int num,
1144 const struct GNUNET_TIME_Absolute *elements[], 1177 const struct GNUNET_TIME_Absolute *elements[],
1145 const struct GNUNET_PQ_Context *db) 1178 struct GNUNET_PQ_Context *db)
1146{ 1179{
1180 Oid oid;
1181 GNUNET_assert (GNUNET_OK ==
1182 GNUNET_PQ_get_oid_by_name (db,"int8",&oid));
1147 return query_param_array_generic (num, 1183 return query_param_array_generic (num,
1148 false, 1184 false,
1149 elements, 1185 elements,
1150 NULL, 1186 NULL,
1151 sizeof(struct GNUNET_TIME_Absolute), 1187 sizeof(struct GNUNET_TIME_Absolute),
1152 array_of_abs_time, 1188 array_of_abs_time,
1153 db->oids[GNUNET_PQ_DATATYPE_INT8]); 1189 oid);
1154} 1190}
1155 1191
1156 1192
@@ -1158,15 +1194,18 @@ struct GNUNET_PQ_QueryParam
1158GNUNET_PQ_query_param_array_rel_time ( 1194GNUNET_PQ_query_param_array_rel_time (
1159 unsigned int num, 1195 unsigned int num,
1160 const struct GNUNET_TIME_Relative *elements, 1196 const struct GNUNET_TIME_Relative *elements,
1161 const struct GNUNET_PQ_Context *db) 1197 struct GNUNET_PQ_Context *db)
1162{ 1198{
1199 Oid oid;
1200 GNUNET_assert (GNUNET_OK ==
1201 GNUNET_PQ_get_oid_by_name (db,"int8",&oid));
1163 return query_param_array_generic (num, 1202 return query_param_array_generic (num,
1164 true, 1203 true,
1165 elements, 1204 elements,
1166 NULL, 1205 NULL,
1167 sizeof(struct GNUNET_TIME_Relative), 1206 sizeof(struct GNUNET_TIME_Relative),
1168 array_of_abs_time, 1207 array_of_abs_time,
1169 db->oids[GNUNET_PQ_DATATYPE_INT8]); 1208 oid);
1170} 1209}
1171 1210
1172 1211
@@ -1174,15 +1213,18 @@ struct GNUNET_PQ_QueryParam
1174GNUNET_PQ_query_param_array_ptrs_rel_time ( 1213GNUNET_PQ_query_param_array_ptrs_rel_time (
1175 unsigned int num, 1214 unsigned int num,
1176 const struct GNUNET_TIME_Relative *elements[], 1215 const struct GNUNET_TIME_Relative *elements[],
1177 const struct GNUNET_PQ_Context *db) 1216 struct GNUNET_PQ_Context *db)
1178{ 1217{
1218 Oid oid;
1219 GNUNET_assert (GNUNET_OK ==
1220 GNUNET_PQ_get_oid_by_name (db,"int8",&oid));
1179 return query_param_array_generic (num, 1221 return query_param_array_generic (num,
1180 false, 1222 false,
1181 elements, 1223 elements,
1182 NULL, 1224 NULL,
1183 sizeof(struct GNUNET_TIME_Relative), 1225 sizeof(struct GNUNET_TIME_Relative),
1184 array_of_abs_time, 1226 array_of_abs_time,
1185 db->oids[GNUNET_PQ_DATATYPE_INT8]); 1227 oid);
1186} 1228}
1187 1229
1188 1230
@@ -1190,15 +1232,18 @@ struct GNUNET_PQ_QueryParam
1190GNUNET_PQ_query_param_array_timestamp ( 1232GNUNET_PQ_query_param_array_timestamp (
1191 unsigned int num, 1233 unsigned int num,
1192 const struct GNUNET_TIME_Timestamp *elements, 1234 const struct GNUNET_TIME_Timestamp *elements,
1193 const struct GNUNET_PQ_Context *db) 1235 struct GNUNET_PQ_Context *db)
1194{ 1236{
1237 Oid oid;
1238 GNUNET_assert (GNUNET_OK ==
1239 GNUNET_PQ_get_oid_by_name (db,"int8",&oid));
1195 return query_param_array_generic (num, 1240 return query_param_array_generic (num,
1196 true, 1241 true,
1197 elements, 1242 elements,
1198 NULL, 1243 NULL,
1199 sizeof(struct GNUNET_TIME_Timestamp), 1244 sizeof(struct GNUNET_TIME_Timestamp),
1200 array_of_timestamp, 1245 array_of_timestamp,
1201 db->oids[GNUNET_PQ_DATATYPE_INT8]); 1246 oid);
1202} 1247}
1203 1248
1204 1249
@@ -1206,15 +1251,18 @@ struct GNUNET_PQ_QueryParam
1206GNUNET_PQ_query_param_array_ptrs_timestamp ( 1251GNUNET_PQ_query_param_array_ptrs_timestamp (
1207 unsigned int num, 1252 unsigned int num,
1208 const struct GNUNET_TIME_Timestamp *elements[], 1253 const struct GNUNET_TIME_Timestamp *elements[],
1209 const struct GNUNET_PQ_Context *db) 1254 struct GNUNET_PQ_Context *db)
1210{ 1255{
1256 Oid oid;
1257 GNUNET_assert (GNUNET_OK ==
1258 GNUNET_PQ_get_oid_by_name (db,"int8",&oid));
1211 return query_param_array_generic (num, 1259 return query_param_array_generic (num,
1212 false, 1260 false,
1213 elements, 1261 elements,
1214 NULL, 1262 NULL,
1215 sizeof(struct GNUNET_TIME_Timestamp), 1263 sizeof(struct GNUNET_TIME_Timestamp),
1216 array_of_timestamp, 1264 array_of_timestamp,
1217 db->oids[GNUNET_PQ_DATATYPE_INT8]); 1265 oid);
1218} 1266}
1219 1267
1220 1268
diff --git a/src/pq/pq_result_helper.c b/src/pq/pq_result_helper.c
index 5f6215fc1..d0cb8c4b6 100644
--- a/src/pq/pq_result_helper.c
+++ b/src/pq/pq_result_helper.c
@@ -1429,7 +1429,7 @@ array_cleanup (void *cls,
1429 1429
1430struct GNUNET_PQ_ResultSpec 1430struct GNUNET_PQ_ResultSpec
1431GNUNET_PQ_result_spec_array_bool ( 1431GNUNET_PQ_result_spec_array_bool (
1432 const struct GNUNET_PQ_Context *db, 1432 struct GNUNET_PQ_Context *db,
1433 const char *name, 1433 const char *name,
1434 size_t *num, 1434 size_t *num,
1435 bool **dst) 1435 bool **dst)
@@ -1439,7 +1439,10 @@ GNUNET_PQ_result_spec_array_bool (
1439 1439
1440 info->num = num; 1440 info->num = num;
1441 info->typ = array_of_bool; 1441 info->typ = array_of_bool;
1442 info->oid = db->oids[GNUNET_PQ_DATATYPE_BOOL]; 1442 GNUNET_assert (GNUNET_OK ==
1443 GNUNET_PQ_get_oid_by_name (db,
1444 "bool",
1445 &info->oid));
1443 1446
1444 struct GNUNET_PQ_ResultSpec res = { 1447 struct GNUNET_PQ_ResultSpec res = {
1445 .conv = extract_array_generic, 1448 .conv = extract_array_generic,
@@ -1454,7 +1457,7 @@ GNUNET_PQ_result_spec_array_bool (
1454 1457
1455struct GNUNET_PQ_ResultSpec 1458struct GNUNET_PQ_ResultSpec
1456GNUNET_PQ_result_spec_array_uint16 ( 1459GNUNET_PQ_result_spec_array_uint16 (
1457 const struct GNUNET_PQ_Context *db, 1460 struct GNUNET_PQ_Context *db,
1458 const char *name, 1461 const char *name,
1459 size_t *num, 1462 size_t *num,
1460 uint16_t **dst) 1463 uint16_t **dst)
@@ -1464,7 +1467,10 @@ GNUNET_PQ_result_spec_array_uint16 (
1464 1467
1465 info->num = num; 1468 info->num = num;
1466 info->typ = array_of_uint16; 1469 info->typ = array_of_uint16;
1467 info->oid = db->oids[GNUNET_PQ_DATATYPE_INT2]; 1470 GNUNET_assert (GNUNET_OK ==
1471 GNUNET_PQ_get_oid_by_name (db,
1472 "int2",
1473 &info->oid));
1468 1474
1469 struct GNUNET_PQ_ResultSpec res = { 1475 struct GNUNET_PQ_ResultSpec res = {
1470 .conv = extract_array_generic, 1476 .conv = extract_array_generic,
@@ -1479,7 +1485,7 @@ GNUNET_PQ_result_spec_array_uint16 (
1479 1485
1480struct GNUNET_PQ_ResultSpec 1486struct GNUNET_PQ_ResultSpec
1481GNUNET_PQ_result_spec_array_uint32 ( 1487GNUNET_PQ_result_spec_array_uint32 (
1482 const struct GNUNET_PQ_Context *db, 1488 struct GNUNET_PQ_Context *db,
1483 const char *name, 1489 const char *name,
1484 size_t *num, 1490 size_t *num,
1485 uint32_t **dst) 1491 uint32_t **dst)
@@ -1489,7 +1495,10 @@ GNUNET_PQ_result_spec_array_uint32 (
1489 1495
1490 info->num = num; 1496 info->num = num;
1491 info->typ = array_of_uint32; 1497 info->typ = array_of_uint32;
1492 info->oid = db->oids[GNUNET_PQ_DATATYPE_INT4]; 1498 GNUNET_assert (GNUNET_OK ==
1499 GNUNET_PQ_get_oid_by_name (db,
1500 "int4",
1501 &info->oid));
1493 1502
1494 struct GNUNET_PQ_ResultSpec res = { 1503 struct GNUNET_PQ_ResultSpec res = {
1495 .conv = extract_array_generic, 1504 .conv = extract_array_generic,
@@ -1504,7 +1513,7 @@ GNUNET_PQ_result_spec_array_uint32 (
1504 1513
1505struct GNUNET_PQ_ResultSpec 1514struct GNUNET_PQ_ResultSpec
1506GNUNET_PQ_result_spec_array_uint64 ( 1515GNUNET_PQ_result_spec_array_uint64 (
1507 const struct GNUNET_PQ_Context *db, 1516 struct GNUNET_PQ_Context *db,
1508 const char *name, 1517 const char *name,
1509 size_t *num, 1518 size_t *num,
1510 uint64_t **dst) 1519 uint64_t **dst)
@@ -1514,7 +1523,10 @@ GNUNET_PQ_result_spec_array_uint64 (
1514 1523
1515 info->num = num; 1524 info->num = num;
1516 info->typ = array_of_uint64; 1525 info->typ = array_of_uint64;
1517 info->oid = db->oids[GNUNET_PQ_DATATYPE_INT8]; 1526 GNUNET_assert (GNUNET_OK ==
1527 GNUNET_PQ_get_oid_by_name (db,
1528 "int8",
1529 &info->oid));
1518 1530
1519 struct GNUNET_PQ_ResultSpec res = { 1531 struct GNUNET_PQ_ResultSpec res = {
1520 .conv = extract_array_generic, 1532 .conv = extract_array_generic,
@@ -1529,7 +1541,7 @@ GNUNET_PQ_result_spec_array_uint64 (
1529 1541
1530struct GNUNET_PQ_ResultSpec 1542struct GNUNET_PQ_ResultSpec
1531GNUNET_PQ_result_spec_array_abs_time ( 1543GNUNET_PQ_result_spec_array_abs_time (
1532 const struct GNUNET_PQ_Context *db, 1544 struct GNUNET_PQ_Context *db,
1533 const char *name, 1545 const char *name,
1534 size_t *num, 1546 size_t *num,
1535 struct GNUNET_TIME_Absolute **dst) 1547 struct GNUNET_TIME_Absolute **dst)
@@ -1539,7 +1551,10 @@ GNUNET_PQ_result_spec_array_abs_time (
1539 1551
1540 info->num = num; 1552 info->num = num;
1541 info->typ = array_of_abs_time; 1553 info->typ = array_of_abs_time;
1542 info->oid = db->oids[GNUNET_PQ_DATATYPE_INT8]; 1554 GNUNET_assert (GNUNET_OK ==
1555 GNUNET_PQ_get_oid_by_name (db,
1556 "int8",
1557 &info->oid));
1543 1558
1544 struct GNUNET_PQ_ResultSpec res = { 1559 struct GNUNET_PQ_ResultSpec res = {
1545 .conv = extract_array_generic, 1560 .conv = extract_array_generic,
@@ -1554,7 +1569,7 @@ GNUNET_PQ_result_spec_array_abs_time (
1554 1569
1555struct GNUNET_PQ_ResultSpec 1570struct GNUNET_PQ_ResultSpec
1556GNUNET_PQ_result_spec_array_rel_time ( 1571GNUNET_PQ_result_spec_array_rel_time (
1557 const struct GNUNET_PQ_Context *db, 1572 struct GNUNET_PQ_Context *db,
1558 const char *name, 1573 const char *name,
1559 size_t *num, 1574 size_t *num,
1560 struct GNUNET_TIME_Relative **dst) 1575 struct GNUNET_TIME_Relative **dst)
@@ -1564,7 +1579,10 @@ GNUNET_PQ_result_spec_array_rel_time (
1564 1579
1565 info->num = num; 1580 info->num = num;
1566 info->typ = array_of_rel_time; 1581 info->typ = array_of_rel_time;
1567 info->oid = db->oids[GNUNET_PQ_DATATYPE_INT8]; 1582 GNUNET_assert (GNUNET_OK ==
1583 GNUNET_PQ_get_oid_by_name (db,
1584 "int8",
1585 &info->oid));
1568 1586
1569 struct GNUNET_PQ_ResultSpec res = { 1587 struct GNUNET_PQ_ResultSpec res = {
1570 .conv = extract_array_generic, 1588 .conv = extract_array_generic,
@@ -1579,7 +1597,7 @@ GNUNET_PQ_result_spec_array_rel_time (
1579 1597
1580struct GNUNET_PQ_ResultSpec 1598struct GNUNET_PQ_ResultSpec
1581GNUNET_PQ_result_spec_array_timestamp ( 1599GNUNET_PQ_result_spec_array_timestamp (
1582 const struct GNUNET_PQ_Context *db, 1600 struct GNUNET_PQ_Context *db,
1583 const char *name, 1601 const char *name,
1584 size_t *num, 1602 size_t *num,
1585 struct GNUNET_TIME_Timestamp **dst) 1603 struct GNUNET_TIME_Timestamp **dst)
@@ -1589,7 +1607,10 @@ GNUNET_PQ_result_spec_array_timestamp (
1589 1607
1590 info->num = num; 1608 info->num = num;
1591 info->typ = array_of_timestamp; 1609 info->typ = array_of_timestamp;
1592 info->oid = db->oids[GNUNET_PQ_DATATYPE_INT8]; 1610 GNUNET_assert (GNUNET_OK ==
1611 GNUNET_PQ_get_oid_by_name (db,
1612 "int8",
1613 &info->oid));
1593 1614
1594 struct GNUNET_PQ_ResultSpec res = { 1615 struct GNUNET_PQ_ResultSpec res = {
1595 .conv = extract_array_generic, 1616 .conv = extract_array_generic,
@@ -1604,7 +1625,7 @@ GNUNET_PQ_result_spec_array_timestamp (
1604 1625
1605struct GNUNET_PQ_ResultSpec 1626struct GNUNET_PQ_ResultSpec
1606GNUNET_PQ_result_spec_array_variable_size ( 1627GNUNET_PQ_result_spec_array_variable_size (
1607 const struct GNUNET_PQ_Context *db, 1628 struct GNUNET_PQ_Context *db,
1608 const char *name, 1629 const char *name,
1609 size_t *num, 1630 size_t *num,
1610 size_t **sizes, 1631 size_t **sizes,
@@ -1616,7 +1637,10 @@ GNUNET_PQ_result_spec_array_variable_size (
1616 info->num = num; 1637 info->num = num;
1617 info->sizes = sizes; 1638 info->sizes = sizes;
1618 info->typ = array_of_byte; 1639 info->typ = array_of_byte;
1619 info->oid = db->oids[GNUNET_PQ_DATATYPE_BYTEA]; 1640 GNUNET_assert (GNUNET_OK ==
1641 GNUNET_PQ_get_oid_by_name (db,
1642 "bytea",
1643 &info->oid));
1620 1644
1621 struct GNUNET_PQ_ResultSpec res = { 1645 struct GNUNET_PQ_ResultSpec res = {
1622 .conv = extract_array_generic, 1646 .conv = extract_array_generic,
@@ -1631,7 +1655,7 @@ GNUNET_PQ_result_spec_array_variable_size (
1631 1655
1632struct GNUNET_PQ_ResultSpec 1656struct GNUNET_PQ_ResultSpec
1633GNUNET_PQ_result_spec_array_fixed_size ( 1657GNUNET_PQ_result_spec_array_fixed_size (
1634 const struct GNUNET_PQ_Context *db, 1658 struct GNUNET_PQ_Context *db,
1635 const char *name, 1659 const char *name,
1636 size_t size, 1660 size_t size,
1637 size_t *num, 1661 size_t *num,
@@ -1643,7 +1667,10 @@ GNUNET_PQ_result_spec_array_fixed_size (
1643 info->num = num; 1667 info->num = num;
1644 info->same_size = size; 1668 info->same_size = size;
1645 info->typ = array_of_byte; 1669 info->typ = array_of_byte;
1646 info->oid = db->oids[GNUNET_PQ_DATATYPE_BYTEA]; 1670 GNUNET_assert (GNUNET_OK ==
1671 GNUNET_PQ_get_oid_by_name (db,
1672 "bytea",
1673 &info->oid));
1647 1674
1648 struct GNUNET_PQ_ResultSpec res = { 1675 struct GNUNET_PQ_ResultSpec res = {
1649 .conv = extract_array_generic, 1676 .conv = extract_array_generic,
@@ -1658,7 +1685,7 @@ GNUNET_PQ_result_spec_array_fixed_size (
1658 1685
1659struct GNUNET_PQ_ResultSpec 1686struct GNUNET_PQ_ResultSpec
1660GNUNET_PQ_result_spec_array_string ( 1687GNUNET_PQ_result_spec_array_string (
1661 const struct GNUNET_PQ_Context *db, 1688 struct GNUNET_PQ_Context *db,
1662 const char *name, 1689 const char *name,
1663 size_t *num, 1690 size_t *num,
1664 char **dst) 1691 char **dst)
@@ -1668,7 +1695,10 @@ GNUNET_PQ_result_spec_array_string (
1668 1695
1669 info->num = num; 1696 info->num = num;
1670 info->typ = array_of_string; 1697 info->typ = array_of_string;
1671 info->oid = db->oids[GNUNET_PQ_DATATYPE_VARCHAR]; 1698 GNUNET_assert (GNUNET_OK ==
1699 GNUNET_PQ_get_oid_by_name (db,
1700 "varchar",
1701 &info->oid));
1672 1702
1673 struct GNUNET_PQ_ResultSpec res = { 1703 struct GNUNET_PQ_ResultSpec res = {
1674 .conv = extract_array_generic, 1704 .conv = extract_array_generic,