mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-02-07 12:50:32 +03:00
* psycopg/pqpath.c (pq_raise): remove unused arguments to
function, and simplify. (pq_resolve_critical): make function static, since it isn't being used outside of pqpath.c any more.
This commit is contained in:
parent
e744242fe1
commit
11b017fcbe
|
@ -1,3 +1,10 @@
|
||||||
|
2008-01-19 James Henstridge <james@jamesh.id.au>
|
||||||
|
|
||||||
|
* psycopg/pqpath.c (pq_raise): remove unused arguments to
|
||||||
|
function, and simplify.
|
||||||
|
(pq_resolve_critical): make function static, since it isn't being
|
||||||
|
used outside of pqpath.c any more.
|
||||||
|
|
||||||
2008-01-17 James Henstridge <james@jamesh.id.au>
|
2008-01-17 James Henstridge <james@jamesh.id.au>
|
||||||
|
|
||||||
* ZPsycopgDA/DA.py (Connection.__init__): Default the encoding to
|
* ZPsycopgDA/DA.py (Connection.__init__): Default the encoding to
|
||||||
|
|
|
@ -145,15 +145,13 @@ exception_from_sqlstate(const char *sqlstate)
|
||||||
This function should be called while holding the GIL. */
|
This function should be called while holding the GIL. */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
pq_raise(connectionObject *conn, cursorObject *curs, PGresult *pgres,
|
pq_raise(connectionObject *conn, cursorObject *curs, PGresult *pgres)
|
||||||
PyObject *exc, const char *msg)
|
|
||||||
{
|
{
|
||||||
PyObject *pgc = (PyObject*)curs;
|
PyObject *pgc = (PyObject*)curs;
|
||||||
|
PyObject *exc = NULL;
|
||||||
const char *err = NULL;
|
const char *err = NULL;
|
||||||
const char *err2 = NULL;
|
const char *err2 = NULL;
|
||||||
const char *code = NULL;
|
const char *code = NULL;
|
||||||
char *buf = NULL;
|
|
||||||
|
|
||||||
if ((conn == NULL && curs == NULL) || (curs != NULL && conn == NULL)) {
|
if ((conn == NULL && curs == NULL) || (curs != NULL && conn == NULL)) {
|
||||||
PyErr_SetString(Error, "psycopg went psycotic and raised a null error");
|
PyErr_SetString(Error, "psycopg went psycotic and raised a null error");
|
||||||
|
@ -182,10 +180,9 @@ pq_raise(connectionObject *conn, cursorObject *curs, PGresult *pgres,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if exc is NULL, analyze the message and try to deduce the right
|
/* Analyze the message and try to deduce the right exception kind
|
||||||
exception kind (only if we got the SQLSTATE from the pgres,
|
(only if we got the SQLSTATE from the pgres, obviously) */
|
||||||
obviously) */
|
if (code != NULL) {
|
||||||
if (exc == NULL && code != NULL) {
|
|
||||||
exc = exception_from_sqlstate(code);
|
exc = exception_from_sqlstate(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,28 +204,9 @@ pq_raise(connectionObject *conn, cursorObject *curs, PGresult *pgres,
|
||||||
/* try to remove the initial "ERROR: " part from the postgresql error */
|
/* try to remove the initial "ERROR: " part from the postgresql error */
|
||||||
err2 = strip_severity(err);
|
err2 = strip_severity(err);
|
||||||
|
|
||||||
/* if msg is not NULL, add it to the error message, after a '\n' */
|
|
||||||
if (msg && code) {
|
|
||||||
size_t len = strlen(code) + strlen(err) + strlen(msg) + 5;
|
|
||||||
if ((buf = PyMem_Malloc(len))) {
|
|
||||||
snprintf(buf, len, "[%s] %s\n%s", code, err2, msg);
|
|
||||||
psyco_set_error(exc, pgc, buf, err, code);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (msg) {
|
|
||||||
size_t len = strlen(err) + strlen(msg) + 2;
|
|
||||||
if ((buf = PyMem_Malloc(len))) {
|
|
||||||
snprintf(buf, len, "%s\n%s", err2, msg);
|
|
||||||
psyco_set_error(exc, pgc, buf, err, code);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
psyco_set_error(exc, pgc, err2, err, code);
|
psyco_set_error(exc, pgc, err2, err, code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf != NULL) PyMem_Free(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* pq_set_critical, pq_resolve_critical - manage critical errors
|
/* pq_set_critical, pq_resolve_critical - manage critical errors
|
||||||
|
|
||||||
this function is invoked when a PQexec() call returns NULL, meaning a
|
this function is invoked when a PQexec() call returns NULL, meaning a
|
||||||
|
@ -265,7 +243,7 @@ pq_clear_critical(connectionObject *conn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *
|
static PyObject *
|
||||||
pq_resolve_critical(connectionObject *conn, int close)
|
pq_resolve_critical(connectionObject *conn, int close)
|
||||||
{
|
{
|
||||||
Dprintf("pq_resolve_critical: resolving %s", conn->critical);
|
Dprintf("pq_resolve_critical: resolving %s", conn->critical);
|
||||||
|
@ -363,7 +341,7 @@ pq_complete_error(connectionObject *conn, PGresult **pgres, char **error)
|
||||||
Dprintf("pq_complete_error: pgconn = %p, pgres = %p, error = %s",
|
Dprintf("pq_complete_error: pgconn = %p, pgres = %p, error = %s",
|
||||||
conn->pgconn, *pgres, *error ? *error : "(null)");
|
conn->pgconn, *pgres, *error ? *error : "(null)");
|
||||||
if (*pgres != NULL)
|
if (*pgres != NULL)
|
||||||
pq_raise(conn, NULL, *pgres, NULL, NULL);
|
pq_raise(conn, NULL, *pgres);
|
||||||
else if (*error != NULL) {
|
else if (*error != NULL) {
|
||||||
PyErr_SetString(OperationalError, *error);
|
PyErr_SetString(OperationalError, *error);
|
||||||
free(*error);
|
free(*error);
|
||||||
|
@ -865,7 +843,7 @@ _pq_copy_in_v3(cursorObject *curs)
|
||||||
IFCLEARPGRES(curs->pgres);
|
IFCLEARPGRES(curs->pgres);
|
||||||
while ((curs->pgres = PQgetResult(curs->conn->pgconn)) != NULL) {
|
while ((curs->pgres = PQgetResult(curs->conn->pgconn)) != NULL) {
|
||||||
if (PQresultStatus(curs->pgres) == PGRES_FATAL_ERROR)
|
if (PQresultStatus(curs->pgres) == PGRES_FATAL_ERROR)
|
||||||
pq_raise(curs->conn, curs, NULL, NULL, NULL);
|
pq_raise(curs->conn, curs, NULL);
|
||||||
IFCLEARPGRES(curs->pgres);
|
IFCLEARPGRES(curs->pgres);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -899,7 +877,7 @@ _pq_copy_in(cursorObject *curs)
|
||||||
IFCLEARPGRES(curs->pgres);
|
IFCLEARPGRES(curs->pgres);
|
||||||
while ((curs->pgres = PQgetResult(curs->conn->pgconn)) != NULL) {
|
while ((curs->pgres = PQgetResult(curs->conn->pgconn)) != NULL) {
|
||||||
if (PQresultStatus(curs->pgres) == PGRES_FATAL_ERROR)
|
if (PQresultStatus(curs->pgres) == PGRES_FATAL_ERROR)
|
||||||
pq_raise(curs->conn, curs, NULL, NULL, NULL);
|
pq_raise(curs->conn, curs, NULL);
|
||||||
IFCLEARPGRES(curs->pgres);
|
IFCLEARPGRES(curs->pgres);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -936,7 +914,7 @@ _pq_copy_out_v3(cursorObject *curs)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len == -2) {
|
if (len == -2) {
|
||||||
pq_raise(curs->conn, NULL, NULL, NULL, NULL);
|
pq_raise(curs->conn, curs, NULL);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -944,7 +922,7 @@ _pq_copy_out_v3(cursorObject *curs)
|
||||||
IFCLEARPGRES(curs->pgres);
|
IFCLEARPGRES(curs->pgres);
|
||||||
while ((curs->pgres = PQgetResult(curs->conn->pgconn)) != NULL) {
|
while ((curs->pgres = PQgetResult(curs->conn->pgconn)) != NULL) {
|
||||||
if (PQresultStatus(curs->pgres) == PGRES_FATAL_ERROR)
|
if (PQresultStatus(curs->pgres) == PGRES_FATAL_ERROR)
|
||||||
pq_raise(curs->conn, curs, NULL, NULL, NULL);
|
pq_raise(curs->conn, curs, NULL);
|
||||||
IFCLEARPGRES(curs->pgres);
|
IFCLEARPGRES(curs->pgres);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -995,7 +973,7 @@ _pq_copy_out(cursorObject *curs)
|
||||||
IFCLEARPGRES(curs->pgres);
|
IFCLEARPGRES(curs->pgres);
|
||||||
while ((curs->pgres = PQgetResult(curs->conn->pgconn)) != NULL) {
|
while ((curs->pgres = PQgetResult(curs->conn->pgconn)) != NULL) {
|
||||||
if (PQresultStatus(curs->pgres) == PGRES_FATAL_ERROR)
|
if (PQresultStatus(curs->pgres) == PGRES_FATAL_ERROR)
|
||||||
pq_raise(curs->conn, curs, NULL, NULL, NULL);
|
pq_raise(curs->conn, curs, NULL);
|
||||||
IFCLEARPGRES(curs->pgres);
|
IFCLEARPGRES(curs->pgres);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1130,7 +1108,7 @@ pq_fetch(cursorObject *curs)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Dprintf("pq_fetch: uh-oh, something FAILED");
|
Dprintf("pq_fetch: uh-oh, something FAILED");
|
||||||
pq_raise(curs->conn, curs, NULL, NULL, NULL);
|
pq_raise(curs->conn, curs, NULL);
|
||||||
IFCLEARPGRES(curs->pgres);
|
IFCLEARPGRES(curs->pgres);
|
||||||
ex = -1;
|
ex = -1;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -39,7 +39,6 @@ extern int pq_abort(connectionObject *conn);
|
||||||
extern int pq_is_busy(connectionObject *conn);
|
extern int pq_is_busy(connectionObject *conn);
|
||||||
|
|
||||||
extern void pq_set_critical(connectionObject *conn, const char *msg);
|
extern void pq_set_critical(connectionObject *conn, const char *msg);
|
||||||
extern PyObject *pq_resolve_critical(connectionObject *conn, int close);
|
|
||||||
|
|
||||||
extern int pq_execute_command_locked(connectionObject *conn,
|
extern int pq_execute_command_locked(connectionObject *conn,
|
||||||
const char *query,
|
const char *query,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user