summaryrefslogtreecommitdiff
path: root/psycopg/psycopgmodule.c
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2010-12-25 11:43:42 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2010-12-31 03:18:27 +0100
commitd3f3f1caf0177f32b70dcb7632ad0a164abcfc65 (patch)
tree79dbc842549a2fd7230bf739d46fd74017a65ea5 /psycopg/psycopgmodule.c
parent60841c65676941cd26d91cc6b704bd4c67fe2cb9 (diff)
downloadpsycopg2-d3f3f1caf0177f32b70dcb7632ad0a164abcfc65.tar.gz
Added utility method to return a string in the connection encoding.
In Py2 the result is plain string, in Py3 an unicode decoded in the connection encoding.
Diffstat (limited to 'psycopg/psycopgmodule.c')
-rw-r--r--psycopg/psycopgmodule.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/psycopg/psycopgmodule.c b/psycopg/psycopgmodule.c
index 568cf6e..d580fa0 100644
--- a/psycopg/psycopgmodule.c
+++ b/psycopg/psycopgmodule.c
@@ -582,26 +582,26 @@ psyco_set_error(PyObject *exc, PyObject *curs, const char *msg,
PyObject *err = PyObject_CallFunction(exc, "s", msg);
if (err) {
+ connectionObject *conn = NULL;
+ if (curs) {
+ PyObject_SetAttrString(err, "cursor", curs);
+ conn = ((cursorObject *)curs)->conn;
+ }
+
if (pgerror) {
- /* XXX is this always ASCII? If not, it needs
- to be decoded properly for Python 3. */
- t = Text_FromUTF8(pgerror);
+ t = conn_text_from_chars(conn, pgerror);
PyObject_SetAttrString(err, "pgerror", t);
Py_DECREF(t);
}
if (pgcode) {
- /* XXX likewise */
- t = Text_FromUTF8(pgcode);
+ t = conn_text_from_chars(conn, pgcode);
PyObject_SetAttrString(err, "pgcode", t);
Py_DECREF(t);
}
- if (curs)
- PyObject_SetAttrString(err, "cursor", curs);
-
PyErr_SetObject(exc, err);
- Py_DECREF(err);
+ Py_DECREF(err);
}
}