From 5b6a9b017ad1d5c98ffe4e3181d398fcca495932 Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Tue, 11 Nov 2008 20:38:06 +0000 Subject: [PATCH] Raise a cx_Oracle.Error instance for invalid handle as well in order to make debugging of such error messages simpler. --- Environment.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Environment.c b/Environment.c index 72bad6a..c4661e3 100644 --- a/Environment.c +++ b/Environment.c @@ -162,7 +162,7 @@ static void Environment_Free( // exception for Python. At this point it is assumed that the Oracle // environment is fully initialized. //----------------------------------------------------------------------------- -static void Environment_RaiseError( +static int Environment_RaiseError( udt_Environment *environment, // environment to raise error for const char *context) // context in which error occurred { @@ -197,6 +197,7 @@ static void Environment_RaiseError( PyErr_SetObject(exceptionType, (PyObject*) error); Py_DECREF(error); } + return -1; } @@ -210,10 +211,19 @@ static int Environment_CheckForError( sword status, // status of last call const char *context) // context { + udt_Error *error; + if (status != OCI_SUCCESS && status != OCI_SUCCESS_WITH_INFO) { - if (status == OCI_INVALID_HANDLE) - PyErr_SetString(g_DatabaseErrorException, "Invalid handle!"); - else Environment_RaiseError(environment, context); + if (status != OCI_INVALID_HANDLE) + return Environment_RaiseError(environment, context); + error = Error_New(environment, context, 0); + if (!error) + return -1; + error->code = 0; + error->message = cxString_FromAscii("Invalid handle!"); + if (!error->message) + Py_DECREF(error); + else PyErr_SetObject(g_DatabaseErrorException, (PyObject*) error); return -1; } return 0;