summaryrefslogtreecommitdiff
path: root/psycopg/psycopgmodule.c
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2011-02-19 14:13:32 +0000
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2011-02-19 14:16:53 +0000
commit8a081143146ca68c4a40ba7daedf3e104a02819d (patch)
tree6706de69c314111f700a53022eed93caa61bdb25 /psycopg/psycopgmodule.c
parentd263ecfee7dd6badc8a21b772805a82cde0c8519 (diff)
downloadpsycopg2-8a081143146ca68c4a40ba7daedf3e104a02819d.tar.gz
Correctly handle exceptions with non-ascii chars in the message
Previous implementation would have barfed in canse of non-utf-8 data in the message.
Diffstat (limited to 'psycopg/psycopgmodule.c')
-rw-r--r--psycopg/psycopgmodule.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/psycopg/psycopgmodule.c b/psycopg/psycopgmodule.c
index 82a6a2d..a498223 100644
--- a/psycopg/psycopgmodule.c
+++ b/psycopg/psycopgmodule.c
@@ -593,14 +593,27 @@ psyco_set_error(PyObject *exc, PyObject *curs, const char *msg,
const char *pgerror, const char *pgcode)
{
PyObject *t;
+ PyObject *pymsg;
+ PyObject *err = NULL;
+ connectionObject *conn = NULL;
- PyObject *err = PyObject_CallFunction(exc, "s", msg);
+ if (curs) {
+ conn = ((cursorObject *)curs)->conn;
+ }
+
+ if ((pymsg = conn_text_from_chars(conn, msg))) {
+ err = PyObject_CallFunctionObjArgs(exc, pymsg, NULL);
+ Py_DECREF(pymsg);
+ }
+ else {
+ /* what's better than an error in an error handler in the morning?
+ * Anyway, some error was set, refcount is ok... get outta here. */
+ return;
+ }
if (err) {
- connectionObject *conn = NULL;
if (curs) {
PyObject_SetAttrString(err, "cursor", curs);
- conn = ((cursorObject *)curs)->conn;
}
if (pgerror) {