Improve handling of server failure

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/sqlclient/trunk@38974 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2015-09-08 08:12:18 +00:00
parent 37447b55b9
commit 8939b86ba4
2 changed files with 36 additions and 4 deletions

View file

@ -1,3 +1,8 @@
2015-07-22 Richard Frith-Macdonald <rfm@gnu.org>
* 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 <wolfgang.lux@gmail.com>
* SQLClient.m (initialize): Restore initialization of NSDateClass

View file

@ -430,18 +430,36 @@ connectQuote(NSString *str)
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 @@ connectQuote(NSString *str)
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 @@ connectQuote(NSString *str)
{
str = [NSString stringWithCString: cstr];
}
[self backendDisconnect];
[NSException raise: SQLException format: @"Error executing %@: %@",
stmt, str];
}
@ -989,6 +1015,7 @@ static inline unsigned int trim(char *str, unsigned len)
{
str = [NSString stringWithCString: cstr];
}
[self backendDisconnect];
[NSException raise: SQLException format: @"Error executing %@: %@",
stmt, str];
}