Author: rfm
Date: Mon Oct 12 17:25:19 2015
New Revision: 39052
URL: http://svn.gna.org/viewcvs/gnustep?rev=39052&view=rev
Log:
Be more rigorous about checkingfor failure response froms server and properly
closing the connection and cleaning up.
Modified:
libs/sqlclient/trunk/Postgres.m
Modified: libs/sqlclient/trunk/Postgres.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/Postgres.m?rev=39052&r1=39051&r2=39052&view=diff
==============================================================================
--- libs/sqlclient/trunk/Postgres.m (original)
+++ libs/sqlclient/trunk/Postgres.m Mon Oct 12 17:25:19 2015
@@ -641,7 +641,9 @@
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;
@@ -658,16 +660,14 @@
if (nil == 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 @@
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;
@@ -1014,6 +1016,10 @@
if (nil == str)
{
str = [NSString stringWithCString: cstr];
+ }
+ if (result != 0)
+ {
+ PQclear(result);
}
[self backendDisconnect];
[NSException raise: SQLException format: @"Error executing %@: %@",
@@ -1128,15 +1134,10 @@
[obj[i] release];
}
}
- else if (PQresultStatus(result) == PGRES_COMMAND_OK)
+ else
{
[NSException raise: SQLException format: @"Error executing %@: %s",
stmt, "query produced no result"];
- }
- else
- {
- [NSException raise: SQLException format: @"Error executing %@: %s",
- stmt, PQresultErrorMessage(result)];
}
}
NS_HANDLER
_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs