diff options
author | Özgür Kesim <oec-taler@kesim.org> | 2023-05-11 15:14:32 +0200 |
---|---|---|
committer | Özgür Kesim <oec-taler@kesim.org> | 2023-05-11 15:14:32 +0200 |
commit | 2531393309e1a550596a2d2ff7b8949ef33531ec (patch) | |
tree | 052d46ace034353455f6e6ace80cb0047bc593b0 /src/pq/pq_connect.c | |
parent | 0af8797baa8ed9bec3373910bc8a2ce971aed303 (diff) | |
download | gnunet-2531393309e1a550596a2d2ff7b8949ef33531ec.tar.gz gnunet-2531393309e1a550596a2d2ff7b8949ef33531ec.zip |
pq: added array-type support for queries (only)
NEWS: relevant array-types in queries (not results) in postgresql added
- support for base types BOOL, INT2, INT4, INT8, BYTEA and VARCHAR
Diffstat (limited to 'src/pq/pq_connect.c')
-rw-r--r-- | src/pq/pq_connect.c | 59 |
1 files changed, 29 insertions, 30 deletions
diff --git a/src/pq/pq_connect.c b/src/pq/pq_connect.c index 2bbc7e885..9493eb2d7 100644 --- a/src/pq/pq_connect.c +++ b/src/pq/pq_connect.c | |||
@@ -337,14 +337,17 @@ get_array_type_oids (struct GNUNET_PQ_Context *db) | |||
337 | 337 | ||
338 | GNUNET_assert (NULL != db); | 338 | GNUNET_assert (NULL != db); |
339 | /* Initialize to Oid(0) (= unknown) */ | 339 | /* Initialize to Oid(0) (= unknown) */ |
340 | memset (db->arraytype2oid, | 340 | memset (db->oids, |
341 | 0, | 341 | 0, |
342 | sizeof(db->arraytype2oid)); | 342 | sizeof(db->oids)); |
343 | |||
343 | res = PQexec (db->conn, | 344 | res = PQexec (db->conn, |
344 | "SELECT" | 345 | "SELECT" |
345 | " typname, oid" | 346 | " typname, oid" |
346 | " FROM pg_type " | 347 | " FROM pg_type " |
347 | " WHERE typname LIKE '\\_%';"); | 348 | " WHERE typname in " |
349 | " ('bool', 'int2', 'int4', 'int8', 'bytea', 'varchar');"); | ||
350 | |||
348 | est = PQresultStatus (res); | 351 | est = PQresultStatus (res); |
349 | if ( (PGRES_COMMAND_OK != est) && | 352 | if ( (PGRES_COMMAND_OK != est) && |
350 | (PGRES_TUPLES_OK != est)) | 353 | (PGRES_TUPLES_OK != est)) |
@@ -366,54 +369,50 @@ get_array_type_oids (struct GNUNET_PQ_Context *db) | |||
366 | 369 | ||
367 | { | 370 | { |
368 | int nrows = PQntuples (res); | 371 | int nrows = PQntuples (res); |
369 | int nfound = 1; /* skip GNUNET_PQ_ARRAY_UNKNOWN */ | 372 | int nfound = 1; /* skip GNUNET_PQ_DATATYPE_UNKNOWN */ |
373 | char dummy; | ||
370 | 374 | ||
371 | for (int r = 0; r < nrows; r++) | 375 | for (int r = 0; r < nrows; r++) |
372 | { | 376 | { |
373 | enum GNUNET_PQ_ArrayTypes atype = GNUNET_PQ_ARRAY_UNKNOWN; | 377 | enum GNUNET_PQ_DataTypes atype = GNUNET_PQ_DATATYPE_UNKNOWN; |
374 | const char *typ_s = PQgetvalue (res,r,0); | 378 | char *typ_s = PQgetvalue (res,r,0); |
375 | const char *oid_s = PQgetvalue (res,r,1); | 379 | char *oid_s = PQgetvalue (res,r,1); |
376 | char dummy; | ||
377 | |||
378 | GNUNET_assert (NULL != typ_s); | 380 | GNUNET_assert (NULL != typ_s); |
379 | GNUNET_assert (NULL != oid_s); | 381 | GNUNET_assert (NULL != oid_s); |
380 | 382 | ||
381 | if (! strcmp (typ_s, "_bool")) | 383 | if (! strcmp (typ_s,"bool")) |
382 | atype = GNUNET_PQ_ARRAY_BOOL; | 384 | atype = GNUNET_PQ_DATATYPE_BOOL; |
383 | else if (! strcmp (typ_s, "_int2")) | 385 | else if (! strcmp (typ_s,"int2")) |
384 | atype = GNUNET_PQ_ARRAY_INT2; | 386 | atype = GNUNET_PQ_DATATYPE_INT2; |
385 | else if (! strcmp (typ_s, "_int4")) | 387 | else if (! strcmp (typ_s,"int4")) |
386 | atype = GNUNET_PQ_ARRAY_INT4; | 388 | atype = GNUNET_PQ_DATATYPE_INT4; |
387 | else if (! strcmp (typ_s, "_int8")) | 389 | else if (! strcmp (typ_s,"int8")) |
388 | atype = GNUNET_PQ_ARRAY_INT8; | 390 | atype = GNUNET_PQ_DATATYPE_INT8; |
389 | else if (! strcmp (typ_s, "_bytea")) | 391 | else if (! strcmp (typ_s,"bytea")) |
390 | atype = GNUNET_PQ_ARRAY_BYTEA; | 392 | atype = GNUNET_PQ_DATATYPE_BYTEA; |
391 | else if (! strcmp (typ_s, "_varchar")) | 393 | else if (! strcmp (typ_s,"varchar")) |
392 | atype = GNUNET_PQ_ARRAY_VARCHAR; | 394 | atype = GNUNET_PQ_DATATYPE_VARCHAR; |
393 | else | 395 | else |
394 | continue; | 396 | continue; |
395 | 397 | ||
396 | GNUNET_assert (GNUNET_PQ_ARRAY_MAX > atype); | 398 | GNUNET_assert (GNUNET_PQ_DATATYPE_MAX > atype); |
397 | 399 | ||
398 | if ( (GNUNET_PQ_ARRAY_UNKNOWN != atype) && | 400 | if ( (GNUNET_PQ_DATATYPE_UNKNOWN != atype) && |
399 | (1 == sscanf (oid_s, | 401 | (1 == sscanf (oid_s, |
400 | "%u%c", | 402 | "%u%c", |
401 | &db->arraytype2oid[atype], | 403 | &db->oids[atype], |
402 | &dummy))) | 404 | &dummy))) |
403 | { | 405 | { |
404 | nfound++; | 406 | nfound++; |
405 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
406 | "OID[%s]: %d\n", | ||
407 | typ_s, | ||
408 | db->arraytype2oid[atype]); | ||
409 | } | 407 | } |
410 | } | 408 | } |
411 | if (GNUNET_PQ_ARRAY_MAX != nfound) | 409 | |
410 | if (GNUNET_PQ_DATATYPE_MAX != nfound) | ||
412 | { | 411 | { |
413 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 412 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
414 | "Couldn't find all array types, only found %d of %d!\n", | 413 | "Couldn't find all array types, only found %d of %d!\n", |
415 | nfound - 1, | 414 | nfound - 1, |
416 | GNUNET_PQ_ARRAY_MAX - 1); | 415 | GNUNET_PQ_DATATYPE_MAX - 1); |
417 | return GNUNET_SYSERR; | 416 | return GNUNET_SYSERR; |
418 | } | 417 | } |
419 | } | 418 | } |