[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] branch master updated: pq: simplified and improved API for arra
From: |
gnunet |
Subject: |
[gnunet] branch master updated: pq: simplified and improved API for array-support |
Date: |
Sun, 30 Jul 2023 00:11:39 +0200 |
This is an automated email from the git hooks/post-receive script.
oec pushed a commit to branch master
in repository gnunet.
The following commit(s) were added to refs/heads/master by this push:
new 80f5ce941 pq: simplified and improved API for array-support
80f5ce941 is described below
commit 80f5ce941d40ddffdc592a6428b4c54df00ebb28
Author: Özgür Kesim <oec-taler@kesim.org>
AuthorDate: Sun Jul 30 00:08:48 2023 +0200
pq: simplified and improved API for array-support
NEWS: GNUNET_PQ_get_oid removed, GNUNET_PQ_get_oid_by_name improved
---
src/include/gnunet_pq_lib.h | 158 +++++++++++++------------------
src/pq/pq.h | 16 +++-
src/pq/pq_connect.c | 226 ++++++++++++++++++--------------------------
src/pq/pq_query_helper.c | 112 +++++++++++++++-------
src/pq/pq_result_helper.c | 70 ++++++++++----
5 files changed, 301 insertions(+), 281 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 (
* End of query parameter specification.
*/
#define GNUNET_PQ_query_param_end \
- { \
- .conv = NULL, \
- .conv_cls = NULL, \
- .data = NULL, \
- .size = 0, \
- .num_params = 0 \
- }
+ { \
+ .conv = NULL, \
+ .conv_cls = NULL, \
+ .data = NULL, \
+ .size = 0, \
+ .num_params = 0 \
+ }
/**
@@ -182,34 +182,6 @@ GNUNET_PQ_query_param_string (const char *ptr);
struct GNUNET_PQ_QueryParam
GNUNET_PQ_query_param_bool (bool b);
-
-/**
- * Array types (in Postgres) that are supported in GNUnet.
- */
-enum GNUNET_PQ_DataTypes
-{
- GNUNET_PQ_DATATYPE_UNKNOWN, /* Unsupported type */
- GNUNET_PQ_DATATYPE_BOOL,
- GNUNET_PQ_DATATYPE_INT2,
- GNUNET_PQ_DATATYPE_INT4,
- GNUNET_PQ_DATATYPE_INT8,
- GNUNET_PQ_DATATYPE_BYTEA,
- GNUNET_PQ_DATATYPE_VARCHAR,
- GNUNET_PQ_DATATYPE_MAX, /* Must be last */
-};
-
-/**
- * Returns the oid for a given, basic datatype
- *
- * @param db The db-connection
- * @param typ the Datatype
- * @return The oid
- */
-Oid
-GNUNET_PQ_get_oid (
- const struct GNUNET_PQ_Context *db,
- enum GNUNET_PQ_DataTypes typ);
-
/**
* Returns the oid for a given datatype by name.
*
@@ -254,7 +226,7 @@ struct GNUNET_PQ_QueryParam
GNUNET_PQ_query_param_array_bool (
unsigned int num,
const bool *elements,
- const struct GNUNET_PQ_Context *db);
+ struct GNUNET_PQ_Context *db);
/**
* Generate query parameter for an array of uint16_t in host byte order.
@@ -269,7 +241,7 @@ struct GNUNET_PQ_QueryParam
GNUNET_PQ_query_param_array_uint16 (
unsigned int num,
const uint16_t *elements,
- const struct GNUNET_PQ_Context *db);
+ struct GNUNET_PQ_Context *db);
/**
* Generate query parameter for an array of uint32_t in host byte order.
@@ -284,7 +256,7 @@ struct GNUNET_PQ_QueryParam
GNUNET_PQ_query_param_array_uint32 (
unsigned int num,
const uint32_t *elements,
- const struct GNUNET_PQ_Context *db);
+ struct GNUNET_PQ_Context *db);
/**
* Generate query parameter for an array of uint64 in host byte order.
@@ -299,7 +271,7 @@ struct GNUNET_PQ_QueryParam
GNUNET_PQ_query_param_array_uint64 (
unsigned int num,
const uint64_t *elements,
- const struct GNUNET_PQ_Context *db);
+ struct GNUNET_PQ_Context *db);
/**
* Generate query parameter for an array of buffers @a elements, each of
@@ -316,7 +288,7 @@ GNUNET_PQ_query_param_array_bytes (
unsigned int num,
const void *elements,
const size_t *sizes,
- const struct GNUNET_PQ_Context *db);
+ struct GNUNET_PQ_Context *db);
/**
* Generate query parameter for an array of buffers @a elements,
@@ -333,7 +305,7 @@ GNUNET_PQ_query_param_array_bytes_same_size (
unsigned int num,
const void *elements,
size_t same_size,
- const struct GNUNET_PQ_Context *db);
+ struct GNUNET_PQ_Context *db);
/**
* Generate array of equal-sized query parameter with size determined
@@ -345,10 +317,10 @@ GNUNET_PQ_query_param_array_bytes_same_size (
* @return query parameter to use
*/
#define GNUNET_PQ_query_param_array_auto_from_type(num, elements, db) \
- GNUNET_PQ_query_param_array_bytes_same_size ((num), \
- (elements), \
- sizeof(*(elements)), \
- (db))
+ GNUNET_PQ_query_param_array_bytes_same_size ((num), \
+ (elements), \
+ sizeof(*(elements)), \
+ (db))
/**
* 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 (
unsigned int num,
const void *elements[],
size_t same_size,
- const struct GNUNET_PQ_Context *db);
+ struct GNUNET_PQ_Context *db);
/**
* Generate array of equal-sized query parameter with size determined by
@@ -378,10 +350,10 @@ GNUNET_PQ_query_param_array_ptrs_bytes_same_size (
* @return query parameter to use
*/
#define GNUNET_PQ_query_param_array_ptrs_auto_from_type(num, elements, db) \
- GNUNET_PQ_query_param_array_ptrs_bytes_same_size ((num), \
- (elements), \
-
sizeof(*(elements[0])), \
- (db))
+ GNUNET_PQ_query_param_array_ptrs_bytes_same_size ((num), \
+ (elements), \
+ sizeof(*(elements[0])), \
+ (db))
/**
@@ -396,7 +368,7 @@ struct GNUNET_PQ_QueryParam
GNUNET_PQ_query_param_array_string (
unsigned int num,
const char *elements,
- const struct GNUNET_PQ_Context *db);
+ struct GNUNET_PQ_Context *db);
/**
@@ -411,7 +383,7 @@ struct GNUNET_PQ_QueryParam
GNUNET_PQ_query_param_array_ptrs_string (
unsigned int num,
const char *elements[],
- const struct GNUNET_PQ_Context *db);
+ struct GNUNET_PQ_Context *db);
/**
* Generate fixed-size query parameter with size determined
@@ -421,7 +393,7 @@ GNUNET_PQ_query_param_array_ptrs_string (
* @return query parameter to use
*/
#define GNUNET_PQ_query_param_auto_from_type(x) \
- GNUNET_PQ_query_param_fixed_size ((x), sizeof(*(x)))
+ GNUNET_PQ_query_param_fixed_size ((x), sizeof(*(x)))
/**
* Generate query parameter for an array of absolute time stamps (continuous)
@@ -434,7 +406,7 @@ struct GNUNET_PQ_QueryParam
GNUNET_PQ_query_param_array_abs_time (
unsigned int num,
const struct GNUNET_TIME_Absolute *elements,
- const struct GNUNET_PQ_Context *db);
+ struct GNUNET_PQ_Context *db);
/**
* Generate query parameter for an array of absolute time stamps (pointers)
@@ -447,7 +419,7 @@ struct GNUNET_PQ_QueryParam
GNUNET_PQ_query_param_array_ptrs_abs_time (
unsigned int num,
const struct GNUNET_TIME_Absolute *elements[],
- const struct GNUNET_PQ_Context *db);
+ struct GNUNET_PQ_Context *db);
/**
* Generate query parameter for an array of relative time stamps (continuous)
@@ -460,7 +432,7 @@ struct GNUNET_PQ_QueryParam
GNUNET_PQ_query_param_array_rel_time (
unsigned int num,
const struct GNUNET_TIME_Relative *elements,
- const struct GNUNET_PQ_Context *db);
+ struct GNUNET_PQ_Context *db);
/**
* Generate query parameter for an array of relative time stamps (pointers)
@@ -473,7 +445,7 @@ struct GNUNET_PQ_QueryParam
GNUNET_PQ_query_param_array_ptrs_rel_time (
unsigned int num,
const struct GNUNET_TIME_Relative *elements[],
- const struct GNUNET_PQ_Context *db);
+ struct GNUNET_PQ_Context *db);
/**
* Generate query parameter for an array of time stamps (continuous)
@@ -486,7 +458,7 @@ struct GNUNET_PQ_QueryParam
GNUNET_PQ_query_param_array_timestamp (
unsigned int num,
const struct GNUNET_TIME_Timestamp *elements,
- const struct GNUNET_PQ_Context *db);
+ struct GNUNET_PQ_Context *db);
/**
* Generate query parameter for an array of time stamps (pointers)
@@ -499,7 +471,7 @@ struct GNUNET_PQ_QueryParam
GNUNET_PQ_query_param_array_ptrs_timestamp (
unsigned int num,
const struct GNUNET_TIME_Timestamp *elements[],
- const struct GNUNET_PQ_Context *db);
+ struct GNUNET_PQ_Context *db);
/**
* Generate query parameter for an RSA public key. The
@@ -712,17 +684,17 @@ struct GNUNET_PQ_ResultSpec
* @return array last entry for the result specification to use
*/
#define GNUNET_PQ_result_spec_end \
- { \
- .conv = NULL, \
- .cleaner = NULL, \
- .cls = NULL, \
- .dst = NULL, \
- .dst_size = 0, \
- .fname = NULL, \
- .result_size = NULL, \
- .is_nullable = false, \
- .is_null = NULL \
- }
+ { \
+ .conv = NULL, \
+ .cleaner = NULL, \
+ .cls = NULL, \
+ .dst = NULL, \
+ .dst_size = 0, \
+ .fname = NULL, \
+ .result_size = NULL, \
+ .is_nullable = false, \
+ .is_null = NULL \
+ }
/**
@@ -775,7 +747,7 @@ GNUNET_PQ_result_spec_fixed_size (const char *name,
* @return array entry for the result specification to use
*/
#define GNUNET_PQ_result_spec_auto_from_type(name, dst) \
- GNUNET_PQ_result_spec_fixed_size (name, (dst), sizeof(*(dst)))
+ GNUNET_PQ_result_spec_fixed_size (name, (dst), sizeof(*(dst)))
/**
@@ -932,7 +904,7 @@ GNUNET_PQ_result_spec_uint64 (const char *name,
*/
struct GNUNET_PQ_ResultSpec
GNUNET_PQ_result_spec_array_bool (
- const struct GNUNET_PQ_Context *db,
+ struct GNUNET_PQ_Context *db,
const char *name,
size_t *num,
bool **bools);
@@ -948,7 +920,7 @@ GNUNET_PQ_result_spec_array_bool (
*/
struct GNUNET_PQ_ResultSpec
GNUNET_PQ_result_spec_array_uint16 (
- const struct GNUNET_PQ_Context *db,
+ struct GNUNET_PQ_Context *db,
const char *name,
size_t *num,
uint16_t **dst);
@@ -964,7 +936,7 @@ GNUNET_PQ_result_spec_array_uint16 (
*/
struct GNUNET_PQ_ResultSpec
GNUNET_PQ_result_spec_array_uint32 (
- const struct GNUNET_PQ_Context *db,
+ struct GNUNET_PQ_Context *db,
const char *name,
size_t *num,
uint32_t **dst);
@@ -980,7 +952,7 @@ GNUNET_PQ_result_spec_array_uint32 (
*/
struct GNUNET_PQ_ResultSpec
GNUNET_PQ_result_spec_array_uint64 (
- const struct GNUNET_PQ_Context *db,
+ struct GNUNET_PQ_Context *db,
const char *name,
size_t *num,
uint64_t **dst);
@@ -997,7 +969,7 @@ GNUNET_PQ_result_spec_array_uint64 (
*/
struct GNUNET_PQ_ResultSpec
GNUNET_PQ_result_spec_array_abs_time (
- const struct GNUNET_PQ_Context *db,
+ struct GNUNET_PQ_Context *db,
const char *name,
size_t *num,
struct GNUNET_TIME_Absolute **dst);
@@ -1013,7 +985,7 @@ GNUNET_PQ_result_spec_array_abs_time (
*/
struct GNUNET_PQ_ResultSpec
GNUNET_PQ_result_spec_array_rel_time (
- const struct GNUNET_PQ_Context *db,
+ struct GNUNET_PQ_Context *db,
const char *name,
size_t *num,
struct GNUNET_TIME_Relative **dst);
@@ -1030,7 +1002,7 @@ GNUNET_PQ_result_spec_array_rel_time (
struct GNUNET_PQ_ResultSpec
GNUNET_PQ_result_spec_array_timestamp (
- const struct GNUNET_PQ_Context *db,
+ struct GNUNET_PQ_Context *db,
const char *name,
size_t *num,
struct GNUNET_TIME_Timestamp **dst);
@@ -1047,7 +1019,7 @@ GNUNET_PQ_result_spec_array_timestamp (
*/
struct GNUNET_PQ_ResultSpec
GNUNET_PQ_result_spec_array_variable_size (
- const struct GNUNET_PQ_Context *db,
+ struct GNUNET_PQ_Context *db,
const char *name,
size_t *num,
size_t **sizes,
@@ -1066,7 +1038,7 @@ GNUNET_PQ_result_spec_array_variable_size (
*/
struct GNUNET_PQ_ResultSpec
GNUNET_PQ_result_spec_array_fixed_size (
- const struct GNUNET_PQ_Context *db,
+ struct GNUNET_PQ_Context *db,
const char *name,
size_t size,
size_t *num,
@@ -1083,12 +1055,12 @@ GNUNET_PQ_result_spec_array_fixed_size (
* @return array entry for the result specification to use
*/
#define GNUNET_PQ_result_spec_auto_array_from_type(db, name, num, dst) \
- GNUNET_PQ_result_spec_array_fixed_size ( \
- (db), \
- (name), \
- sizeof(*(dst)), \
- (num), \
- (void *) &(dst))
+ GNUNET_PQ_result_spec_array_fixed_size ( \
+ (db), \
+ (name), \
+ sizeof(*(dst)), \
+ (num), \
+ (void *) &(dst))
/**
@@ -1102,7 +1074,7 @@ GNUNET_PQ_result_spec_array_fixed_size (
*/
struct GNUNET_PQ_ResultSpec
GNUNET_PQ_result_spec_array_string (
- const struct GNUNET_PQ_Context *db,
+ struct GNUNET_PQ_Context *db,
const char *name,
size_t *num,
char **dst);
@@ -1280,9 +1252,9 @@ struct GNUNET_PQ_PreparedStatement
* Terminator for prepared statement list.
*/
#define GNUNET_PQ_PREPARED_STATEMENT_END \
- { \
- NULL, NULL \
- }
+ { \
+ NULL, NULL \
+ }
/**
@@ -1352,9 +1324,9 @@ struct GNUNET_PQ_ExecuteStatement
* Terminator for executable statement list.
*/
#define GNUNET_PQ_EXECUTE_STATEMENT_END \
- { \
- NULL, GNUNET_SYSERR \
- }
+ { \
+ NULL, GNUNET_SYSERR \
+ }
/**
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
/**
* Mapping between array types and Oid's, filled at reconnect
*/
- Oid oids[GNUNET_PQ_DATATYPE_MAX];
+ struct
+ {
+ /* allocated number of elements array @table */
+ unsigned int cap;
+
+ /* number of entries in @table */
+ unsigned int num;
+
+ struct name2oid
+ {
+ const char *name;
+ Oid oid;
+ } *table;
+
+ } oids;
};
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)
}
-/**
- * Retrieves the Oid's for the supported array types and sets db->arraytype2oid
- * on succes.
- *
- * @param[in,out] db Context for the database connection
- * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
- */
-static enum GNUNET_GenericReturnValue
-get_array_type_oids (struct GNUNET_PQ_Context *db)
+enum GNUNET_GenericReturnValue
+GNUNET_PQ_get_oid_by_name (
+ struct GNUNET_PQ_Context *db,
+ const char *name,
+ Oid *oid)
{
- PGresult *res;
- ExecStatusType est;
-
- GNUNET_assert (NULL != db);
- /* Initialize to Oid(0) (= unknown) */
- memset (db->oids,
- 0,
- sizeof(db->oids));
-
- res = PQexec (db->conn,
- "SELECT"
- " typname, oid"
- " FROM pg_type "
- " WHERE typname in "
- " ('bool', 'int2', 'int4', 'int8', 'bytea', 'varchar');");
-
- est = PQresultStatus (res);
- if ( (PGRES_COMMAND_OK != est) &&
- (PGRES_TUPLES_OK != est))
+ /* Check if the entry is in the cache already */
+ for (unsigned int i = 0; i < db->oids.num; i++)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to run statement to retrieve Oids for array types!\n");
- return GNUNET_SYSERR;
+ /* Pointer comparison */
+ if (name == db->oids.table[i].name)
+ {
+ *oid = db->oids.table[i].oid;
+ return GNUNET_OK;
+ }
}
- if ( (2 != PQnfields (res)) ||
- (0 != PQfnumber (res, "typname")) ||
- (1 != PQfnumber (res, "oid"))
- )
+ /* No entry found in cache, ask database */
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected table retrieved for array types\n");
- return GNUNET_SYSERR;
+ enum GNUNET_DB_QueryStatus qs;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (name),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec spec[] = {
+ GNUNET_PQ_result_spec_uint32 ("oid",
+ oid),
+ GNUNET_PQ_result_spec_end
+ };
+
+ GNUNET_assert (NULL != db);
+
+ qs = GNUNET_PQ_eval_prepared_singleton_select (db,
+ "gnunet_pq_get_oid_by_name",
+ params,
+ spec);
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
+ return GNUNET_SYSERR;
}
+ /* Add the entry to the cache */
+ if (NULL == db->oids.table)
{
- int nrows = PQntuples (res);
- int nfound = 1; /* skip GNUNET_PQ_DATATYPE_UNKNOWN */
- char dummy;
-
- for (int r = 0; r < nrows; r++)
- {
- enum GNUNET_PQ_DataTypes atype = GNUNET_PQ_DATATYPE_UNKNOWN;
- char *typ_s = PQgetvalue (res,r,0);
- char *oid_s = PQgetvalue (res,r,1);
- GNUNET_assert (NULL != typ_s);
- GNUNET_assert (NULL != oid_s);
-
- if (! strcmp (typ_s,"bool"))
- atype = GNUNET_PQ_DATATYPE_BOOL;
- else if (! strcmp (typ_s,"int2"))
- atype = GNUNET_PQ_DATATYPE_INT2;
- else if (! strcmp (typ_s,"int4"))
- atype = GNUNET_PQ_DATATYPE_INT4;
- else if (! strcmp (typ_s,"int8"))
- atype = GNUNET_PQ_DATATYPE_INT8;
- else if (! strcmp (typ_s,"bytea"))
- atype = GNUNET_PQ_DATATYPE_BYTEA;
- else if (! strcmp (typ_s,"varchar"))
- atype = GNUNET_PQ_DATATYPE_VARCHAR;
- else
- continue;
-
- GNUNET_assert (GNUNET_PQ_DATATYPE_MAX > atype);
-
- if ( (GNUNET_PQ_DATATYPE_UNKNOWN != atype) &&
- (1 == sscanf (oid_s,
- "%u%c",
- &db->oids[atype],
- &dummy)))
- {
- nfound++;
- }
- }
-
- if (GNUNET_PQ_DATATYPE_MAX != nfound)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Couldn't find all array types, only found %d of %d!\n",
- nfound - 1,
- GNUNET_PQ_DATATYPE_MAX - 1);
- return GNUNET_SYSERR;
- }
+ db->oids.table = GNUNET_new_array (8,
+ typeof(*db->oids.table));
+ db->oids.cap = 8;
+ db->oids.num = 0;
}
- return GNUNET_OK;
-}
+ if (db->oids.cap <= db->oids.num)
+ GNUNET_array_grow (db->oids.table,
+ db->oids.cap,
+ db->oids.cap + 8);
-Oid
-GNUNET_PQ_get_oid (
- const struct GNUNET_PQ_Context *db,
- enum GNUNET_PQ_DataTypes typ)
-{
- GNUNET_assert (GNUNET_PQ_DATATYPE_MAX > typ);
- return db->oids[typ];
+ db->oids.table[db->oids.num].name = name;
+ db->oids.table[db->oids.num].oid = *oid;
+ db->oids.num++;
+
+ return GNUNET_OK;
}
+/**
+ * Load the initial set of OIDs for the supported
+ * array-datatypes
+ *
+ * @param db The database context
+ * @return GNUNET_OK on success, GNUNET_SYSERR if any of the types couldn't be
found
+ */
+static
enum GNUNET_GenericReturnValue
-GNUNET_PQ_get_oid_by_name (
- struct GNUNET_PQ_Context *db,
- const char *name,
- Oid *oid)
+load_initial_oids (struct GNUNET_PQ_Context *db)
{
- char *typname;
- enum GNUNET_DB_QueryStatus qs;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (name),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_string ("typname",
- &typname),
- GNUNET_PQ_result_spec_uint32 ("oid",
- oid),
- GNUNET_PQ_result_spec_end
+ static const char *typnames[] = {
+ "bool",
+ "int2",
+ "int4",
+ "int8",
+ "bytea",
+ "varchar"
};
+ Oid oid;
- GNUNET_assert (NULL != db);
-
- /* Initialize to Oid(0) (= unknown) */
- *oid = 0;
-
- qs = GNUNET_PQ_eval_prepared_singleton_select (db,
- "gnunet_pq_get_oid_by_name",
- params,
- rs);
- if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
- return GNUNET_SYSERR;
-
- if (0 != strcasecmp (typname, name))
- return GNUNET_SYSERR;
-
+ for (size_t i = 0; i< sizeof(typnames) / sizeof(*typnames); i++)
+ {
+ if (GNUNET_OK !=
+ GNUNET_PQ_get_oid_by_name (db,
+ typnames[i],
+ &oid))
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "pq",
+ "Couldn't retrieve OID for type %s\n",
+ typnames[i]);
+ return GNUNET_SYSERR;
+ }
+ }
return GNUNET_OK;
}
@@ -559,16 +513,6 @@ GNUNET_PQ_reconnect (struct GNUNET_PQ_Context *db)
}
}
- /* Retrieve the OIDs for the supported Array types */
- if (GNUNET_SYSERR == get_array_type_oids (db))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to retrieve OID information for array types!\n");
- PQfinish (db->conn);
- db->conn = NULL;
- return;
- }
-
/* Prepare statement for OID lookup by name */
{
PGresult *res;
@@ -596,6 +540,18 @@ GNUNET_PQ_reconnect (struct GNUNET_PQ_Context *db)
PQclear (res);
}
+ /* Reset the OID-cache and retrieve the OIDs for the supported Array types */
+ db->oids.num = 0;
+ if (GNUNET_SYSERR == load_initial_oids (db))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to retrieve OID information for array types!\n");
+ PQfinish (db->conn);
+ db->conn = NULL;
+ return;
+ }
+
+
if (NULL != db->auto_suffix)
{
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
GNUNET_PQ_query_param_array_bool (
unsigned int num,
const bool *elements,
- const struct GNUNET_PQ_Context *db)
+ struct GNUNET_PQ_Context *db)
{
+ Oid oid;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,"bool",&oid));
return query_param_array_generic (num,
true,
elements,
NULL,
sizeof(bool),
array_of_bool,
- db->oids[GNUNET_PQ_DATATYPE_BOOL]);
+ oid);
}
@@ -978,15 +981,18 @@ struct GNUNET_PQ_QueryParam
GNUNET_PQ_query_param_array_uint16 (
unsigned int num,
const uint16_t *elements,
- const struct GNUNET_PQ_Context *db)
+ struct GNUNET_PQ_Context *db)
{
+ Oid oid;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,"int2",&oid));
return query_param_array_generic (num,
true,
elements,
NULL,
sizeof(uint16_t),
array_of_uint16,
- db->oids[GNUNET_PQ_DATATYPE_INT2]);
+ oid);
}
@@ -994,15 +1000,18 @@ struct GNUNET_PQ_QueryParam
GNUNET_PQ_query_param_array_uint32 (
unsigned int num,
const uint32_t *elements,
- const struct GNUNET_PQ_Context *db)
+ struct GNUNET_PQ_Context *db)
{
+ Oid oid;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,"int4",&oid));
return query_param_array_generic (num,
true,
elements,
NULL,
sizeof(uint32_t),
array_of_uint32,
- db->oids[GNUNET_PQ_DATATYPE_INT4]);
+ oid);
}
@@ -1010,15 +1019,18 @@ struct GNUNET_PQ_QueryParam
GNUNET_PQ_query_param_array_uint64 (
unsigned int num,
const uint64_t *elements,
- const struct GNUNET_PQ_Context *db)
+ struct GNUNET_PQ_Context *db)
{
+ Oid oid;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,"int8",&oid));
return query_param_array_generic (num,
true,
elements,
NULL,
sizeof(uint64_t),
array_of_uint64,
- db->oids[GNUNET_PQ_DATATYPE_INT8]);
+ oid);
}
@@ -1027,15 +1039,18 @@ GNUNET_PQ_query_param_array_bytes (
unsigned int num,
const void *elements,
const size_t *sizes,
- const struct GNUNET_PQ_Context *db)
+ struct GNUNET_PQ_Context *db)
{
+ Oid oid;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,"bytea",&oid));
return query_param_array_generic (num,
true,
elements,
sizes,
0,
array_of_byte,
- db->oids[GNUNET_PQ_DATATYPE_BYTEA]);
+ oid);
}
@@ -1044,15 +1059,18 @@ GNUNET_PQ_query_param_array_ptrs_bytes (
unsigned int num,
const void *elements[],
const size_t *sizes,
- const struct GNUNET_PQ_Context *db)
+ struct GNUNET_PQ_Context *db)
{
+ Oid oid;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,"bytea",&oid));
return query_param_array_generic (num,
false,
elements,
sizes,
0,
array_of_byte,
- db->oids[GNUNET_PQ_DATATYPE_BYTEA]);
+ oid);
}
@@ -1061,15 +1079,18 @@ GNUNET_PQ_query_param_array_bytes_same_size (
unsigned int num,
const void *elements,
size_t same_size,
- const struct GNUNET_PQ_Context *db)
+ struct GNUNET_PQ_Context *db)
{
+ Oid oid;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,"bytea",&oid));
return query_param_array_generic (num,
true,
elements,
NULL,
same_size,
array_of_byte,
- db->oids[GNUNET_PQ_DATATYPE_BYTEA]);
+ oid);
}
@@ -1078,15 +1099,18 @@ GNUNET_PQ_query_param_array_ptrs_bytes_same_size (
unsigned int num,
const void *elements[],
size_t same_size,
- const struct GNUNET_PQ_Context *db)
+ struct GNUNET_PQ_Context *db)
{
+ Oid oid;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,"bytea",&oid));
return query_param_array_generic (num,
false,
elements,
NULL,
same_size,
array_of_byte,
- db->oids[GNUNET_PQ_DATATYPE_BYTEA]);
+ oid);
}
@@ -1094,15 +1118,18 @@ struct GNUNET_PQ_QueryParam
GNUNET_PQ_query_param_array_string (
unsigned int num,
const char *elements,
- const struct GNUNET_PQ_Context *db)
+ struct GNUNET_PQ_Context *db)
{
+ Oid oid;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,"varchar",&oid));
return query_param_array_generic (num,
true,
elements,
NULL,
0,
array_of_string,
- db->oids[GNUNET_PQ_DATATYPE_VARCHAR]);
+ oid);
}
@@ -1110,15 +1137,18 @@ struct GNUNET_PQ_QueryParam
GNUNET_PQ_query_param_array_ptrs_string (
unsigned int num,
const char *elements[],
- const struct GNUNET_PQ_Context *db)
+ struct GNUNET_PQ_Context *db)
{
+ Oid oid;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,"varchar",&oid));
return query_param_array_generic (num,
false,
elements,
NULL,
0,
array_of_string,
- db->oids[GNUNET_PQ_DATATYPE_VARCHAR]);
+ oid);
}
@@ -1126,15 +1156,18 @@ struct GNUNET_PQ_QueryParam
GNUNET_PQ_query_param_array_abs_time (
unsigned int num,
const struct GNUNET_TIME_Absolute *elements,
- const struct GNUNET_PQ_Context *db)
+ struct GNUNET_PQ_Context *db)
{
+ Oid oid;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,"int8",&oid));
return query_param_array_generic (num,
true,
elements,
NULL,
sizeof(struct GNUNET_TIME_Absolute),
array_of_abs_time,
- db->oids[GNUNET_PQ_DATATYPE_INT8]);
+ oid);
}
@@ -1142,15 +1175,18 @@ struct GNUNET_PQ_QueryParam
GNUNET_PQ_query_param_array_ptrs_abs_time (
unsigned int num,
const struct GNUNET_TIME_Absolute *elements[],
- const struct GNUNET_PQ_Context *db)
+ struct GNUNET_PQ_Context *db)
{
+ Oid oid;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,"int8",&oid));
return query_param_array_generic (num,
false,
elements,
NULL,
sizeof(struct GNUNET_TIME_Absolute),
array_of_abs_time,
- db->oids[GNUNET_PQ_DATATYPE_INT8]);
+ oid);
}
@@ -1158,15 +1194,18 @@ struct GNUNET_PQ_QueryParam
GNUNET_PQ_query_param_array_rel_time (
unsigned int num,
const struct GNUNET_TIME_Relative *elements,
- const struct GNUNET_PQ_Context *db)
+ struct GNUNET_PQ_Context *db)
{
+ Oid oid;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,"int8",&oid));
return query_param_array_generic (num,
true,
elements,
NULL,
sizeof(struct GNUNET_TIME_Relative),
array_of_abs_time,
- db->oids[GNUNET_PQ_DATATYPE_INT8]);
+ oid);
}
@@ -1174,15 +1213,18 @@ struct GNUNET_PQ_QueryParam
GNUNET_PQ_query_param_array_ptrs_rel_time (
unsigned int num,
const struct GNUNET_TIME_Relative *elements[],
- const struct GNUNET_PQ_Context *db)
+ struct GNUNET_PQ_Context *db)
{
+ Oid oid;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,"int8",&oid));
return query_param_array_generic (num,
false,
elements,
NULL,
sizeof(struct GNUNET_TIME_Relative),
array_of_abs_time,
- db->oids[GNUNET_PQ_DATATYPE_INT8]);
+ oid);
}
@@ -1190,15 +1232,18 @@ struct GNUNET_PQ_QueryParam
GNUNET_PQ_query_param_array_timestamp (
unsigned int num,
const struct GNUNET_TIME_Timestamp *elements,
- const struct GNUNET_PQ_Context *db)
+ struct GNUNET_PQ_Context *db)
{
+ Oid oid;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,"int8",&oid));
return query_param_array_generic (num,
true,
elements,
NULL,
sizeof(struct GNUNET_TIME_Timestamp),
array_of_timestamp,
- db->oids[GNUNET_PQ_DATATYPE_INT8]);
+ oid);
}
@@ -1206,15 +1251,18 @@ struct GNUNET_PQ_QueryParam
GNUNET_PQ_query_param_array_ptrs_timestamp (
unsigned int num,
const struct GNUNET_TIME_Timestamp *elements[],
- const struct GNUNET_PQ_Context *db)
+ struct GNUNET_PQ_Context *db)
{
+ Oid oid;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,"int8",&oid));
return query_param_array_generic (num,
false,
elements,
NULL,
sizeof(struct GNUNET_TIME_Timestamp),
array_of_timestamp,
- db->oids[GNUNET_PQ_DATATYPE_INT8]);
+ oid);
}
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,
struct GNUNET_PQ_ResultSpec
GNUNET_PQ_result_spec_array_bool (
- const struct GNUNET_PQ_Context *db,
+ struct GNUNET_PQ_Context *db,
const char *name,
size_t *num,
bool **dst)
@@ -1439,7 +1439,10 @@ GNUNET_PQ_result_spec_array_bool (
info->num = num;
info->typ = array_of_bool;
- info->oid = db->oids[GNUNET_PQ_DATATYPE_BOOL];
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,
+ "bool",
+ &info->oid));
struct GNUNET_PQ_ResultSpec res = {
.conv = extract_array_generic,
@@ -1454,7 +1457,7 @@ GNUNET_PQ_result_spec_array_bool (
struct GNUNET_PQ_ResultSpec
GNUNET_PQ_result_spec_array_uint16 (
- const struct GNUNET_PQ_Context *db,
+ struct GNUNET_PQ_Context *db,
const char *name,
size_t *num,
uint16_t **dst)
@@ -1464,7 +1467,10 @@ GNUNET_PQ_result_spec_array_uint16 (
info->num = num;
info->typ = array_of_uint16;
- info->oid = db->oids[GNUNET_PQ_DATATYPE_INT2];
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,
+ "int2",
+ &info->oid));
struct GNUNET_PQ_ResultSpec res = {
.conv = extract_array_generic,
@@ -1479,7 +1485,7 @@ GNUNET_PQ_result_spec_array_uint16 (
struct GNUNET_PQ_ResultSpec
GNUNET_PQ_result_spec_array_uint32 (
- const struct GNUNET_PQ_Context *db,
+ struct GNUNET_PQ_Context *db,
const char *name,
size_t *num,
uint32_t **dst)
@@ -1489,7 +1495,10 @@ GNUNET_PQ_result_spec_array_uint32 (
info->num = num;
info->typ = array_of_uint32;
- info->oid = db->oids[GNUNET_PQ_DATATYPE_INT4];
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,
+ "int4",
+ &info->oid));
struct GNUNET_PQ_ResultSpec res = {
.conv = extract_array_generic,
@@ -1504,7 +1513,7 @@ GNUNET_PQ_result_spec_array_uint32 (
struct GNUNET_PQ_ResultSpec
GNUNET_PQ_result_spec_array_uint64 (
- const struct GNUNET_PQ_Context *db,
+ struct GNUNET_PQ_Context *db,
const char *name,
size_t *num,
uint64_t **dst)
@@ -1514,7 +1523,10 @@ GNUNET_PQ_result_spec_array_uint64 (
info->num = num;
info->typ = array_of_uint64;
- info->oid = db->oids[GNUNET_PQ_DATATYPE_INT8];
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,
+ "int8",
+ &info->oid));
struct GNUNET_PQ_ResultSpec res = {
.conv = extract_array_generic,
@@ -1529,7 +1541,7 @@ GNUNET_PQ_result_spec_array_uint64 (
struct GNUNET_PQ_ResultSpec
GNUNET_PQ_result_spec_array_abs_time (
- const struct GNUNET_PQ_Context *db,
+ struct GNUNET_PQ_Context *db,
const char *name,
size_t *num,
struct GNUNET_TIME_Absolute **dst)
@@ -1539,7 +1551,10 @@ GNUNET_PQ_result_spec_array_abs_time (
info->num = num;
info->typ = array_of_abs_time;
- info->oid = db->oids[GNUNET_PQ_DATATYPE_INT8];
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,
+ "int8",
+ &info->oid));
struct GNUNET_PQ_ResultSpec res = {
.conv = extract_array_generic,
@@ -1554,7 +1569,7 @@ GNUNET_PQ_result_spec_array_abs_time (
struct GNUNET_PQ_ResultSpec
GNUNET_PQ_result_spec_array_rel_time (
- const struct GNUNET_PQ_Context *db,
+ struct GNUNET_PQ_Context *db,
const char *name,
size_t *num,
struct GNUNET_TIME_Relative **dst)
@@ -1564,7 +1579,10 @@ GNUNET_PQ_result_spec_array_rel_time (
info->num = num;
info->typ = array_of_rel_time;
- info->oid = db->oids[GNUNET_PQ_DATATYPE_INT8];
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,
+ "int8",
+ &info->oid));
struct GNUNET_PQ_ResultSpec res = {
.conv = extract_array_generic,
@@ -1579,7 +1597,7 @@ GNUNET_PQ_result_spec_array_rel_time (
struct GNUNET_PQ_ResultSpec
GNUNET_PQ_result_spec_array_timestamp (
- const struct GNUNET_PQ_Context *db,
+ struct GNUNET_PQ_Context *db,
const char *name,
size_t *num,
struct GNUNET_TIME_Timestamp **dst)
@@ -1589,7 +1607,10 @@ GNUNET_PQ_result_spec_array_timestamp (
info->num = num;
info->typ = array_of_timestamp;
- info->oid = db->oids[GNUNET_PQ_DATATYPE_INT8];
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,
+ "int8",
+ &info->oid));
struct GNUNET_PQ_ResultSpec res = {
.conv = extract_array_generic,
@@ -1604,7 +1625,7 @@ GNUNET_PQ_result_spec_array_timestamp (
struct GNUNET_PQ_ResultSpec
GNUNET_PQ_result_spec_array_variable_size (
- const struct GNUNET_PQ_Context *db,
+ struct GNUNET_PQ_Context *db,
const char *name,
size_t *num,
size_t **sizes,
@@ -1616,7 +1637,10 @@ GNUNET_PQ_result_spec_array_variable_size (
info->num = num;
info->sizes = sizes;
info->typ = array_of_byte;
- info->oid = db->oids[GNUNET_PQ_DATATYPE_BYTEA];
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,
+ "bytea",
+ &info->oid));
struct GNUNET_PQ_ResultSpec res = {
.conv = extract_array_generic,
@@ -1631,7 +1655,7 @@ GNUNET_PQ_result_spec_array_variable_size (
struct GNUNET_PQ_ResultSpec
GNUNET_PQ_result_spec_array_fixed_size (
- const struct GNUNET_PQ_Context *db,
+ struct GNUNET_PQ_Context *db,
const char *name,
size_t size,
size_t *num,
@@ -1643,7 +1667,10 @@ GNUNET_PQ_result_spec_array_fixed_size (
info->num = num;
info->same_size = size;
info->typ = array_of_byte;
- info->oid = db->oids[GNUNET_PQ_DATATYPE_BYTEA];
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,
+ "bytea",
+ &info->oid));
struct GNUNET_PQ_ResultSpec res = {
.conv = extract_array_generic,
@@ -1658,7 +1685,7 @@ GNUNET_PQ_result_spec_array_fixed_size (
struct GNUNET_PQ_ResultSpec
GNUNET_PQ_result_spec_array_string (
- const struct GNUNET_PQ_Context *db,
+ struct GNUNET_PQ_Context *db,
const char *name,
size_t *num,
char **dst)
@@ -1668,7 +1695,10 @@ GNUNET_PQ_result_spec_array_string (
info->num = num;
info->typ = array_of_string;
- info->oid = db->oids[GNUNET_PQ_DATATYPE_VARCHAR];
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,
+ "varchar",
+ &info->oid));
struct GNUNET_PQ_ResultSpec res = {
.conv = extract_array_generic,
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnunet] branch master updated: pq: simplified and improved API for array-support,
gnunet <=