gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet] branch master updated: fix #7374


From: gnunet
Subject: [gnunet] branch master updated: fix #7374
Date: Tue, 18 Oct 2022 21:24:18 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new f0b91ff6c fix #7374
f0b91ff6c is described below

commit f0b91ff6ca4e327dc0e29e8d888d88d873e80e65
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Tue Oct 18 21:24:09 2022 +0200

    fix #7374
---
 src/pq/pq_connect.c | 90 +++++++++++++++++++++++++++++++----------------------
 1 file 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)
                      "pq",
                      "Database connection to '%s' failed: %s\n",
                      db->config_str,
-                     (NULL != db->conn) 
+                     (NULL != db->conn)
                      ? PQerrorMessage (db->conn)
                      : "PQconnectdb returned NULL");
     if (NULL != db->conn)
@@ -352,20 +352,27 @@ GNUNET_PQ_reconnect (struct GNUNET_PQ_Context *db)
   PQsetNoticeProcessor (db->conn,
                         &pq_notice_processor_cb,
                         db);
-  if (NULL != db->auto_suffix)
   {
     PGresult *res;
-
-    res = PQprepare (db->conn,
-                     "gnunet_pq_check_patch",
-                     "SELECT"
-                     " applied_by"
-                     " FROM _v.patches"
-                     " WHERE patch_name = $1"
-                     " LIMIT 1",
-                     1,
-                     NULL);
-    if (PGRES_COMMAND_OK != PQresultStatus (res))
+    ExecStatusType est;
+
+    res = PQexec (db->conn,
+                  "SELECT"
+                  " schema_name"
+                  " FROM information_schema.schemata"
+                  " WHERE schema_name='_v';");
+    est = PQresultStatus (res);
+    if ( (PGRES_COMMAND_OK != est) &&
+         (PGRES_TUPLES_OK != est) )
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Failed to run statement to check versioning schema. 
Bad!\n");
+      PQclear (res);
+      PQfinish (db->conn);
+      db->conn = NULL;
+      return;
+    }
+    if (0 == PQntuples (res))
     {
       enum GNUNET_GenericReturnValue ret;
 
@@ -373,18 +380,16 @@ GNUNET_PQ_reconnect (struct GNUNET_PQ_Context *db)
       if (0 != (db->flags & GNUNET_PQ_FLAG_DROP))
       {
         GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                    "Failed to prepare statement to check patch level. Likely 
versioning schema does not exist yet. Not attempting drop!\n");
+                    "Versioning schema does not exist yet. Not attempting 
drop!\n");
         PQfinish (db->conn);
         db->conn = NULL;
         return;
       }
-      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                  "Failed to prepare statement to check patch level. Likely 
versioning schema does not exist yet, loading versioning!\n");
       ret = GNUNET_PQ_exec_sql (db,
                                 "versioning");
       if (GNUNET_NO == ret)
       {
-        GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                     "Failed to find SQL file to load database versioning 
logic\n");
         PQfinish (db->conn);
         db->conn = NULL;
@@ -398,27 +403,36 @@ GNUNET_PQ_reconnect (struct GNUNET_PQ_Context *db)
         db->conn = NULL;
         return;
       }
-      /* try again to prepare our statement! */
-      res = PQprepare (db->conn,
-                       "gnunet_pq_check_patch",
-                       "SELECT"
-                       " applied_by"
-                       " FROM _v.patches"
-                       " WHERE patch_name = $1"
-                       " LIMIT 1",
-                       1,
-                       NULL);
-      if (PGRES_COMMAND_OK != PQresultStatus (res))
-      {
-        GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                    "Failed to run SQL logic to setup database versioning 
logic: %s/%s\n",
-                    PQresultErrorMessage (res),
-                    PQerrorMessage (db->conn));
-        PQclear (res);
-        PQfinish (db->conn);
-        db->conn = NULL;
-        return;
-      }
+    }
+    else
+    {
+      PQclear (res);
+    }
+  }
+
+  if (NULL != db->auto_suffix)
+  {
+    PGresult *res;
+
+    res = PQprepare (db->conn,
+                     "gnunet_pq_check_patch",
+                     "SELECT"
+                     " applied_by"
+                     " FROM _v.patches"
+                     " WHERE patch_name = $1"
+                     " LIMIT 1",
+                     1,
+                     NULL);
+    if (PGRES_COMMAND_OK != PQresultStatus (res))
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Failed to run SQL logic to setup database versioning logic: 
%s/%s\n",
+                  PQresultErrorMessage (res),
+                  PQerrorMessage (db->conn));
+      PQclear (res);
+      PQfinish (db->conn);
+      db->conn = NULL;
+      return;
     }
     PQclear (res);
 

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]