const struct GNUNET_CRYPTO_RsaSignature *x);
+/**
+ * Generate query parameter for a relative time value.
+ * The database must store a 64-bit integer.
+ *
+ * @param x pointer to the query parameter to pass
+ */
+struct GNUNET_PQ_QueryParam
+GNUNET_PQ_query_param_relative_time (const struct GNUNET_TIME_Relative *x);
+
+
/**
* Generate query parameter for an absolute time value.
* The database must store a 64-bit integer.
struct GNUNET_TIME_Absolute *at);
+/**
+ * Relative time expected.
+ *
+ * @param name name of the field in the table
+ * @param[out] rt where to store the result
+ * @return array entry for the result specification to use
+ */
+struct GNUNET_PQ_ResultSpec
+GNUNET_PQ_result_spec_relative_time (const char *name,
+ struct GNUNET_TIME_Relative *rt);
+
+
/**
* Absolute time expected.
*
}
+/**
+ * Function called to convert input argument into SQL parameters.
+ *
+ * @param cls closure
+ * @param data pointer to input argument
+ * @param data_len number of bytes in @a data (if applicable)
+ * @param[out] param_values SQL data to set
+ * @param[out] param_lengths SQL length data to set
+ * @param[out] param_formats SQL format data to set
+ * @param param_length number of entries available in the @a param_values, @a param_lengths and @a param_formats arrays
+ * @param[out] scratch buffer for dynamic allocations (to be done via #GNUNET_malloc()
+ * @param scratch_length number of entries left in @a scratch
+ * @return -1 on error, number of offsets used in @a scratch otherwise
+ */
+static int
+qconv_rel_time (void *cls,
+ const void *data,
+ size_t data_len,
+ void *param_values[],
+ int param_lengths[],
+ int param_formats[],
+ unsigned int param_length,
+ void *scratch[],
+ unsigned int scratch_length)
+{
+ const struct GNUNET_TIME_Relative *u = data;
+ struct GNUNET_TIME_Relative rel;
+ uint64_t *u_nbo;
+
+ GNUNET_break (NULL == cls);
+ if (1 != param_length)
+ return -1;
+ rel = *u;
+ if (rel.rel_value_us > INT64_MAX)
+ rel.rel_value_us = INT64_MAX;
+ u_nbo = GNUNET_new (uint64_t);
+ scratch[0] = u_nbo;
+ *u_nbo = GNUNET_htonll (rel.rel_value_us);
+ param_values[0] = (void *) u_nbo;
+ param_lengths[0] = sizeof(uint64_t);
+ param_formats[0] = 1;
+ return 1;
+}
+
+
+/**
+ * Generate query parameter for a relative time value.
+ * The database must store a 64-bit integer.
+ *
+ * @param x pointer to the query parameter to pass
+ * @return array entry for the query parameters to use
+ */
+struct GNUNET_PQ_QueryParam
+GNUNET_PQ_query_param_relative_time (const struct GNUNET_TIME_Relative *x)
+{
+ struct GNUNET_PQ_QueryParam res =
+ { &qconv_rel_time, NULL, x, sizeof(*x), 1 };
+
+ return res;
+}
+
+
/**
* Function called to convert input argument into SQL parameters.
*
}
+/**
+ * Extract data from a Postgres database @a result at row @a row.
+ *
+ * @param cls closure
+ * @param result where to extract data from
+ * @param int row to extract data from
+ * @param fname name (or prefix) of the fields to extract from
+ * @param[in,out] dst_size where to store size of result, may be NULL
+ * @param[out] dst where to store the result
+ * @return
+ * #GNUNET_YES if all results could be extracted
+ * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
+ */
+static int
+extract_rel_time (void *cls,
+ PGresult *result,
+ int row,
+ const char *fname,
+ size_t *dst_size,
+ void *dst)
+{
+ struct GNUNET_TIME_Relative *udst = dst;
+ const int64_t *res;
+ int fnum;
+
+ (void) cls;
+ fnum = PQfnumber (result,
+ fname);
+ if (fnum < 0)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if (PQgetisnull (result,
+ row,
+ fnum))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_assert (NULL != dst);
+ if (sizeof(struct GNUNET_TIME_Relative) != *dst_size)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if (sizeof(int64_t) !=
+ PQgetlength (result,
+ row,
+ fnum))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ res = (int64_t *) PQgetvalue (result,
+ row,
+ fnum);
+ if (INT64_MAX == GNUNET_ntohll ((uint64_t) *res))
+ *udst = GNUNET_TIME_UNIT_FOREVER_REL;
+ else
+ udst->rel_value_us = GNUNET_ntohll ((uint64_t) *res);
+ return GNUNET_OK;
+}
+
+
+/**
+ * Relative time expected.
+ *
+ * @param name name of the field in the table
+ * @param[out] at where to store the result
+ * @return array entry for the result specification to use
+ */
+struct GNUNET_PQ_ResultSpec
+GNUNET_PQ_result_spec_relative_time (const char *name,
+ struct GNUNET_TIME_Relative *rt)
+{
+ struct GNUNET_PQ_ResultSpec res = {
+ &extract_rel_time,
+ NULL,
+ NULL,
+ (void *) rt,
+ sizeof(*rt),
+ name,
+ NULL
+ };
+
+ return res;
+}
+
+
/**
* Extract data from a Postgres database @a result at row @a row.
*