From d830fda977da7de3ff818457d5ad89389fb7b3f9 Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Mon, 8 Oct 2012 18:53:08 +0000 Subject: [PATCH] Stricter error checking. FossilOrigin-Name: cbc15fadc1bcf0dc8623f72e33d144803c4cf0d8bf740302a8915ae04cec1372 --- PGConnection.m | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/PGConnection.m b/PGConnection.m index a09aaea..d917810 100644 --- a/PGConnection.m +++ b/PGConnection.m @@ -70,11 +70,19 @@ command: command]; } - if (PQresultStatus(result) == PGRES_TUPLES_OK) + switch (PQresultStatus(result)) { + case PGRES_TUPLES_OK: return [PGResult PG_resultWithResult: result]; - - PQclear(result); - return nil; + case PGRES_COMMAND_OK: + PQclear(result); + return nil; + default: + PQclear(result); + @throw [PGCommandFailedException + exceptionWithClass: [self class] + connection: self + command: command]; + } } - (PGResult*)executeCommand: (OFConstantString*)command @@ -124,19 +132,19 @@ [pool release]; - if (PQresultStatus(result) == PGRES_FATAL_ERROR) { + switch (PQresultStatus(result)) { + case PGRES_TUPLES_OK: + return [PGResult PG_resultWithResult: result]; + case PGRES_COMMAND_OK: + PQclear(result); + return nil; + default: PQclear(result); @throw [PGCommandFailedException exceptionWithClass: [self class] connection: self command: command]; } - - if (PQresultStatus(result) == PGRES_TUPLES_OK) - return [PGResult PG_resultWithResult: result]; - - PQclear(result); - return nil; } - (void)insertRow: (OFDictionary*)row