aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-10-18 21:24:09 +0200
committerChristian Grothoff <christian@grothoff.org>2022-10-18 21:24:16 +0200
commitf0b91ff6ca4e327dc0e29e8d888d88d873e80e65 (patch)
treec1bdb706a4e3e4287b48811d44b577ec0ea63de6
parent282b9d3694d2b3052dc0c5a971dec85e7158faca (diff)
downloadgnunet-f0b91ff6ca4e327dc0e29e8d888d88d873e80e65.tar.gz
gnunet-f0b91ff6ca4e327dc0e29e8d888d88d873e80e65.zip
fix #7374
-rw-r--r--src/pq/pq_connect.c90
1 files changed, 52 insertions, 38 deletions
diff --git a/src/pq/pq_connect.c b/src/pq/pq_connect.c
index 2e36f58f1..a911bf8e1 100644
--- a/src/pq/pq_connect.c
+++ b/src/pq/pq_connect.c
@@ -336,7 +336,7 @@ GNUNET_PQ_reconnect (struct GNUNET_PQ_Context *db)
336 "pq", 336 "pq",
337 "Database connection to '%s' failed: %s\n", 337 "Database connection to '%s' failed: %s\n",
338 db->config_str, 338 db->config_str,
339 (NULL != db->conn) 339 (NULL != db->conn)
340 ? PQerrorMessage (db->conn) 340 ? PQerrorMessage (db->conn)
341 : "PQconnectdb returned NULL"); 341 : "PQconnectdb returned NULL");
342 if (NULL != db->conn) 342 if (NULL != db->conn)
@@ -352,20 +352,27 @@ GNUNET_PQ_reconnect (struct GNUNET_PQ_Context *db)
352 PQsetNoticeProcessor (db->conn, 352 PQsetNoticeProcessor (db->conn,
353 &pq_notice_processor_cb, 353 &pq_notice_processor_cb,
354 db); 354 db);
355 if (NULL != db->auto_suffix)
356 { 355 {
357 PGresult *res; 356 PGresult *res;
358 357 ExecStatusType est;
359 res = PQprepare (db->conn, 358
360 "gnunet_pq_check_patch", 359 res = PQexec (db->conn,
361 "SELECT" 360 "SELECT"
362 " applied_by" 361 " schema_name"
363 " FROM _v.patches" 362 " FROM information_schema.schemata"
364 " WHERE patch_name = $1" 363 " WHERE schema_name='_v';");
365 " LIMIT 1", 364 est = PQresultStatus (res);
366 1, 365 if ( (PGRES_COMMAND_OK != est) &&
367 NULL); 366 (PGRES_TUPLES_OK != est) )
368 if (PGRES_COMMAND_OK != PQresultStatus (res)) 367 {
368 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
369 "Failed to run statement to check versioning schema. Bad!\n");
370 PQclear (res);
371 PQfinish (db->conn);
372 db->conn = NULL;
373 return;
374 }
375 if (0 == PQntuples (res))
369 { 376 {
370 enum GNUNET_GenericReturnValue ret; 377 enum GNUNET_GenericReturnValue ret;
371 378
@@ -373,18 +380,16 @@ GNUNET_PQ_reconnect (struct GNUNET_PQ_Context *db)
373 if (0 != (db->flags & GNUNET_PQ_FLAG_DROP)) 380 if (0 != (db->flags & GNUNET_PQ_FLAG_DROP))
374 { 381 {
375 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 382 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
376 "Failed to prepare statement to check patch level. Likely versioning schema does not exist yet. Not attempting drop!\n"); 383 "Versioning schema does not exist yet. Not attempting drop!\n");
377 PQfinish (db->conn); 384 PQfinish (db->conn);
378 db->conn = NULL; 385 db->conn = NULL;
379 return; 386 return;
380 } 387 }
381 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
382 "Failed to prepare statement to check patch level. Likely versioning schema does not exist yet, loading versioning!\n");
383 ret = GNUNET_PQ_exec_sql (db, 388 ret = GNUNET_PQ_exec_sql (db,
384 "versioning"); 389 "versioning");
385 if (GNUNET_NO == ret) 390 if (GNUNET_NO == ret)
386 { 391 {
387 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 392 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
388 "Failed to find SQL file to load database versioning logic\n"); 393 "Failed to find SQL file to load database versioning logic\n");
389 PQfinish (db->conn); 394 PQfinish (db->conn);
390 db->conn = NULL; 395 db->conn = NULL;
@@ -398,27 +403,36 @@ GNUNET_PQ_reconnect (struct GNUNET_PQ_Context *db)
398 db->conn = NULL; 403 db->conn = NULL;
399 return; 404 return;
400 } 405 }
401 /* try again to prepare our statement! */ 406 }
402 res = PQprepare (db->conn, 407 else
403 "gnunet_pq_check_patch", 408 {
404 "SELECT" 409 PQclear (res);
405 " applied_by" 410 }
406 " FROM _v.patches" 411 }
407 " WHERE patch_name = $1" 412
408 " LIMIT 1", 413 if (NULL != db->auto_suffix)
409 1, 414 {
410 NULL); 415 PGresult *res;
411 if (PGRES_COMMAND_OK != PQresultStatus (res)) 416
412 { 417 res = PQprepare (db->conn,
413 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 418 "gnunet_pq_check_patch",
414 "Failed to run SQL logic to setup database versioning logic: %s/%s\n", 419 "SELECT"
415 PQresultErrorMessage (res), 420 " applied_by"
416 PQerrorMessage (db->conn)); 421 " FROM _v.patches"
417 PQclear (res); 422 " WHERE patch_name = $1"
418 PQfinish (db->conn); 423 " LIMIT 1",
419 db->conn = NULL; 424 1,
420 return; 425 NULL);
421 } 426 if (PGRES_COMMAND_OK != PQresultStatus (res))
427 {
428 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
429 "Failed to run SQL logic to setup database versioning logic: %s/%s\n",
430 PQresultErrorMessage (res),
431 PQerrorMessage (db->conn));
432 PQclear (res);
433 PQfinish (db->conn);
434 db->conn = NULL;
435 return;
422 } 436 }
423 PQclear (res); 437 PQclear (res);
424 438