Be more rigorous about checkingfor failure response froms server and properly

closing the connection and cleaning up.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/sqlclient/trunk@39052 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2015-10-12 15:25:19 +00:00
parent fb23a2d5fd
commit 14c31894a0

View file

@ -641,7 +641,9 @@ connectQuote(NSString *str)
giving: &length];
result = PQexec(connection, statement);
if (0 == result || PQresultStatus(result) == PGRES_FATAL_ERROR)
if (0 == result
|| (PQresultStatus(result) != PGRES_COMMAND_OK
&& PQresultStatus(result) != PGRES_TUPLES_OK))
{
NSString *str;
const char *cstr;
@ -659,16 +661,14 @@ connectQuote(NSString *str)
{
str = [NSString stringWithCString: cstr];
}
if (result != 0)
{
PQclear(result);
}
[self backendDisconnect];
[NSException raise: SQLException format: @"Error executing %@: %@",
stmt, str];
}
if (PQresultStatus(result) != PGRES_COMMAND_OK
&& PQresultStatus(result) != PGRES_TUPLES_OK)
{
[NSException raise: SQLException format: @"Error executing %@: %s",
stmt, PQresultErrorMessage(result)];
}
tuples = PQcmdTuples(result);
if (0 != tuples)
{
@ -997,7 +997,9 @@ static inline unsigned int trim(char *str, unsigned len)
statement = (char*)[stmt UTF8String];
result = PQexec(connection, statement);
if (0 == result || PQresultStatus(result) == PGRES_FATAL_ERROR)
if (0 == result
|| (PQresultStatus(result) != PGRES_COMMAND_OK
&& PQresultStatus(result) != PGRES_TUPLES_OK))
{
NSString *str;
const char *cstr;
@ -1015,6 +1017,10 @@ static inline unsigned int trim(char *str, unsigned len)
{
str = [NSString stringWithCString: cstr];
}
if (result != 0)
{
PQclear(result);
}
[self backendDisconnect];
[NSException raise: SQLException format: @"Error executing %@: %@",
stmt, str];
@ -1128,15 +1134,10 @@ static inline unsigned int trim(char *str, unsigned len)
[obj[i] release];
}
}
else if (PQresultStatus(result) == PGRES_COMMAND_OK)
{
[NSException raise: SQLException format: @"Error executing %@: %s",
stmt, "query produced no result"];
}
else
{
[NSException raise: SQLException format: @"Error executing %@: %s",
stmt, PQresultErrorMessage(result)];
stmt, "query produced no result"];
}
}
NS_HANDLER