summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--psycopg/connection.h4
-rw-r--r--psycopg/connection_int.c14
-rw-r--r--psycopg/connection_type.c2
-rw-r--r--psycopg/cursor_type.c8
-rw-r--r--psycopg/pqpath.c13
-rw-r--r--psycopg/pqpath.h2
6 files changed, 20 insertions, 23 deletions
diff --git a/psycopg/connection.h b/psycopg/connection.h
index 79f823e..9647ffd 100644
--- a/psycopg/connection.h
+++ b/psycopg/connection.h
@@ -138,12 +138,12 @@ HIDDEN PGcancel *conn_get_cancel(PGconn *pgconn);
HIDDEN void conn_notice_process(connectionObject *self);
HIDDEN void conn_notice_clean(connectionObject *self);
HIDDEN void conn_notifies_process(connectionObject *self);
-HIDDEN int conn_setup(connectionObject *self, PGconn *pgconn);
+RAISES_NEG HIDDEN int conn_setup(connectionObject *self, PGconn *pgconn);
HIDDEN int conn_connect(connectionObject *self, long int async);
HIDDEN void conn_close(connectionObject *self);
RAISES_NEG HIDDEN int conn_commit(connectionObject *self);
RAISES_NEG HIDDEN int conn_rollback(connectionObject *self);
-HIDDEN int conn_set_session(connectionObject *self, const char *isolevel,
+RAISES_NEG HIDDEN int conn_set_session(connectionObject *self, const char *isolevel,
const char *readonly, const char *deferrable,
int autocommit);
HIDDEN int conn_set_autocommit(connectionObject *self, int value);
diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c
index 4d1ffb9..abc61e8 100644
--- a/psycopg/connection_int.c
+++ b/psycopg/connection_int.c
@@ -332,7 +332,7 @@ exit:
*
* Return 0 on success, else nonzero.
*/
-static int
+RAISES_NEG static int
conn_read_encoding(connectionObject *self, PGconn *pgconn)
{
char *enc = NULL, *codec = NULL;
@@ -468,7 +468,7 @@ conn_is_datestyle_ok(PGconn *pgconn)
/* conn_setup - setup and read basic information about the connection */
-int
+RAISES_NEG int
conn_setup(connectionObject *self, PGconn *pgconn)
{
PGresult *pgres = NULL;
@@ -482,7 +482,7 @@ conn_setup(connectionObject *self, PGconn *pgconn)
return -1;
}
- if (conn_read_encoding(self, pgconn)) {
+ if (0 > conn_read_encoding(self, pgconn)) {
return -1;
}
@@ -496,7 +496,7 @@ conn_setup(connectionObject *self, PGconn *pgconn)
pthread_mutex_lock(&self->lock);
Py_BLOCK_THREADS;
- if (psyco_green() && (pq_set_non_blocking(self, 1, 1) != 0)) {
+ if (psyco_green() && (0 > pq_set_non_blocking(self, 1))) {
return -1;
}
@@ -774,7 +774,7 @@ _conn_poll_setup_async(connectionObject *self)
switch (self->status) {
case CONN_STATUS_CONNECTING:
/* Set the connection to nonblocking now. */
- if (pq_set_non_blocking(self, 1, 1) != 0) {
+ if (pq_set_non_blocking(self, 1) != 0) {
break;
}
@@ -785,7 +785,7 @@ _conn_poll_setup_async(connectionObject *self)
PyErr_SetString(InterfaceError, "only protocol 3 supported");
break;
}
- if (conn_read_encoding(self, self->pgconn)) {
+ if (0 > conn_read_encoding(self, self->pgconn)) {
break;
}
self->cancel = conn_get_cancel(self->pgconn);
@@ -971,7 +971,7 @@ conn_rollback(connectionObject *self)
return res;
}
-int
+RAISES_NEG int
conn_set_session(connectionObject *self,
const char *isolevel, const char *readonly, const char *deferrable,
int autocommit)
diff --git a/psycopg/connection_type.c b/psycopg/connection_type.c
index 47afbd7..9cdd640 100644
--- a/psycopg/connection_type.c
+++ b/psycopg/connection_type.c
@@ -528,7 +528,7 @@ psyco_conn_set_session(connectionObject *self, PyObject *args, PyObject *kwargs)
if (-1 == c_autocommit) { return NULL; }
}
- if (0 != conn_set_session(self,
+ if (0 > conn_set_session(self,
c_isolevel, c_readonly, c_deferrable, c_autocommit)) {
return NULL;
}
diff --git a/psycopg/cursor_type.c b/psycopg/cursor_type.c
index 3ce02a1..030147d 100644
--- a/psycopg/cursor_type.c
+++ b/psycopg/cursor_type.c
@@ -726,7 +726,7 @@ _psyco_curs_buildrow(cursorObject *self, int row)
}
if (!t) { goto exit; }
- if (0 == _psyco_curs_buildrow_fill(self, t, row, n, istuple)) {
+ if (0 <= _psyco_curs_buildrow_fill(self, t, row, n, istuple)) {
rv = t;
t = NULL;
}
@@ -1347,7 +1347,7 @@ psyco_curs_copy_from(cursorObject *self, PyObject *args, PyObject *kwargs)
Py_INCREF(file);
self->copyfile = file;
- if (pq_execute(self, query, 0) == 1) {
+ if (pq_execute(self, query, 0) >= 0) {
res = Py_None;
Py_INCREF(Py_None);
}
@@ -1443,7 +1443,7 @@ psyco_curs_copy_to(cursorObject *self, PyObject *args, PyObject *kwargs)
Py_INCREF(file);
self->copyfile = file;
- if (pq_execute(self, query, 0) == 1) {
+ if (pq_execute(self, query, 0) >= 0) {
res = Py_None;
Py_INCREF(Py_None);
}
@@ -1517,7 +1517,7 @@ psyco_curs_copy_expert(cursorObject *self, PyObject *args, PyObject *kwargs)
self->copyfile = file;
/* At this point, the SQL statement must be str, not unicode */
- if (pq_execute(self, Bytes_AS_STRING(sql), 0) == 1) {
+ if (pq_execute(self, Bytes_AS_STRING(sql), 0) >= 0) {
res = Py_None;
Py_INCREF(res);
}
diff --git a/psycopg/pqpath.c b/psycopg/pqpath.c
index 899c331..e8b8dc6 100644
--- a/psycopg/pqpath.c
+++ b/psycopg/pqpath.c
@@ -304,19 +304,16 @@ pq_clear_async(connectionObject *conn)
Accepted arg values are 1 (nonblocking) and 0 (blocking).
- Return 0 if everything ok, else nonzero.
-
- In case of error, if pyerr is nonzero, set a Python exception.
+ Return 0 if everything ok, else < 0 and set an exception.
*/
-int
-pq_set_non_blocking(connectionObject *conn, int arg, int pyerr)
+RAISES_NEG int
+pq_set_non_blocking(connectionObject *conn, int arg)
{
int ret = PQsetnonblocking(conn->pgconn, arg);
if (0 != ret) {
Dprintf("PQsetnonblocking(%d) FAILED", arg);
- if (pyerr) {
- PyErr_SetString(OperationalError, "PQsetnonblocking() failed");
- }
+ PyErr_SetString(OperationalError, "PQsetnonblocking() failed");
+ ret = -1;
}
return ret;
}
diff --git a/psycopg/pqpath.h b/psycopg/pqpath.h
index 2fff85f..a8f39c1 100644
--- a/psycopg/pqpath.h
+++ b/psycopg/pqpath.h
@@ -61,7 +61,7 @@ HIDDEN int pq_is_busy(connectionObject *conn);
HIDDEN int pq_is_busy_locked(connectionObject *conn);
HIDDEN int pq_flush(connectionObject *conn);
HIDDEN void pq_clear_async(connectionObject *conn);
-HIDDEN int pq_set_non_blocking(connectionObject *conn, int arg, int pyerr);
+RAISES_NEG HIDDEN int pq_set_non_blocking(connectionObject *conn, int arg);
HIDDEN void pq_set_critical(connectionObject *conn, const char *msg);