diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c index 5d148df3..87dc6ef9 100644 --- a/psycopg/connection_int.c +++ b/psycopg/connection_int.c @@ -1107,7 +1107,7 @@ conn_poll(connectionObject *self) /* fetch the tuples (if there are any) and build the result. We * don't care if pq_fetch return 0 or 1, but if there was an error, * we want to signal it to the caller. */ - if (pq_fetch(curs, 0) == -1) { + if (0 > pq_fetch(curs, 0)) { res = PSYCO_POLL_ERROR; } diff --git a/psycopg/pqpath.c b/psycopg/pqpath.c index b765aba0..01ded5a8 100644 --- a/psycopg/pqpath.c +++ b/psycopg/pqpath.c @@ -246,7 +246,7 @@ pq_resolve_critical(connectionObject *conn, int close) PyErr_SetString(OperationalError, msg); /* we don't want to destroy this connection but just close it */ - if (close == 1) conn_close(conn); + if (close) conn_close(conn); /* remember to clear the critical! */ pq_clear_critical(conn); @@ -1832,7 +1832,7 @@ exit: return ret; } -int +RAISES_NEG int pq_fetch(cursorObject *curs, int no_result) { int pgstatus, ex = -1; @@ -1863,8 +1863,7 @@ pq_fetch(cursorObject *curs, int no_result) Py_CLEAR(curs->pgstatus); if (!(curs->pgstatus = TO_STATE(conn_text_from_chars( curs->conn, PQcmdStatus(curs->pgres))))) { - ex = -1; - return ex; + return -1; } switch(pgstatus) { @@ -1910,7 +1909,7 @@ pq_fetch(cursorObject *curs, int no_result) if (!no_result) { Dprintf("pq_fetch: got tuples"); curs->rowcount = PQntuples(curs->pgres); - if (0 == _pq_fetch_tuples(curs)) { ex = 0; } + ex = _pq_fetch_tuples(curs); /* don't clear curs->pgres, because it contains the results! */ } else { @@ -1956,7 +1955,7 @@ pq_fetch(cursorObject *curs, int no_result) raise the exception but we avoid to close the connection) */ Dprintf("pq_fetch: fetching done; check for critical errors"); if (curs->conn->critical) { - return pq_resolve_critical(curs->conn, ex == -1 ? 1 : 0); + ex = pq_resolve_critical(curs->conn, ex < 0); } return ex;