Author: rfm
Date: Tue Sep  8 10:12:18 2015
New Revision: 38974

URL: http://svn.gna.org/viewcvs/gnustep?rev=38974&view=rev
Log:
Improve handling of server failure

Modified:
    libs/sqlclient/trunk/ChangeLog
    libs/sqlclient/trunk/Postgres.m

Modified: libs/sqlclient/trunk/ChangeLog
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/ChangeLog?rev=38974&r1=38973&r2=38974&view=diff
==============================================================================
--- libs/sqlclient/trunk/ChangeLog      (original)
+++ libs/sqlclient/trunk/ChangeLog      Tue Sep  8 10:12:18 2015
@@ -1,3 +1,8 @@
+2015-07-22 Richard Frith-Macdonald  <[email protected]>
+
+       * Postgres.m: disconnect on fatal error, so we don't keep trying to
+       re-use the same connection when there's a problem with the server.
+
 2015-07-23  Wolfgang Lux  <[email protected]>
 
        * SQLClient.m (initialize): Restore initialization of NSDateClass

Modified: libs/sqlclient/trunk/Postgres.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/Postgres.m?rev=38974&r1=38973&r2=38974&view=diff
==============================================================================
--- libs/sqlclient/trunk/Postgres.m     (original)
+++ libs/sqlclient/trunk/Postgres.m     Tue Sep  8 10:12:18 2015
@@ -430,18 +430,36 @@
              p = PQparameterStatus(connection, "standard_conforming_strings");
               if (p != 0)
                 {
+                  PGresult     *result;
+
                   /* If the escape_string_warning setting is on,
                    * the server will warn about backslashes even
                    * in properly quoted strings, so turn it off.
                    */
                   if (strcmp(p, "on") == 0)
                     {
-                      [self execute: @"SET escape_string_warning=off", nil];
+                      result = PQexec(connection,
+                        "SET escape_string_warning=off");
                     }
                   else
                     {
-                      [self execute: @"SET standard_conforming_strings=on;"
-                        @"SET escape_string_warning=off", nil];
+                      result = PQexec(connection,
+                        "SET standard_conforming_strings=on;"
+                        "SET escape_string_warning=off");
+                    }
+                  if (0 == result
+                    || PQresultStatus(result) != PGRES_COMMAND_OK)
+                    {
+                      [self debug: @"Error setting string handling"
+                        @" with '%@' (%@) - %s",
+                        [self name], m, PQerrorMessage(connection)];
+                      if (result != 0)
+                        {
+                          PQclear(result);
+                        }
+                      PQfinish(connection);
+                      connection = 0;
+                      connected = NO;
                     }
                 }
               else
@@ -454,7 +472,14 @@
 
              if ([self debugging] > 0)
                {
-                 [self debug: @"Connected to '%@'", [self name]];
+                  if (YES == connected)
+                    {
+                      [self debug: @"Connected to '%@'", [self name]];
+                    }
+                  else
+                    {
+                      [self debug: @"Disconnected '%@'", [self name]];
+                    }
                }
            }
        }
@@ -634,6 +659,7 @@
             {
               str = [NSString stringWithCString: cstr];
             }
+          [self backendDisconnect];
          [NSException raise: SQLException format: @"Error executing %@: %@",
            stmt, str];
        }
@@ -989,6 +1015,7 @@
             {
               str = [NSString stringWithCString: cstr];
             }
+          [self backendDisconnect];
          [NSException raise: SQLException format: @"Error executing %@: %@",
            stmt, str];
        }


_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to