diff options
Diffstat (limited to 'psycopg/pqpath.c')
| -rw-r--r-- | psycopg/pqpath.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/psycopg/pqpath.c b/psycopg/pqpath.c index 8136d0a..6a6d05a 100644 --- a/psycopg/pqpath.c +++ b/psycopg/pqpath.c @@ -172,16 +172,19 @@ pq_raise(connectionObject *conn, cursorObject *curs, PGresult *pgres) if (pgres) { err = PQresultErrorMessage(pgres); if (err != NULL) { + Dprintf("pq_raise: PQresultErrorMessage: err=%s", err); code = PQresultErrorField(pgres, PG_DIAG_SQLSTATE); } } - if (err == NULL) + if (err == NULL) { err = PQerrorMessage(conn->pgconn); + Dprintf("pq_raise: PQerrorMessage: err=%s", err); + } /* if the is no error message we probably called pq_raise without reason: we need to set an exception anyway because the caller will probably raise and a meaningful message is better than an empty one */ - if (err == NULL) { + if (err == NULL || err[0] == '\0') { PyErr_SetString(Error, "psycopg went psycotic without error set"); return; } @@ -191,9 +194,15 @@ pq_raise(connectionObject *conn, cursorObject *curs, PGresult *pgres) if (code != NULL) { exc = exception_from_sqlstate(code); } + else { + /* Fallback if there is no exception code (reported happening e.g. + * when the connection is closed). */ + exc = DatabaseError; + } /* try to remove the initial "ERROR: " part from the postgresql error */ err2 = strip_severity(err); + Dprintf("pq_raise: err2=%s", err2); psyco_set_error(exc, curs, err2, err, code); } @@ -1355,6 +1364,13 @@ pq_fetch(cursorObject *curs) /* don't clear curs->pgres, because it contains the results! */ break; + case PGRES_EMPTY_QUERY: + PyErr_SetString(ProgrammingError, + "can't execute an empty query"); + IFCLEARPGRES(curs->pgres); + ex = -1; + break; + default: Dprintf("pq_fetch: uh-oh, something FAILED: pgconn = %p", curs->conn); pq_raise(curs->conn, curs, NULL); |
