Fix PR10: Gcm_input may loose its input message
[gnucomo.git] / src / lib / database.cpp
index 0980bf7..63384a8 100644 (file)
@@ -70,8 +70,6 @@
 
 *****************************/
 
-static const char *RCSID = "$Id: database.cpp,v 1.13 2011-03-24 10:21:47 arjen Exp $";
-
 #include <date.h>
 
 //#define DEBUG
@@ -93,7 +91,7 @@ extern std::ostream *Log;
 **  VARS CHANGED   :
 **  FUNCTIONS USED :
 **  SEE ALSO       :
-**  LAST MODIFIED  : Aug 17, 2003
+**  LAST MODIFIED  : Sep 23, 2020
 **=========================================================================
 */
 
@@ -101,30 +99,30 @@ static int gdb_refcount = 0;
 
 gnucomo_database::gnucomo_database(gnucomo_config *c)
 {
+   dbconn = 0;
+   dbxact = 0;
    cfg = c;
 
-   dbconn = new pqxx::connection(cfg->Database());
-
-   if (!dbconn->is_open())
+   try
    {
-      std::cerr << "Connection to database failed.\n";
-   }
-   else
-   {
-      try
+      dbconn = new pqxx::connection(cfg->Database());
+
+      if (!dbconn->is_open())
+      {
+         std::cerr << "Connection to database failed.\n";
+      }
+      else
       {
          // Create the transaction object
 
          //dbxact = new pqxx::transaction<pqxx::serializable>(*dbconn, "GnuCoMo");
          dbxact = new pqxx::work(*dbconn, "GnuCoMo");
+         gdb_refcount++;
       }
-      catch (std::exception &e)
-      {
-         *Log << "Cannot setup the database transaction: " << e.what() << "\n";
-         *Log << "You are probably using incompatible versions of PostgreSQL an libpqxx.\n";
-         exit(1);
-      }
-      gdb_refcount++;
+   }
+   catch (std::exception &e)
+   {
+      *Log << "Cannot setup the database transaction: " << e.what() << "\n";
    }
 }