aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2023-05-08 14:12:05 +0200
committerChristian Grothoff <christian@grothoff.org>2023-05-08 14:12:05 +0200
commit7d10d1e317c7ac8b656b2cfdb89f86ff7ba44464 (patch)
treef7417ba96786964eb85426dd792863190110bb25
parentcfdc99228ccdadc9392aaaf38661af931d6d5b6a (diff)
downloadgnunet-7d10d1e317c7ac8b656b2cfdb89f86ff7ba44464.tar.gz
gnunet-7d10d1e317c7ac8b656b2cfdb89f86ff7ba44464.zip
-minor cleanup
-rw-r--r--src/pq/pq_connect.c39
1 files changed, 20 insertions, 19 deletions
diff --git a/src/pq/pq_connect.c b/src/pq/pq_connect.c
index f6fd3e34b..c8ed24de4 100644
--- a/src/pq/pq_connect.c
+++ b/src/pq/pq_connect.c
@@ -326,27 +326,25 @@ GNUNET_PQ_reconnect_if_down (struct GNUNET_PQ_Context *db)
326 * Retrieves the Oid's for the supported array types and sets db->arraytype2oid 326 * Retrieves the Oid's for the supported array types and sets db->arraytype2oid
327 * on succes. 327 * on succes.
328 * 328 *
329 * @param db Context for the database connection 329 * @param[in,out] db Context for the database connection
330 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise 330 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
331 */ 331 */
332static enum GNUNET_GenericReturnValue 332static enum GNUNET_GenericReturnValue
333get_array_type_oids (struct GNUNET_PQ_Context *db) 333get_array_type_oids (struct GNUNET_PQ_Context *db)
334{ 334{
335 PGresult *res; 335 PGresult *res;
336 ExecStatusType est; 336 ExecStatusType est;
337 GNUNET_assert (NULL != db);
338 337
338 GNUNET_assert (NULL != db);
339 /* Initialize to Oid(0) (= unknown) */ 339 /* Initialize to Oid(0) (= unknown) */
340 memset (db->arraytype2oid, 340 memset (db->arraytype2oid,
341 0, 341 0,
342 sizeof(db->arraytype2oid)); 342 sizeof(db->arraytype2oid));
343
344 res = PQexec (db->conn, 343 res = PQexec (db->conn,
345 "SELECT" 344 "SELECT"
346 " typname, oid" 345 " typname, oid"
347 " FROM pg_type " 346 " FROM pg_type "
348 " WHERE typname like '\\_%';"); 347 " WHERE typname LIKE '\\_%';");
349
350 est = PQresultStatus (res); 348 est = PQresultStatus (res);
351 if ( (PGRES_COMMAND_OK != est) && 349 if ( (PGRES_COMMAND_OK != est) &&
352 (PGRES_TUPLES_OK != est)) 350 (PGRES_TUPLES_OK != est))
@@ -373,38 +371,42 @@ get_array_type_oids (struct GNUNET_PQ_Context *db)
373 for (int r = 0; r < nrows; r++) 371 for (int r = 0; r < nrows; r++)
374 { 372 {
375 enum GNUNET_PQ_ArrayTypes atype = GNUNET_PQ_ARRAY_UNKNOWN; 373 enum GNUNET_PQ_ArrayTypes atype = GNUNET_PQ_ARRAY_UNKNOWN;
376 char *typ_s = PQgetvalue (res,r,0); 374 const char *typ_s = PQgetvalue (res,r,0);
377 char *oid_s = PQgetvalue (res,r,1); 375 const char *oid_s = PQgetvalue (res,r,1);
376 char dummy;
377
378 GNUNET_assert (NULL != typ_s); 378 GNUNET_assert (NULL != typ_s);
379 GNUNET_assert (NULL != oid_s); 379 GNUNET_assert (NULL != oid_s);
380 380
381 if (! strcmp (typ_s,"_bool")) 381 if (! strcmp (typ_s, "_bool"))
382 atype = GNUNET_PQ_ARRAY_BOOL; 382 atype = GNUNET_PQ_ARRAY_BOOL;
383 else if (! strcmp (typ_s,"_int2")) 383 else if (! strcmp (typ_s, "_int2"))
384 atype = GNUNET_PQ_ARRAY_INT2; 384 atype = GNUNET_PQ_ARRAY_INT2;
385 else if (! strcmp (typ_s,"_int4")) 385 else if (! strcmp (typ_s, "_int4"))
386 atype = GNUNET_PQ_ARRAY_INT4; 386 atype = GNUNET_PQ_ARRAY_INT4;
387 else if (! strcmp (typ_s,"_int8")) 387 else if (! strcmp (typ_s, "_int8"))
388 atype = GNUNET_PQ_ARRAY_INT8; 388 atype = GNUNET_PQ_ARRAY_INT8;
389 else if (! strcmp (typ_s,"_bytea")) 389 else if (! strcmp (typ_s, "_bytea"))
390 atype = GNUNET_PQ_ARRAY_BYTEA; 390 atype = GNUNET_PQ_ARRAY_BYTEA;
391 else if (! strcmp (typ_s,"_varchar")) 391 else if (! strcmp (typ_s, "_varchar"))
392 atype = GNUNET_PQ_ARRAY_VARCHAR; 392 atype = GNUNET_PQ_ARRAY_VARCHAR;
393 else 393 else
394 continue; 394 continue;
395 395
396 GNUNET_assert (GNUNET_PQ_ARRAY_MAX > atype); 396 GNUNET_assert (GNUNET_PQ_ARRAY_MAX > atype);
397 397
398 if ((GNUNET_PQ_ARRAY_UNKNOWN != atype) && 398 if ( (GNUNET_PQ_ARRAY_UNKNOWN != atype) &&
399 (1 == sscanf (oid_s, "%u", &db->arraytype2oid[atype]))) 399 (1 == sscanf (oid_s,
400 "%u%c",
401 &db->arraytype2oid[atype])))
400 { 402 {
401 nfound++; 403 nfound++;
402 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 404 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
403 "OID[%s]: %d\n", 405 "OID[%s]: %d\n",
404 typ_s, db->arraytype2oid[atype]); 406 typ_s,
407 db->arraytype2oid[atype]);
405 } 408 }
406 } 409 }
407
408 if (GNUNET_PQ_ARRAY_MAX != nfound) 410 if (GNUNET_PQ_ARRAY_MAX != nfound)
409 { 411 {
410 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 412 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -414,7 +416,6 @@ get_array_type_oids (struct GNUNET_PQ_Context *db)
414 return GNUNET_SYSERR; 416 return GNUNET_SYSERR;
415 } 417 }
416 } 418 }
417
418 return GNUNET_OK; 419 return GNUNET_OK;
419} 420}
420 421