diff options
| author | James Henstridge <james@jamesh.id.au> | 2007-12-19 14:29:03 +0000 |
|---|---|---|
| committer | James Henstridge <james@jamesh.id.au> | 2007-12-19 14:29:03 +0000 |
| commit | fd5d2d52384068ad7ad30aafd9d2ea525d7909fa (patch) | |
| tree | 835d3d5ca297d8db91d303664de26080518b5b3d /psycopg/psycopgmodule.c | |
| parent | 67afd678b0d5e84aeb743c5e45b04d141701f4f0 (diff) | |
| download | psycopg2-fd5d2d52384068ad7ad30aafd9d2ea525d7909fa.tar.gz | |
* psycopg/pqpath.c (pq_raise): only remove the first 8 characters
of the exception message if it actually gives the severity.
* psycopg/pqpath.h (pq_resolve_critical): add prototype, since
this function is being used from connection_int.c.
* psycopg/psycopg.h: update psyco_set_error() prototype.
* psycopg/psycopgmodule.c (psyco_errors_init): set pgerror, pgcode
and cursor class attributes to None on psycopg2.Error so that the
attributes will always be available (simplifies error handling).
(psyco_set_error): add const qualifiers to msg, pgerror and pgcode
arguments.
Don't bother setting pgerror, pgcode or cursor to None if they are
not provided -- the class defaults take care of this.
Diffstat (limited to 'psycopg/psycopgmodule.c')
| -rw-r--r-- | psycopg/psycopgmodule.c | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/psycopg/psycopgmodule.c b/psycopg/psycopgmodule.c index 53fd641..43b9ea3 100644 --- a/psycopg/psycopgmodule.c +++ b/psycopg/psycopgmodule.c @@ -481,6 +481,13 @@ psyco_errors_init(void) *exctable[i].exc = PyErr_NewException(exctable[i].name, base, dict); } + + /* Make pgerror, pgcode and cursor default to None on psycopg + error objects. This simplifies error handling code that checks + these attributes. */ + PyObject_SetAttrString(Error, "pgerror", Py_None); + PyObject_SetAttrString(Error, "pgcode", Py_None); + PyObject_SetAttrString(Error, "cursor", Py_None); } void @@ -518,8 +525,8 @@ psyco_errors_set(PyObject *type) Create a new error of the given type with extra attributes. */ void -psyco_set_error(PyObject *exc, PyObject *curs, char *msg, - char *pgerror, char *pgcode) +psyco_set_error(PyObject *exc, PyObject *curs, const char *msg, + const char *pgerror, const char *pgcode) { PyObject *t; @@ -528,26 +535,18 @@ psyco_set_error(PyObject *exc, PyObject *curs, char *msg, if (err) { if (pgerror) { t = PyString_FromString(pgerror); + PyObject_SetAttrString(err, "pgerror", t); + Py_DECREF(t); } - else { - t = Py_None ; Py_INCREF(t); - } - PyObject_SetAttrString(err, "pgerror", t); - Py_DECREF(t); if (pgcode) { t = PyString_FromString(pgcode); + PyObject_SetAttrString(err, "pgcode", t); + Py_DECREF(t); } - else { - t = Py_None ; Py_INCREF(t); - } - PyObject_SetAttrString(err, "pgcode", t); - Py_DECREF(t); if (curs) PyObject_SetAttrString(err, "cursor", curs); - else - PyObject_SetAttrString(err, "cursor", Py_None); PyErr_SetObject(exc, err); Py_DECREF(err); @@ -557,7 +556,7 @@ psyco_set_error(PyObject *exc, PyObject *curs, char *msg, /* Return nonzero if the current one is the main interpreter */ static int -psyco_is_main_interp() +psyco_is_main_interp(void) { static PyInterpreterState *main_interp = NULL; /* Cached reference */ PyInterpreterState *interp; |
